Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to represent 1/3rd of 100% in CSS?

Tags:

css

I have a big <div> with three little <div>'s inside of it, inline. They each have 33% width, but that causes some alignment problems because 3 * 33% != 100%. What is the best way to represent a perfect third in CSS like this? Maybe just 33.33%?

like image 205
AKor Avatar asked Mar 01 '11 18:03

AKor


People also ask

What does 100% do in CSS?

It seems like this should be one of the easiest things to understand in CSS. If you want a block-level element to fill any remaining space inside of its parent, then it's simple — just add width: 100% in your CSS declaration for that element, and your problem is solved.

How do you divide in CSS?

To achieve this CSS border-top-width property or CSS border-bottom-width property are used in CSS. Divide Width Classes: divide-x: This class is used to set the x-axis divide. divide-x-reverse: This class is used to set the x-axis reverse divide.

Can we give width more than 100% in CSS?

Yes, as per the CSS 2.1 Specification, all non-negative values are valid for width, that includes percentage values above 100%.

Should you use percentage CSS?

Clearly, there is nothing right or wrong. With pixels, it is easy to position objects relative to each other and controls specific heights and widths. On the other hand, scaling objects with percentages is easy. % Is the way to go in a modern world like vector graphics.


1 Answers

Now that calc is widely supported among modern browsers, you can use:

#myDiv {     width: calc(100% / 3); } 

Or you can use this as a fallback if your browser wouldn't support it:

#myDivWithFallback {     width: 33.33%;     width: calc(100% / 3); } 
like image 93
Nathan Chase Avatar answered Sep 20 '22 17:09

Nathan Chase