Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equal line height with varying border width (border-box)

Tags:

css

In this simplified example I have 4 circles, each with varying border-width and I am trying to maintain equal line height in each to keep them horizontally aligned.

However the border width seems to effect the line height (despite being technically outside the box?)

Is there anyway to solve this without manually adjusting each line-height?

width: 50px;
height: 50px;
border-radius: 50px;
border: 1px solid #1daeec;
line-height: 50px;

Example: http://jsfiddle.net/vcJ3G/

like image 223
Titan Avatar asked Aug 07 '13 14:08

Titan


People also ask

How do borders affect the size of the box?

border-box tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width.

How do you include the padding and border in an element's total width and height?

With the CSS box-sizing Property The box-sizing property allows us to include the padding and border in an element's total width and height. If you set box-sizing: border-box; on an element, padding and border are included in the width and height: Both divs are the same size now!

Does border affect width?

Yes, borders take up physical space. So, if you set a div to be 100%, then give it a 1px border, it will be 2px wider than the container it is in.


2 Answers

You can remove the line-height, use display:table-cell instead, and add vertical-align:middle; to your stat class.

jsFiddle example

.stat {
    display: table-cell;
    width: 50px;
    height: 50px;
    border-radius: 50px;
    border: 1px solid #1daeec;
    text-align: center;
    margin: 10px;
    font-size: 16px;
    color: #1daeec;
    text-transform: uppercase;
    vertical-align:middle;
}
like image 193
j08691 Avatar answered Nov 09 '22 19:11

j08691


Your css works fine all you have to do is remove some from top section

* {
    margin: 0px;
    padding: 0px;

}

http://jsfiddle.net/techsin/vcJ3G/15/

like image 27
Muhammad Umer Avatar answered Nov 09 '22 19:11

Muhammad Umer