# Simple CSS question about positioning

**URL:** https://boards.straightdope.com/t/simple-css-question-about-positioning/560995
**Category:** Factual Questions
**Created:** [November 17, 2010, 5:33pm UTC](https://boards.straightdope.com/t/simple-css-question-about-positioning/560995 "2010-11-17T17:33:16Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Cagey\_Drifter](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Cagey\_Drifter](https://boards.straightdope.com/u/Cagey_Drifter)
#### Post date: [November 17, 2010, 5:33pm UTC](https://boards.straightdope.com/t/simple-css-question-about-positioning/560995/1 "2010-11-17T17:33:16Z")

</div>

Easy question, I think: I have an image that I want to stretch across the length of the screen, but I’m having an issue that should be easy to fix, but I can’t figure out how and can’t find the answer online. Basically, when I use the below code, it by default places the image not at the upper left edge despite my explicit instructions (!), but a few (~8) pixels away from the edge. How do I get it to stop doing that? And can I do it without using negative numbers in the top and left tags?

```auto

div.top {background-image:url('background.gif');
	position:relative;
	width:100%;
	height:136px;
	top:0px;
	left:0px;}
	

```

---

<div class="post-metadata">

### Author: ![\_Undecided\_Adrian](https://avatars.discourse-cdn.com/v4/letter/_/eada6e/32.png) [@\_Undecided\_Adrian](https://boards.straightdope.com/u/_Undecided_Adrian)
#### Post date: [November 17, 2010, 6:50pm UTC](https://boards.straightdope.com/t/simple-css-question-about-positioning/560995/2 "2010-11-17T18:50:59Z")

</div>

That’s either the margin or the padding of the body, IIRC.

---

<div class="post-metadata">

### Author: ![Markxxx](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@Markxxx](https://boards.straightdope.com/u/Markxxx)
#### Post date: [November 17, 2010, 6:57pm UTC](https://boards.straightdope.com/t/simple-css-question-about-positioning/560995/3 "2010-11-17T18:57:47Z")

</div>

Is it doing it in Firefox and IE or just one? If so which version are you testing it on.

You might also want to look around [Dynamic Drive forums](http://www.dynamicdrive.com/forums/) they are very helpful and experts

---

<div class="post-metadata">

### Author: ![kushiel](https://avatars.discourse-cdn.com/v4/letter/k/bbce88/32.png) [@kushiel](https://boards.straightdope.com/u/kushiel)
#### Post date: [November 17, 2010, 6:57pm UTC](https://boards.straightdope.com/t/simple-css-question-about-positioning/560995/4 "2010-11-17T18:57:51Z")

</div>

You are using position:relative, which makes your div be positioned relative to everything else on the page. The body and html elements have inherent margins and padding. If this is the very top element on the page, you can just make CSS rules for body and html that make the margin:0 and padding:0.

If there are elements coming before this one, it gets complicated. Changing your position to position:absolute will make your div leave the flow of the page - BUT only until the next highest element with position on it. So if div.top is within div.containTop and div.containTop has position on it, div.top will position itself at top:0 left:0 of div.containTop. But if there is no position on any elements containing div.top then it will position itself according to body.

---

<div class="post-metadata">

### Author: ![Cagey\_Drifter](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@Cagey\_Drifter](https://boards.straightdope.com/u/Cagey_Drifter)
#### Post date: [November 17, 2010, 9:05pm UTC](https://boards.straightdope.com/t/simple-css-question-about-positioning/560995/5 "2010-11-17T21:05:02Z")

</div>

> [@kushiel](#):
>
> You are using position:relative, which makes your div be positioned relative to everything else on the page. The body and html elements have inherent margins and padding. If this is the very top element on the page, you can just make CSS rules for body and html that make the margin:0 and padding:0.
> 
> If there are elements coming before this one, it gets complicated. Changing your position to position:absolute will make your div leave the flow of the page - BUT only until the next highest element with position on it. So if div.top is within div.containTop and div.containTop has position on it, div.top will position itself at top:0 left:0 of div.containTop. But if there is no position on any elements containing div.top then it will position itself according to body.

Great, that worked. Thanks!

---

<div class="post-metadata">

### Author: ![Duckster](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/duckster/32/1244_2.png) [@Duckster](https://boards.straightdope.com/u/Duckster)
#### Post date: [November 18, 2010, 2:21am UTC](https://boards.straightdope.com/t/simple-css-question-about-positioning/560995/6 "2010-11-18T02:21:59Z")

</div>

> [@kushiel](#):
>
> The body and html elements have inherent margins and padding. If this is the very top element on the page, you can just make CSS rules for body and html that make the margin:0 and padding:0.

And different browsers have different default values in CSS. A very popular method is to use CSS reset code that zeros out all default CSS values, regardless of the browser. You can then apply values so that your page looks almost identical in any of the Tier 1 browsers.  
[Here’s a very good explanation of CSS reset](http://www.maxdesign.com.au/articles/css-reset/). The only caveat is you really need intermediate to advanced web/CSS skills. And I don’t mean being proficient at Wordpress or other Easy-Bake Oven web tools. I’m talking working at pure code level skill.
