I have a border on a couple of DIVs that is only on the left side.
CSS:
#Mid-Content_ {
position: absolute;
left: 510px;
top: 119px;
height: 70%;
border-left: #CCC 2px solid;
width: 250px;
padding-left: 10px;
}
The border goes from the top to the bottom of the left side which is exactly what it should do according to the CSS code.
Is there a way to make it shorter, say 10px from the top and bottom? The problem is that the text inside the DIV needs to be inline with this border line.
To adjust the border length, you can use the width & height properties of these pseudo-elements. In the following example, we have added a blue bottom border to the div element and we have shortened it to 50% by setting the width of the ::before element to 50%.
CSS borders are placed between the margins and padding of an HTML element. If you want the borders of an HTML element to extend past the width (or height) of that element, you can add CSS padding to the element in order to push the borders outward.
Have a look at this fiddle
HTML
<div id="contentArea">
<div id="border"></div>
text text text text text text text text text text
</div>
CSS
#contentArea {
height: 100px;
width: 80px;
position: relative;
background: #3beadc;
padding:5px;
}
#border {
border-left: 2px solid #f51c40;
position: absolute;
top: 10px;
bottom: 10px
left:0px;
}
If you want the border to be outside the contentArea, change its left value to negative*border width* e.g. left:-2px;
in the case above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With