How can I remove right margin for a section element? [duplicate] - html

This question already has answers here:
Removing the default 8px margin from body
(3 answers)
Closed 3 months ago.
I'm trying to put a navigation bar with links at the very top of the browser screen. This bar will stretch all the way to the top, left, and right, with zero margins outside of it. I have already set the width to "width: 100%" in the CSS for this container. I have set margin-left, margin-top, and margin-right all at -8px because it appears putting a negative pixelation in is the only way to get those margins to go all the way to the edge.
For some reason, no matter what CSS properties I set, I cannot get that right margin to go all the way to the edge. Any ideas as to what I can try to get this stubborn margin to disappear? Just for kicks, I even set the right margin to negative 500px just to see. It had no effect on it. My right margin seems to be totally inaccessible. I would say that right now there is about a 5px margin on the right side that will not go away.
Please help.
.publicnavbarwrap {
width: 100%;
margin-top: -8px;
margin-left: -8px;
margin-right: -8px;
background-color: #CCC;
box-shadow: 5px 5px 5px;
#FFF;
}
body {
font-family: Quicksand, verdana;
background-color: #000000;
box-sizing: border-box;
background-image: url(../images/background.jpg);
background-size: cover;
}
<section class="publicnavbarwrap">
<div id="public_nav_bar">
Nav content
</div>
</section>

Remove the negative margins from .publicnavbarwrap and add this to the body:
body {
margin: 0;
}
Some browsers have a default margin for the body inside the user agent stylesheet

Related

Why do I get an offset on div's left with "width: 100%" property? [duplicate]

I am starting to work with css and have basic issue.
I have a div element:
.top {
background-color: #3B5998;
margin-left: 0px;
margin-top: 0px
}
<div class="top">...</div>
The colour code is taking effect (good).
The problem I have is that there seems to be a bit of white space on left, top and right of the div. How do I get rid of the white space? For example if you take a look at Facebook page, the top part is completely blue, there is no white space at the top.
You need to reset both the default padding and margin attributes in your stylesheet:
html, body {
margin: 0;
padding: 0;
}
As #Jason McCreary mentions, you should also look into using a reset stylesheet. The one he links to, Eric Meyer's CSS reset, is a great place to start.
It also looks like you're missing a semi-colon in your css, it should look as follows:
.top
{
background-color:#3B5998;
margin-left:0px;
margin-top:0px;
}
There's padding on the <body> of the page. You can fix this like so:
body
{
padding: 0;
}
I had the same problem . just try this :
html, body {
margin-top:-13px;
}
If you need some padding inside the div, you should choose padding:
padding:top right bottom left;
example:
padding:5px; /* 5px padding at all sides)*/
padding:5px 3px; /* top & bottom 5px padding but right left 3px padding) */
padding:5px 3px 4px; /* top 5px, bottom 4px padding but left right 3px) */
padding:1px 2px 3px 4px; /* top 1px, right 2px bottom 3px & left 4px) */
Similarly to control the space outside the div, you can use margin.
Margin will use exact same formula.
After long time I found the correct solution for me:
html, body {
margin: 0;
padding: 0;
overflow-x: hidden;
}
We need define the overflow in the horizontal.
If other answers don't work, try position:absolute; top: 0px; left: 0px; or display:flex.
I used this and it worked for me:
body {
background-position: 50% 50%;
margin:0px;
padding:0px !important;
height:100%;
}
the issue i had lately also, but even though i used padding:0px even added the !important on body didn't solved it... the actual problem was its position ... which you can do by using background-position:50% 50%; or by automatically let it choose the center position of the screen .. which is margin:0 auto; or margin:auto; that solved it for me ... hope for you all also. i realized the margin is what was needed after i tried #HAS's response thanks man ur awesome ... sorry for zombify the post
margin: 0px; would remove all spaces around the element.
padding: 0px; clears the area around the content
you can try:
html, body {margin: 0px; padding:0px;}
body {margin: auto;}
with margin:auto; the browser calculates a margin.
You can also use
* {margin: 0px; padding: 0px;}
this will remove all default margins and spaces. But be careful while using:
position: absolute;
The 'position' property can take 4 values, static, relative, fixed and absolute. Then you can use top, bottom, left, right properties to position your element. This depends on your layout. This link might be useful https://www.w3schools.com/css/css_margin.asp

How to stick pop up to top in CSS

I am trying to stick my pop up to top and make it a bit smaller to fit the screen.
Here is my landing page URL - yogavoga.com/2weekdiet
Any help will be appreciated.
.modal-content {
margin: 5px auto;
background-color: #fefefe;
border: 1px solid #888;border-width:3px;
width: 90%;
}
I'm not sure if this solves your question in full, because your sample code is a bit short and it doesn't show the element itself. I tried visiting your website, but can't find the element. So it is very difficult for us to say what you actually want.
margin is the space around your div element, in this case your modal. With your code you say your browser to put your element at the top, (0 margin at the top), and do the rest automatically. It does that and will center your element based on the width of your element.
You can scale your element with width. Make it smaller by reducing the percentage.
.modal-content {
margin: 0 auto; // 0 from top, left, bottom and right auto.
background-color: #fefefe;
border: 1px solid #888;
border-width: 3px;
width: 60%; // Width of your element.
}
TIP: remove the margin and padding presets from your body to have your element at the absolute browser border.

Bottom border CSS Margin

I am very new to this community and if this question has already been answered then I apologize I couldn't seem to find it on google or here under other questions.
I am trying to make a border for the body of the page that will not leave any space on any of the sides. I used margin to move the border to the edge for top, right and left but the bottom i am having a hard time with.
heres my CSS for the body border
body {
margin: 0 0 0 0;
background-color: gray;
border: 10px outset #596779;
height: 600px;
text-align: center;
}

Where does the 60px margin come from?

When I check the following code in the Chrome devtools (device toolbar, responsive) and the window gets smaller than 1040px width, the ".wrapper" suddenly get's an increasing right margin until 60px.
I really can't understand why it get's this margin. Can anyone explain this behavior or push me in the right direction?
My HTML-/CSS-Code:
body {
background-color: grey;
padding: 0;
margin: 0;
}
.wrapper {
width: 1040px;
margin: 0 auto;
background-color: red;
}
header[role="banner"] {
background-color: #fff;
padding: 20px 0;
}
<header role="banner">
<div class="wrapper">
<h1>Headline</h1>
</div>
</header>
The line "margin: 0 auto;"
actually means no vertical margin and spread the horizontal margin "automatically": That means there will be an equal margin on the left and right of your "wrapper" to fill in for what goes beyond the 1040 px.
I am positive this is to do with the browser default style that is applied. Try using a normalize or css reset file with your code and see if the style is still applied.

Removing space at the top left and right of div

I am starting to work with css and have basic issue.
I have a div element:
.top {
background-color: #3B5998;
margin-left: 0px;
margin-top: 0px
}
<div class="top">...</div>
The colour code is taking effect (good).
The problem I have is that there seems to be a bit of white space on left, top and right of the div. How do I get rid of the white space? For example if you take a look at Facebook page, the top part is completely blue, there is no white space at the top.
You need to reset both the default padding and margin attributes in your stylesheet:
html, body {
margin: 0;
padding: 0;
}
As #Jason McCreary mentions, you should also look into using a reset stylesheet. The one he links to, Eric Meyer's CSS reset, is a great place to start.
It also looks like you're missing a semi-colon in your css, it should look as follows:
.top
{
background-color:#3B5998;
margin-left:0px;
margin-top:0px;
}
There's padding on the <body> of the page. You can fix this like so:
body
{
padding: 0;
}
I had the same problem . just try this :
html, body {
margin-top:-13px;
}
If you need some padding inside the div, you should choose padding:
padding:top right bottom left;
example:
padding:5px; /* 5px padding at all sides)*/
padding:5px 3px; /* top & bottom 5px padding but right left 3px padding) */
padding:5px 3px 4px; /* top 5px, bottom 4px padding but left right 3px) */
padding:1px 2px 3px 4px; /* top 1px, right 2px bottom 3px & left 4px) */
Similarly to control the space outside the div, you can use margin.
Margin will use exact same formula.
After long time I found the correct solution for me:
html, body {
margin: 0;
padding: 0;
overflow-x: hidden;
}
We need define the overflow in the horizontal.
If other answers don't work, try position:absolute; top: 0px; left: 0px; or display:flex.
I used this and it worked for me:
body {
background-position: 50% 50%;
margin:0px;
padding:0px !important;
height:100%;
}
the issue i had lately also, but even though i used padding:0px even added the !important on body didn't solved it... the actual problem was its position ... which you can do by using background-position:50% 50%; or by automatically let it choose the center position of the screen .. which is margin:0 auto; or margin:auto; that solved it for me ... hope for you all also. i realized the margin is what was needed after i tried #HAS's response thanks man ur awesome ... sorry for zombify the post
margin: 0px; would remove all spaces around the element.
padding: 0px; clears the area around the content
you can try:
html, body {margin: 0px; padding:0px;}
body {margin: auto;}
with margin:auto; the browser calculates a margin.
You can also use
* {margin: 0px; padding: 0px;}
this will remove all default margins and spaces. But be careful while using:
position: absolute;
The 'position' property can take 4 values, static, relative, fixed and absolute. Then you can use top, bottom, left, right properties to position your element. This depends on your layout. This link might be useful https://www.w3schools.com/css/css_margin.asp