Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing extra border caused by line height

Tags:

html

css

I want to set left border for a paragraph, but the border has extra height because of line height. I want to remove the height of the border which exceeds the top and bottom of the text. See the screenshot: enter image description here

I have tried several mothds, for example wrapping the paragraph in a div and setting the negative margin, but doesnt seem to work.

Here's simple css:

p{
    margin: 20px;    
    line-height: 2;    
    border-left: 5px solid green;
}

Demo: http://jsfiddle.net/0et4gq16/

Edit: The line height should not be changed.

like image 436
user1355300 Avatar asked Jan 10 '23 10:01

user1355300


2 Answers

Just draw the line manually!

p{
    margin: 20px;    
    line-height: 2;
    position: relative;
}
p:after {
    content: " ";
    display: block;
    width: 5px;
    background: green;
    position: absolute;
    left: -5px;
    top: 0.5em;
    bottom: 0.5em;
}

fiddle

like image 55
Roman Bekkiev Avatar answered Jan 22 '23 21:01

Roman Bekkiev


If you are not willing to change the line-height property, then I am afraid it is not possible.

The margin property defines the space between your p with border and the rest of the "world". But line-height is space before and after the line, not between the lines.

So, the border aligns itself as close to the text as possible, taking line-height in regard.

like image 45
Alex Karshin Avatar answered Jan 22 '23 20:01

Alex Karshin