CSS: is it possible to set a DIV width to 100% minus 100px?

Hi All,

Title say it all really.

is it possible to set a DIV width to 100% minus 100px, using CSS?

Many thanks
Who is Participating?
rbudjConnect With a Mentor Commented:
oh, for color, make a div set to 100% , then put another div inside that div following my previous instructions.  Make the background color of the container div whatever color you want and it will show through where the right and left margins are 50px
Is the 100px going to be used for anything?
detox1978Author Commented:
I'm creating a block of colour for decoration.  Here's what i have (the width doesn't work).

#extraDiv1 {
      width: 100% - 100px;
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

You just need to set the margin-right and margin-left to 50px.  Then you div will be 100% - 100px
Create another div around it and add padding to that div. It depends a little where you want to place the inner div, but this is a possibility:
div.container { padding-right: 100px; }

Open in new window

Eternal_StudentConnect With a Mentor Commented:
Yes there are numerous ways to do this.

<div style="width:100%;">
      <div style="float:right; background-color:#FF0000; width:100px;">&nbsp;</div>
detox1978Author Commented:
thanks.  i nested a span inside.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.