When we are creating a web page using bootstrap we can set margins. But web browser also gets some margins. Although code as div(class="container-fluid") or code as margin:0; and padding:0; based on the container in the CSS file, I couldn't solve the problem. Can you help me?
Some browsers have a margin on the body tag. Set that to 0 somewhere in your css.
body {
margin: 0;
}
This is Browser default margin for body:
Fix It Like this:
body {
margin:0;
}
Set the margin to zero on any element is simple just type something like
body{
margin:0
}
Although sometimes bootstrap has his own margin rules included like setting margin on h tags, you could remove them as well by using more specific rules (read about specificity here) or by using important
h4{
margin: 0 !important
}
The reason for that is browsers have default styling for elements.
To reset margin only on body element you can use:
body {
margin: 0;
}
To reset all styling (which is not so-bad thing) in all browsers you can use css library called normalize.css.
Normalize.css makes browsers render all elements more consistently and in line with modern standards. It precisely targets only the styles that need normalizing.
This library is used by big companies as GitHub, Twitter, Soundcloud, Guardian, Medium and many others.
Although you put container-fluid, sometimes it doesn't make the width 100% fit the screen because browsers make a default margin and padding.To make it fit the screen you have to do like this.
body{
padding: 0;
margin: 0;
}
If it doesn't work make them important as following.
body{
padding: 0 !important;
margin: 0 !important;
}
Related
I'm learning CSS, and trying to make a default rule:
* {
margin: 0px;
padding: 0px;
}
It's not working, and I don't know why... can you please point me in the right direction?
Its certainly because your body has padding of 50px; which overwrites the rule of html as far your page's body is concerned.
Edit :
body
{
margin : 0px;
padding : 0px;
}
hope you problem is solved now.. :)
Add first you should include a normalize stylesheet. The different browsers have different default styles and this stylesheet will bring one standard to all browsers.
http://necolas.github.io/normalize.css/
I think this will help you ;)
body {
margin: 0px !important;
padding: 0px !important;
}
On CSS part don't use html comment. Thats reason, why doesn't work your css part.
LIke this please write margin and padding in body tag
you have used padding:50px; in your body tag please remove padding,thats * not working properly
DEMO
body{
margin:0;
padding:0;}
here both of working please check demo
*{
margin:0;
padding:0;}
Your are using unordered list to create menu.
by default, It has those intend properties, you can override by using below code, which is not advised.
*{
margin : 0px;
padding : 0px;
}
Demo 1 & Demo 2
Also change background-color : ABC; to background-color : #ABC;
I'm having some trouble with the margin-left CSS property. I have some nested unordered lists. This is what the list looks like with no change to the margin-left (in both IE and Chrome):
I wanted to decrease how much each list is indented so I added this CSS code:
ul li ul
{
margin-left: -25px;
}
This works fine in Chrome, which displays this:
However, IE 8 displays it like this:
I guess the origin of where the margin starts is different between the two browsers? How can I achieve the desired affect of decreasing the indentation of nested unordered lists among all browsers?
You should look into "zero-ing out" the margin and padding for ul and li's like so:
ul,li { margin: 0; padding: 0; }
As different browsers have different defaults. From there, you should be able to add your own margins and paddings as desired.
It's a good thing to use always a CSS reset. This will avoid having differences among browsers. You could use a universal reset like;
* {
margin: 0;
padding: 0;
outline: 0;
/* etc */
}
Or going a bit deeper and use Eric Meyer's one or anyone else. There are a few.
Anyway, in your case instead of play with negative margins, you should reset your margin and padding for ul and li elements:
ul, li {
margin: 0;
padding: 0;
}
I suggest http://necolas.github.io/normalize.css/ or a standard reset css stylesheet
Different browser set different default settings.
Is this valid CSS for browser reset? What does it do? I have been using this for a long time.
html,body,div,ul,ol,li,dl,dt,dd,h1,h2,h3,h4,h5,h6,pre,form,p,blockquote,fieldset,input,hr {margin:0; padding:0;}
h1,h2,h3,h4,h5,h6,pre,code,address,caption,cite,code,em,strong,th {font-size:1em; overflow:hidden; font-weight:normal; font-style:normal;}
ul,ol {list-style:none;}
fieldset,img,hr {border:none;}
caption,th {text-align:left;}
table {border-collapse:collapse; border-spacing:0;}
td {vertical-align:top;}
This is a version of Eric Meyer's CSS reset. You can read about it here:
http://meyerweb.com/eric/thoughts/2011/01/03/reset-revisited/
The goal of a reset stylesheet is to reduce browser inconsistencies in
things like default line heights, margins and font sizes of headings,
and so on.
And here's a history of why and how it came to life: http://sixrevisions.com/css/the-history-of-css-resets/
Yes, it's a type of CSS reset. It basically resets all the default spacing to zero and all the default alignments to left-top, as well as resetting the font sizes and weights of all the headers. The purpose of CSS resets is to make the website look consistent across all browsers.
I don't really like extensive CSS resets, though. Here's mine:
* {
margin: 0;
padding: 0;
}
img {
border: none;
}
table {
border-collapse: collapse;
}
It works fine.
I had a problem to use it with bootstrap wysihtml5 library.
In fact when I try to use italic o bold style, it didnt work.
To make it works I had to delete tag "i" and "b" from this file.
Starting with:
html, body
{
padding: 0;
width: 100%;
font: 100%/1.45em "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
}
Chrome decides that the width should be 1600px, which is wider than my current display, let alone the current Chrome window. I'm sure this is an old chestnut, but I'm failing to find the right tree.
I posted a complete example to git://github.com/bimargulies/css-mystery.git.
One note: My macbook was plugged into a very wide monitor, and is now not. The 1600px seems to me to be related to that, but I don't know how to make it go away except to reboot.
In the chrome devo tools, looking at the effective styles for the , I see:
width: 1600px;
html, body - 100%
That 1600 is very mysterious. And this is after a reboot.
EDIT bingo: buried in the style sheet main.css, from someone else I work 'with', was 'minWidth: 100em;' on body. oops.
You need to add margin: 0 to remove the default margin on the body element.
Are you sure you need width: 100%?
html and body are by default "full width" due to being block-level elements.
Try using a CSS reset...
http://meyerweb.com/eric/tools/css/reset/index.html
... to set all CSS properties to their default values.
I hope this helps.
Hristo
For the record, I think it's best to actually have the explanation in an answer.
There was another CSS clause way down the file:
body
{
minWidth: 100em;
}
I didn't spot it, and the Chrome 'Computed Styles' box does not include this in the 'explanation' of the 1600px in the same way that it include width styles.
I had same issue. could be other div in body is having padding or margin.
margin or padding can cause it.
in my case, was padding
When I declare some base styles for my site I have used to do that on the body tag. Like for example
body {
font-size: medium;
line-height: 1.3em;
}
But I have also seen people do things like that on the html tag. And on both. Where should it be done? Should some be at one and some at the other? Should all be on one of them? Or does it simply not matter at all? Or?
I like applying base declarations to html. Most of the time, I use body as a container, like so:
html {
/* Base styles go here */
font: 14px/1.5 Arial, sans-serif;
background: darkgreen;
}
body {
background: lightgreen;
padding: 0 20px;
width: 920px;
margin: 0 auto;
}
View the demo: http://jsbin.com/atiso3
Most people tend to use additional DIVs just to accomplish this basic behavior. It’s not necessary when you know how to use html and body in CSS ;)
I'd add styling on the body tag as it makes more semantic sense (you're not going to style the head, title and so on).
Also I don't see a lot of people adding styles directly on the html tag anymore except to reset some default styles...
For the strict doctype, only body is necessary. However if the browser is in quirks mode, you'll very likely need to target table cells as well.
In both cases you may want to also target form elements, since they generally inherit the platform default.
html is the container for body, so the latter will inherit from the former. Be careful when mixing:
html, body { font-size: 80%; } will make your body's font size to be 80% of 80%.
I always go for html, but there is an issue with ancient browser support and/or quirks mode.
From my personal experience, the only situation where putting certain base styles on both html and body is necessary is when you're doing some funky hacks that rely on 100% width or height ("sticky" divs or some such). In all other situations, it is perfectly OK to declare the base styles only on body. In other words,
html, body {height:100%}
might actually be necessary, but
html, body {font-family:Arial}
certainly won't. After all, all the elements on which you'll need the font-family will be children of body anyway, so there's no point in specifying it for html, too.
I would either set to body itself. I tend to do that or a use a base div style, depends on what I'm doing, but putting it on the html object seems unintuitive.