How do negative margins in CSS work and why is (margin-top:-5 != margin-bottom:5)?


HOME ยป Web Design

A common trick for vertical positioning elements is to use the following CSS:


.item {
position:absolute;
top:50%;
margin-top:-8px; /* half of height */
height: 16px;
}

When seen in the metric view as in Chrome this is what you see:



However, there is no visual margin depicted when you hover over the element i.e. the margin is 'outside' the border and can be visualized. But negative margins don't show up. How do they look and what is it that makes it different?


Why is margin-top:-8px not the same as margin-bottom:8


Related to : How do negative margins in CSS work and why is (margin-top:-5 != margin-bottom:5)?
margin-top and margin-bottom inside floated div not working
Web Design

I have a problem with margin-top and margin-bottom for some elements inside a floated div.


It's a column div floated to the right (I have also 2 other column divs floated to the left)


Demo here:
http://jsfiddle.net/zTb3g/


I need the "float" to adjust columns in the page, but the margin-top and margin-bottom don't work in some of the elements (ex: b, label, a), yet it works normally for other elements (ex: p, input).


I tried a lot of clearing styles in different places of the markup. Hope someone can help.


Thanks


How do negative margins in CSS work and why is (margin-top:-5 != margin-bottom:5)?
Web Design

A common trick for vertical positioning elements is to use the following CSS:


.item {
position:absolute;
top:50%;
margin-top:-8px; /* half of height */
height: 16px;
}

When seen in the metric view as in Chrome this is what you see:



However, there is no visual margin depicted when you hover over the element i.e. the margin is 'outside' the border and can be visualized. But negative margins don't show up. How do they look and what is it that makes it different?


Why is margin-top:-8px not the same as margin-bottom:8

What is the rationale behind margin-top: auto and margin-bottom: auto amounting to 0 margin?
Web Design

Since margin-right: auto and margin-left: auto center an element horizontally, I would expect their vertical counterparts to behave in the same way.


Yet I understand this does not happen, as per CSS specs:


10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements

If 'margin-top', or 'margin-bottom' are 'auto', their used value is 0.


Also applies to block elements:


10.6.3 Block-level non-replaced elements in normal flow when 'overflow' computes to '
Why does margin-top work, but margin-bottom doesn't?
Web Design

I have the following HTML markup and I want the menu div tag to always be 5px away from the bottom border of the parent container.


I can manually through trial and error position it using margin-top, but if I were to change the logo or modify the div size I'd have to change this value again using trial and error. A much better solution would to tell if to always be 5px away from the bottom instead of telling it to be X pixels from the top.


Why doesn't this work though?


<body>
<div id="header">
<img src="../../Content/images/cumaviLogo.png" alt="Cumavi.com - Compras y ventas online
Will the Screen fit to all devices if i use margin top's and margin bottom's in XML in Android
Web Design

I am developing an application in which i need to use lot of text-views and i am using a relative layout.Since i positioned my text-views in different coordinates(margintop=20dp),will the layout fit for all the android devices(tabs,Nook color phones,normal devices etc)


Any suggestions are highly appreciated
Thanks in advance.


On paragraphs, should I define bottom margin only or top margin also?
Web Design

Hi!
Should I do this?
p
{
margin-top: 2em;
margin-bottom: 2em;
}
or this:
p
{
margin-bottom: 2em;
}
Same question for headers (h1, h2, etc)
Thanks!


Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .