Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do width = 100% - 100px in CSS?

Tags:

html

css

In CSS, how can I do something like this:

width: 100% - 100px; 

I guess this is fairly simple but it is a bit hard to find examples showing that.

like image 689
fmsf Avatar asked May 22 '09 17:05

fmsf


People also ask

How do I change the width to 100% 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.

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

What does width 100% means in CSS?

if you specify width:100%, the element's total width will be 100% of its containing block plus any horizontal margin, padding and border.

How do I get full width in CSS?

Using width, max-width and margin: auto; As mentioned in the previous chapter; a block-level element always takes up the full width available (stretches out to the left and right as far as it can). Setting the width of a block-level element will prevent it from stretching out to the edges of its container.


2 Answers

Could you nest a div with margin-left: 50px; and margin-right: 50px; inside a <div> with width: 100%;?

like image 25
Aric TenEyck Avatar answered Oct 12 '22 10:10

Aric TenEyck


Modern browsers now support the:

width: calc(100% - 100px); 

To see the list of supported browser versions checkout: Can I use calc() as CSS unit value?

There is a jQuery fallback: css width: calc(100% -100px); alternative using jquery

like image 139
Chad Avatar answered Oct 12 '22 11:10

Chad