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;
}
Related
I've used every trick in the poorly-documented book (bad joke pun intended) and there is still a white border around my background image. I am using Bootstrap but I've slapped important tags everywhere it counts, so I doubt that is what is causing the issue. If the issue can be resolved using Bootstrap 5, that would be great. I want to minimize the amount of CSS code I use in this project.
html, body {
background-image: url("./background.gif");
background-repeat: no-repeat;
height: 100vh;
width: 100vw;
background-color: black;
margin: 0!important;
padding: 0!important;
background-size: 100% 100%;
}
Screenshot of webpage
Just remove the border classname on the first div child of body. This adds a 1px solid border by default.
It's working even without your margin and padding set to 0!important in body since you have a _reboot css that already resets the body to margin 0.
This question already has answers here:
How wide is the default `<body>` margin?
(4 answers)
Closed 3 years ago.
I don't quite understand why the footer (and the header) doesn't take up all the space?
I divide the <body> part in 3 sections: 1) div header, 2) div wrapper, 3) div footer (so that I could control each part separately).
Div wrapper (which is supposed to be narrow)
.wrapper {
display: block;
width: 100%;
max-width: 980px;
margin: 20px auto;
padding: 20px;
border: 1px solid black;}
Div footer (which is supposed to be 100% wide on the screen)
.footer {
margin: 0px;
padding: 0px;
background-color: black;
height: 200px;
color: orange;
width: 100%;}
How can I make it cover all the space (like on this website, the header takes all the space, but the main content part is way more narrow).
Thank you in advance!
The footer (which is black) doesnt take up all the space and leaves some background
The footer (which is black) doesnt take up all the space and leaves some background
Seems like you didn't reset the default margin for body which most browsers add by default. To do so, add this:
body {
margin:0;
}
There's more than one way to solve this and there's more than one reason for which the problem could be generated in the first place, so don't tread if different people give you different answers :)
The problem I most usually see when this comes up is generated by a father element not having full width, or having a padding that's bigger than zero. (Probably the body.)
If that's not where the problem lies, then try with these media queries (One at a time).
width: -webkit-fill-available;
width: 100vw
This question already has answers here:
How wide is the default `<body>` margin?
(4 answers)
Closed 3 years ago.
I have a white border around my entire website right now that I am trying to get rid of. I looked it up online and found several sources that all say to set margin: 0; but when I did this, it is not removing the white border. I suspect it has something to do with using view width and view height instead of pixels or percentages, so how can I remove the white border without changing the width and height from using the viewport size?
.container {
width: 100vw;
height: 100vh;
background: purple;
margin: 0;
}
<div class="container">
</div>
you have to set the margin: 0 property on body not on the div container, hope it helped
body {
margin: 0;
}
.container {
width: 100vw;
height: 100vh;
background: purple;
}
<div class="container">
</div>
* {margin: 0; padding: 0}
I recommend checking basic universal css boilerplate
I created a div where I plan to a title for my webpage, I set the width to 100% but there was still white on the sides and top. I got the top to disappear but the sides won't, I assume it's got something to do with the movement of the div, I've checked everywhere, but everyone has different divs for different purposes so I couldn't find the answer. In case you guys wanna show an example of your solution you could do so here
Here is the HTML:
<div id="toptitle">
</div>
For my CSS I tried using margin-left: -8px and the same for the right side but they don't work like that, it's only movement of the div and even when I don't set the left side yet the right still won't move till there's isn't a white gap:
#toptitle {
width: 100%;
height: 140px;
background: #42647F;
margin-top: -15px;
}
Reset your body margin. Also make a research for reset css.
body {
margin: 0;
}
Add margin: 0 to the body :
body{
margin:0;
}
You are missing body margin, please have a look at the below working snippet taken from your codepen. and there is no need to have negative top margin too.
body {
margin: 0
}
#toptitle {
width: 100%;
height: 140px;
background: #42647F;
}
<div id="toptitle">
</div>
The body tag has a default margin of 8px which you have to remove. So just add this to your code:
body{
margin:0;
}
You should also remove margin-top:-15;
Hope this is clear to you!
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.