Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css width above 100%

Tags:

Is correct to specify a width greater than 100% ?

.class{     width: 102%; } 
like image 797
grigno Avatar asked May 29 '14 13:05

grigno


People also ask

What does width 100% do in CSS?

width: 100%; will make the element as wide as the parent container. Extra spacing will be added to the element's size without regards to the parent.

Is width 100 and width 100% the same?

Answer is No. cause 100 is pixels and 100% is percentage of overall size of page.

Should you use 100% width?

Should it Ever Be Used? In many cases, applying width: 100% to a block level element is either unnecessary or will bring undesirable results. If you're using padding on the inner element and you use box-sizing: border-box , then you'll be safe.

What is Max-width in CSS?

Definition and Usage. The max-width property defines the maximum width of an element. If the content is larger than the maximum width, it will automatically change the height of the element. If the content is smaller than the maximum width, the max-width property has no effect.


2 Answers

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

like image 176
Etheryte Avatar answered Sep 21 '22 02:09

Etheryte


Percentage values simply represent a percentage of the length of the element's container. A percentage over 100% is completely valid, however a percentage under 0% isn't (as 0% will always be equal to a length of 0).

Let's say you have a div element which has 100px width. Within that div element is a p element which you're putting a percentage width on, the following will occur:

width: 0%;                         // 0px (0% of 100px) width: 10%;                        // 10px (10% of 100px) width: 100%;                       // 100px (100% of 100px) width: 110%;                       // 110px (110% of 100px) width: 200%;                       // 200px (200% of 100px) width: 1000%;                      // 1000px (1000% of 100px) 

From the W3's CSS Values and Units Module Level 3:

A percentage value is denoted by <percentage>, consists of a <number> immediately followed by a percent sign ‘%’. It corresponds to the PERCENTAGE token in the grammar.

Percentage values are always relative to another value, for example a length. Each property that allows percentages also defines the value to which the percentage refers. The value may be that of another property for the same element, a property for an ancestor element, or a value of the formatting context (e.g., the width of a containing block). When a percentage value is set for a property of the root element and the percentage is defined as referring to the inherited value of some property, the resultant value is the percentage times the initial value of that property.

like image 29
James Donnelly Avatar answered Sep 18 '22 02:09

James Donnelly