This question already has answers here:
How wide is the default `<body>` margin?
(4 answers)
Closed 7 years ago.
Background picture has margin top,left and right, trued to remove it with position absolute and relative, didn't worked what can true else to remove them.
HTML
<header class="banner"></header>
Css
banner {
background-image: url(../images/banner.jpg);
min-height: 750px;
background-size: cover;
background-position: center top; }
CSS
body {
padding:0;
margin:0;
}
You can use too reset.css;
http://meyerweb.com/eric/tools/css/reset/
This seems to be initial margin of HTML page. Remove it through CSS:
body{margin:0}
This is being added by either the body or the header. Add the following to the CSS stylesheet:
body {
margin: 0;
}
Or, the same thing with the body replaced with header.
Related
This question already has answers here:
Webpage not 100% Width
(5 answers)
Div with 100vw of width doesn't fit to the screen
(4 answers)
CSS width:100% not full screen
(2 answers)
Closed 3 months ago.
Why aren't the top, left, and right edges of the red p element's border not directly aligned with the top, left, and right edges of the viewport?
body {
background-color: green;
}
p {
padding: 0px;
background-color: red;
margin: 0px;
border-style: solid;
}
<!DOCTYPE html>
<html>
<body>
<p>p tag</p>
</body>
</html>
The document's body has a default margin of 8px. To solve your issue, set body's margin to 0px:
body {
margin: 0px;
}
It's because your browser user agent stylesheet by default has some spacing. Add the following code on top of your CSS:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
it should disable body margin like this, but use (*) sign cause other elements might also have
This question already has answers here:
How wide is the default `<body>` margin?
(4 answers)
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
What are the default margins for the html heading tags (<h1>, <h2>, <h3>, etc.)?
(4 answers)
Closed 3 years ago.
I have a basic HTML page that contains one div in my body: Container. There is a background image that I'm using to cover the entire width of the page. However, the image doesn't cover the entire page instead it leaves a margin around the top, bottom, left, and right.
In addition, I added an overlay using Container::After, but it also doesn't cover the entire image - it leaves a margin too.
Solutions I tried:
Doing some research, I found that HTML displays elements using inline. So, I tried changing the display to flex. In addition, I even tried to float my container to the left. However, nothing worked. The only thing that worked was adding negative margins to my container and the whitespace was removed. However, when I added an h2 element - the whitespace came back.
I'm not sure what is occurring here? Any suggestions would be great. Below is my jsfiddle:
https://jsfiddle.net/fun_code11/zcqm1w5u/2/
.container{
background-image: url("https://images.unsplash.com/photo-1522202176988-66273c2fd55f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=751&q=80");
background-size: cover;
background-repeat: no-repeat;
position: relative;
height: 600px;
margin-top: -10px;
margin-left: -10px;
margin-right: -10px;
}
.container::after{
content: " ";
position: absolute;
display: block;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
}
You should remove the top margin from the h2. That causes the whitespace. You can do sth like h2 { margin-top:0 }
This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
How wide is the default `<body>` margin?
(4 answers)
What are the default margins for the html heading tags (<h1>, <h2>, <h3>, etc.)?
(4 answers)
Closed 3 years ago.
There seems to be a margin above my image although I haven't set it that way.
I've even tried setting margin-top to 0, but this doesn't fix it.
#header {
background-image: url(https://s3-eu-west-2.amazonaws.com/theartonlinegallery-wp/wp-content/uploads/20180627134442/london-cityscape.jpg);
background-repeat: no-repeat;
height: 350px;
background-position-x: 100%;
background-posititon-y: 75%;
background-size: 1400px;
opacity: 0.8;
text-align: center;
font-family: "Poiret One";
color: white;
margin-top: 0px;
}
<div id="header">
<h1>Investment Blog</h1>
</div>
If you run the code snippet you posted and look at the computed styles, you'll see that while the div does indeed have a margin-top of 0, the h1 block containing "Investment Blog" inside of it does NOT have a margin-top of 0. You'll have to do additional styles for the title.
It's because the body tag has default values that you don't see.
Try to add body { margin:0px; padding:0px; } to your CSS file and it will set the default padding and margin to 0.
You need to set margin to 0 for both the body and the h1, like:
body,
#header h1 {
margin-top: 0;
}
This question already has answers here:
How to remove margin space around body or clear default css styles
(7 answers)
Closed 4 years ago.
I've got several divs on my webpage with background images. Currently it's what I want, but with white borders on the side and top/bottom (for those divs at the top/bottom of page).
This is the current situation:
My webpage - notice slight white border around photo
I'm trying to get it to fill the browser (instead of having borders), but none of the other suggestions are working for me. Below is my code for one div:
<div class="header-image">
<img src="smesh-colour-hires.png">
</div>
And CSS:
.header-image {
background-image: url("animals-deep-ocean-deep-sea-130621.jpg");
background-size: cover;
background-position: center;
height: 500px;
margin: auto;
display:flex;
align-items:center;
justify-content:center;
}
.header-image img{
max-width: 800px;
}
Let me know if anything doesn't make sense and I'll try my best to explain.
Any help would be much appreciated, this is really blocking me!
The white border is probably due to the default margin on the body.
Try adding this in your CSS.
body {
margin: 0;
}
Add this to the top of your CSS
body, html {
margin: 0;
padding: 0;
}
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Center contents of webpage
I have followed the way to make webpage center aligned but the site still is left aligned. Please help out. Thanks
#parent{
margin:0 auto;
width: 960px;
}
<div id="parent">
<!--more code goes here-->
</div>
In some browsers you still have to put a text-align on the body to make it work:
body {
text-align: center; /* this helps some browsers align the #parent element */
}
#parent{
margin:0 auto;
width: 960px; /* a fixed width is mandatory for margin auto to work */
text-align: left; /* this resets the contents alignment */
}