<style>
.jf-header-box {
width: 1100px;
height: 50px;
margin: 0 auto;
background-color: https://api-v5.segmentfault.com/question/-sharp3a5795;
}
.jf-no-login-box {
float: right;
}
.jf-login-user-img {
float: left;
margin: 6px 20px 0 0;
}
.jf-login-user-img img {
width: 40px;
height: 40px;
}
</style>
<div class="jf-header-box">
<div class="jf-no-login-box">
<a href="https://api-v5.segmentfault.com/question/-sharp" class="jf-login-user-img">
<img src="http://jfinal.com/upload/avatar/18/93704.jpg">
</a>
</div>
</div>
here a
is an inline element, which is set to float float: left
, and margin
is displayed effectively.
float: left
at this point, change
to < div class=https://api-v5.segmentfault.com/question/" jf-login-user-img https://api-v5.segmentfault.com/question/"> < / div >
, margin
shows the effect again.
automatically becomes a block-level element after you set a float for an in-line element.