简体   繁体   中英

Why margin-top doesn't work for <i> element?

Here is my code:

 .fa-caret-down{ margin-top: 3px; padding-top:3px; line-height: 3; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> <div><span>something</span> <i class="fa fa-caret-down" aria-hidden="true"></i></div> 

As you see, none of padding or margin or line-height don't make my expected effect. Here is expected result:

在此处输入图片说明

How can I get that?

Note: Based on my real codes, I shouldn't use position: absolute; for that <i> element.

The margin / padding / line-height is working, you just have to add vertical-align:top to span

  span{ vertical-align:top; } .fa-caret-down{ margin-top: 3px; padding-top:3px; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> <div><span>something</span> <i class="fa fa-caret-down" aria-hidden="true"></i></div> 

Here is the changes which works

 .fa-caret-down{ top: 6px; position : relative; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/> <div><span>something</span> <i class="fa fa-caret-down" aria-hidden="true"></i></div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM