Open aosmond3 opened 8 years ago
Hi @andrewosmond,
there are some elements in HTML that contain default margins (such as <h1>-<h6> and <p>
) but no margins are inserted automatically by Brackets. Can you provide some code that has unexpected margins?
<p id="first"><span class="top" id="address">10304 Partnership Court, Williamsport, MD 21795</span><span class="top">301-223-9444</span></p> <img id="logo" src="DCCasework%20Logo.gif" alt="DCCasework Logo">
@petetnt The body element has a top margin of 10px. The p element has a bottom margin of 10px and the has a top margin of 10px. Setting margin: 0px; does not work. Margin: -10px; does work.
@andrewosmond The <p>
element has 1em
margins on both top and bottom by default on at least Chrome and Safari (I think on Firefox it might have only the bottom one).
See the following fiddle: https://jsfiddle.net/4eqvb46d/ where the default margins are removed from the second <p>
-tag.
There's utilities such as Normalizer which normalises these behaviours across browsers.
@petetnt
How exactly did you remove the margins from the second <p>
-tag? Also, these margins occur for every element (e.g. there is a 20px space between the body element and the actual top of the page.
I'm in 9th grade and i haven't taken a programming class before so i appreciate the help.
I seem to remember that Live Preview injects a margin to have a place to display error messages, but I couldn't find where that's done with a quick look at the code. As long as your page looks ok in normal browser, then I wouldn't worry about it.
@redmunds Checked it out, no default margins for anything by default 🎉
@andrewosmond I used an id CSS selector #second
to target the second p
-element, and set that p
-elements margins to 0.
#second {
margin-top: 0;
margin-bottom: 0;
}
Developers tools that ship with most browsers are a super valuable tool for new learners like yourself. Check out Google Chromes one for example: https://developer.chrome.com/devtools
Then if we have this really simple page:
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<p>Test</p>
</body>
</html>
and you open the developer tools, move your mouse over to the <p>
-element you can see that it has margins by default (marked in orange):
You can also see that <body>
element has also some margins:
Which you can remove with some CSS
body {
margin: 0;
}
p {
margin: 0;
}
There are utilities that do this for you, like CSS Reset that you can add to your page. The default styles are there to aid you building sites that "flow" by default, so you can have paragraphs and such by just by writing text, so be weary of reseting them completely!
In the live preview feature of brackets, all of my elements have a top margin of 10px. I can eliminate this margin by setting the margins to -10px, but margin: 0px; does not work. I am new to programming and i am wondering if this is something in settings or just a bug.