Why ul adds extra top margin?
The margin on the <ul>
comes from the default styling that a browser adds to the element. For example if you open Chrome's DevTools and inspect the <ul>
element you'll see styling like this. The user agent stylesheet refers to the browsers default styling. 1em
of margin becomes 16px
as the browser has a font-size: 16px
by default.
As the default styling isn't the same between browsers a common technique is to use a reset stylesheet, like Eric Meyer's Reset CSS or Nicolas Gallagher's normalize.css, to reduce these browser inconsistencies.
CSS ul is taking an extra space when trying to center it
<ul>
elements come with some inherent styling in the browser. If you set padding: 0
on your <ul>
in your css, you'll see that the green bar will be removed.
Does UL have default margin or padding
The problem is that by default, browsers have custom css - in chrome for example:
ul, menu, dir {
display: block;
list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;
}
You'll have to use a custom rule for your ul
:
element.style {
margin-left: 0px;
/* set to 0 if your not using a list-style-type */
padding-left: 20px;
}
why does adding a list element to body add extra padding to html? CSS
This margin is added by the <ul>
. Add the following to your stylesheet:
ul { margin-top: 0px; }
Updated Fiddle
I'm not sure why the <ul>
has a default top margin, nor do I know which browsers do this or if it's per spec, but I think it's safe to say that if you do not want a top margin, the safest bet is to always set it explicitly and not worry about what browsers do by default.
IE adds extra top-margin to every li-element
To get the behavior your looking for try "display: inline" instead of the "float: left". Add both:
ul#mainnav { display: inline }
ul#mainnav li { display: inline }
A great resource for info on customizing lists can be found on A List Apart.
Why is this ul exceeding the size of it's div?
Did you add a zip/uni reset to the top of your css file?
* { margin:0; padding:0; }
( Put that exactly as is at the very top of CSS to override browser default margins/padding ).
Most likely the ul
is being given default padding/margin, so this is to counter-act it.
CSS getting extra padding inside ul
You're forcing your first li
element to be displayed 15px from the top of the ul
element with a margin-top
.
Take out
#filtersContent section ul li {
margin-top: 5px;
}
#filtersContent section ul li:first-child {
margin-top: 15px;
}
Updated CodePen
UL has margin on the left
The <ul>
element has browser inherent padding & margin by default. In your case, Use
#footer ul {
margin: 0; /* To remove default bottom margin */
padding: 0; /* To remove default left padding */
}
or a CSS browser reset ( https://cssreset.com/ ) to deal with this.
Related Topics
How to Change Img Src Attribute Using CSS
Safari Print Media Queries Not Matching Other Browsers/Cutting Off
How to Use CSS to Distort Borders So They Look Like Sketched
Hide Content for Small and Extra Small Screen Size Devices
Global Disable Magnifying Glass on iOS 9 in Meteor Cordova App
Combining Pseudo-Selectors in CSS
How to Over-Ride an @Media CSS for a Material-Ui React Component
How to Style the Scrollbar of on Iframe
Using Position:Absolute to Set an Inputs Width
Why Is "Rgb (224, 226, 213)" an Invalid Property Value
How to Load CSS File Dynamically
Remove Padding from Unordered List
What Is a Parse Error and How to Fix It
Create CSS Grid Layout with Pure CSS
Did Chrome 40 Break Justify-Content CSS Overriding
Jekyll Syntax Highlighting Not Working - Classes Are Not Being Added