CSS border-block Property

CSS (Cascading Style Sheets) is a powerful tool that allows web developers to control the look and feel of their websites. One of the many properties available in CSS is the border-block property. In this article, we will explore what the border-block property is and how it can be used to enhance the visual design of a webpage.

The border-block property is used to set the border properties for the block-axis (vertical) of an element. It is particularly useful when working with elements that have a block-level display, such as divs or paragraphs. By using the border-block property, you can easily add borders to the top and bottom of an element, or even customize each side individually.

Let’s take a look at some examples to better understand the usage of the border-block property:

Example 1:
“`css
div {
border-block: 2px solid #000;
}
“`
In this example, we are targeting a `

` element and applying a 2-pixel solid black border to both the top and bottom sides. This simple declaration can add a neat and clean visual separation between different sections of a webpage.

Example 2:
“`css
p {
border-block: 1px dashed #f00;
}
“`
Here, we are targeting `

` elements and applying a 1-pixel dashed red border to both the top and bottom sides. The dashed border style can be used to create a visually appealing effect, such as highlighting important information within a paragraph.

Example 3:
“`css
blockquote {
border-block: 3px double #00f;
}
“`
In this example, we are targeting `

` elements and applying a 3-pixel double blue border to both the top and bottom sides. The double border style adds a decorative touch, making the blockquote stand out from the surrounding content.

Example 4:
“`css
section {
border-block: 1px solid #888;
border-block-start: 3px dotted #888;
border-block-end: 3px dotted #888;
}
“`
Here, we are targeting `

` elements and applying a 1-pixel solid gray border to both the top and bottom sides. Additionally, we are customizing the top and bottom borders individually by using the border-block-start and border-block-end properties. The dotted border style further enhances the visual appeal of the section.

Example 5:
“`css
nav {
border-block: 2px groove #0f0;
border-block-start-style: none;
}
“`
In this example, we are targeting a `

Scroll to Top