I am a little confused on how to get a repeating image with html and css. Here I have this code:
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="style.css" media="screen" />
</head>
<body>
<div id="top_background"></div>
</body>
</html>
and then in style.css:
/* Reset CSS */
html, body, div, span, h1, h2, h3, h4, h5, h6, p, img, ul, li, fieldset, form, label { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; vertical-align: baseline; background: transparent; }
ol, ul { list-style: none; }
:focus { outline: 0; }
/* Content */
#top_background { background: url(images/header.png) repeat-x; }
But when I load the file it's just a blank web page. Taking out the 'repeat-x' doesn't change anything. I am fairly new to html and css, so I could be doing something completely wrong. Thanks!
Since it's empty, your <div>
has 0 height
.
You should set a height in CSS.
body
I would reconsider publishing it at all - powerbuoy 2012-04-04 03:02
The reason is in your css dimension of id="top_background"
is not set. By default div contains it width 100% because div is block level element.
In your case you are repeating background image so we have to set the height of the div to see the background image.
Its up to you how much width and height you want to set.
For example: You want to repeat your background image upto 600px
and 200px.
For that see below css
#top_background
{
background: url(images/header.png) repeat-x;
width:600px;
height:200px
}
You have not defined height into your #top_background thats why image is not repeating.
so whenever you repeat the image on y-axis or x-axis check the width height and set it according to your requirement.
now you can just add the mentioned below css and can set the width according to your requirement.
#top_background
{
background: url(images/header.png) repeat-x;
height:200px
}