I know there’s another question like this but I tried it and the answer didn’t work.
I have a p with a div and I want to be able to use a reverse (negative) margin on the p. At the moment it’s not effecting the p but the containing div.
Here’s the code :
.reset {
margin-left:4px;
margin-top: 4px;
height:50px;
width:50px;
background:#FFF;
}
.reset p {
margin-top:-4px;
font-size: 38px;
font-family: sans-serif;
text-align: center;
}
Thanks in advance
It doesn’t work because your
pis the first element of yourdiv. As a result, the margin-top of both yourpanddivare somewhat merged.For example, if you put
margin-top: 20pxon both yourpand yourdiv, it will only result in a 20px top margin, not 40px.The easiest way is to use
position: relative;:This way, the
pis still in the usual flow, but you move it 4px up.