Jump to content

How to remove background image spacing in div?


Yamcha
 Share

Recommended Posts

Hi Guys,Anyone know how I can remove spacing in div tags? I'm going to be using two different backgrounds, which is why I went with a div tag, the problem is there is spacing on all four sides..Appreciate your help, Thanks! I'm a noob so still learningPreviewscreenshot20110420at111.png

<html>		<head>		<style type="text/css">		#bgtop {background-image:url(top_bg.jpg); background-repeat:repeat-x; height:396px;}		</style>		</head>			<body>				<div id="bgtop">		</div>										</body></html>

Edited by Yamcha
Link to comment
Share on other sites

All browsers have a default margin around the body. Other elements have unpredictable margins and padding. Experienced developers reset these values (and others, too) with the following CSS. Note that * is the universal selector. A ruleset for * applies to every element in the document. (Those rules can be overwritten by other rules, of course):

* {   padding: 0;   margin: 0;}

Make that the first ruleset in your stylesheet.

Link to comment
Share on other sites

Thanks a lot, it worked! But I've run into another problem, the second background that supposed to be under the first is not showing up, I'm not sure if I'm doing anything wrong or if i'm missing something, the second background has to repeat both ways..Example2lx9gjs.png

<html>		<head>		<style type="text/css">		#bgtop {background-image:url(top_bg.jpg); background-repeat:repeat-x; height:396px;}		#bgbottom {background-image:url(bottom_bg.jpg); background-repeat:repeat-x repeat-y; height:auto;}		body {margin:0px; height: auto;}		</style>		</head>			<body>					<div id="bgtop">		</div>					<div id="bgbottom">		</div>		</body>		</html>

Edited by Yamcha
Link to comment
Share on other sites

#bgbottom has no background because it has no height. You can define a height for it with a height rule. It will also gain height if you add any content to it. You can see this for yourself just by typing a few text characters.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...