Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why dont my Divs span 100% of the width?

Tags:

html

css

width

I have a really dumb question to ask.

I am trying to make a div span 100% of the width of a webpage, but it doesn't reach. I want it to be dynamic (not specify the width in px) and I definitely don't want it to make a horizontal scroll bar appear.

I'm trying to make something similar to Stack Overflow's 100% page width 'alerts' which tell you when you've earned a new badge.

Screenshot of my site: Screenshot of my site. Note how the pink banner and green banner leave gaps where the sky blue background is shown.

Code for the pink banner div

<div width='100%' style="padding:0px; background-color:FF0099; background-image:url('pics/pink_bg.png'); ">
  &nbsp;
</div>
like image 530
Adjam Avatar asked Apr 10 '12 16:04

Adjam


3 Answers

your html body tag might have padding or margin css. you should set those to zero(0). I hope it will help.

like image 198
sarwar026 Avatar answered Sep 28 '22 09:09

sarwar026


Looks like you have padding on your body, which is preventing the div from expanding all the way.

like image 44
David Nguyen Avatar answered Sep 28 '22 09:09

David Nguyen


In your css file, ensure that you don't have any padding on the body. If you don't have anything you can try adding this:

body {
    padding: 0;
    margin: 0;
}
like image 36
dpcasady Avatar answered Sep 28 '22 07:09

dpcasady