Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Short border line?

Tags:

css

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.

like image 567
user2987337 Avatar asked Nov 14 '13 14:11

user2987337


People also ask

How do I reduce border length in CSS?

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%.

How do I increase the border length in CSS?

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.


1 Answers

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

like image 161
SW4 Avatar answered Sep 19 '22 15:09

SW4