CSS Properties
CSS inset-block Property
Photo Credit to CodeToFun
🙋 Introduction
The inset-block
property in CSS is part of the Logical Properties and Values specification. It allows developers to control the logical block-start and block-end offsets of an element in a single declaration.
This property is particularly useful for handling layouts in a way that adapts to different writing modes, such as left-to-right, right-to-left, and vertical text directions.
💡 Syntax
The syntax for the inset-block
property is straightforward. It can take one or two values.
element {
inset-block: value;
}
element {
inset-block: block-start-value block-end-value;
}
- value: Specifies the offset for both the block-start and block-end edges.
- block-start-value block-end-value: Specifies the offset for the block-start and block-end edges individually.
🎛️ Default Value
The default value of the inset-block
property is auto, which means the element's position will be determined by the browser's default styles or other specified properties.
🏠 Property Values
Value | Description |
---|---|
length | Specifies a fixed offset, such as 20px, 1em, 5%, etc. |
auto | The browser calculates the offset automatically. |
initial | Sets the property to its default value. |
inherit | Inherits the value from its parent element. |
📄 Example
In this example, we'll apply the inset-block
property to position an element within its container.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS inset-block Example</title>
<style>
.container {
position: relative;
width: 300px;
height: 200px;
border: 1px solid #000;
}
.box {
position: absolute;
inset-block: 10px 20px;
width: 100px;
height: 50px;
background-color: #007bff;
}
</style>
</head>
<body>
<h1>Element with inset-block Property</h1>
<div class="container">
<div class="box"></div>
</div>
</body>
</html>
🖥️ Browser Compatibility
The inset-block
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.
🎉 Conclusion
The inset-block
property is a versatile tool for web developers looking to manage the block-level positioning of elements in a logical, writing-mode independent manner.
By understanding and using this property, you can create more flexible and robust layouts that adapt to different writing modes and languages. Experiment with different values and see how this property can enhance your web designs.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS inset-block Property), please comment here. I will help you immediately.