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

Posted on 2007-11-28
Last Modified: 2008-02-01
Hi All,

Title say it all really.

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

Many thanks
Question by:detox1978
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
LVL 18

Expert Comment

ID: 20365850
Is the 100px going to be used for anything?

Author Comment

ID: 20365870
I'm creating a block of colour for decoration.  Here's what i have (the width doesn't work).

#extraDiv1 {
      width: 100% - 100px;
LVL 16

Expert Comment

ID: 20365928
You just need to set the margin-right and margin-left to 50px.  Then you div will be 100% - 100px
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

LVL 13

Expert Comment

ID: 20365936
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

LVL 16

Accepted Solution

rbudj earned 200 total points
ID: 20365955
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
LVL 18

Assisted Solution

Eternal_Student earned 50 total points
ID: 20365994
Yes there are numerous ways to do this.

<div style="width:100%;">
      <div style="float:right; background-color:#FF0000; width:100px;">&nbsp;</div>

Author Comment

ID: 20366017
thanks.  i nested a span inside.

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question