DIGIT-ARC read-only archive · snapshot: July 23, 2026

Problem with horizontal bar in HTML-CSS

4 posts · originally from https://geek.digit.in/community/threads/problem-with-horizontal-bar-in-html-css.150922/

gdebojyoti
gdebojyoti Original post #1
Jan 5, 2012 at 12:29 PM
I wanted to create a horizontal bar at the top of my HTML web page. I used the following code for that:

Code:
<html>

<body>

	<div style="width:100%; height:40px; background-color:olive; margin: 0 0 0 0;" align="center">
		Hello
	</div>

</body>

</html>

But a white space appears all around the bar. ( *www.debojyotighosh.com/projects/isn/test1.html )

Is there any way by which this space can be avoided (other than using negative values in "margin")?
Sujeet
Sujeet #2
Jan 7, 2012 at 3:45 AM
:neutral::neutral::neutral:add padding:0 and margin:0 attribute to body!!!!


Code:
<html>

<body style="margin:0; padding:0;">

	<div style="width:100%; height:40px; background-color:olive; margin: 0 0 0 0;" align="center">
		Hello
	</div>

</body>

</html>
buddyram
Jan 7, 2012 at 10:00 AM
^^I guess body tag adds some value to margin and padding attributes by default
does it?
gdebojyoti
Jan 7, 2012 at 8:52 PM
@Sujeet: Thanks a lot! It worked. :)

@buddyram: Yup. Seems like that.