RSM RSM - 1 year ago 67
HTML Question

Css div wont go to the top or all the way to the sides

I have started a website with a redbackground and i want a little bit of white at the top.

i have this code:


body {

background-color: #ff4d4d;
#header {
background-color: #ffffff;
height: 20px;


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Fat Oblongs</title>
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" media="screen" />
<div id="header"></div>


Which produces:

Answer Source

You should make sure your body and html elements have no margin and padding:

html, body {
    padding: 0;
    margin: 0;

Sidenote: you also really should not use XHTML 1.0 Transitional as your doctype. If possible, simply use HTML5 (this has no influence over your borders, but still, don't use transitional doctypes unless you have a very good reason to do so)

<!doctype html>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download