html - inline-block vertical centering issue -


I have the following simple code snippet. It is taken from my application where A1 is a container button, in which there is an icon, the icon should be raised vertically by the parents-line height / height, but it has been moved from above to 1px Can you please explain to me why this behavior is ? Is there a solution?

  .a1 {display: inline-block; Width: 28px; Line-height: 28px; Background-color: # 000; Text align: center; Vertical-row: middle; } .i {display: inline-block; Width: 16px; Height: 16px; Background color: #F00; Vertical-row: middle; }  
  & lt; Div class = "a1" & gt; & Lt; I class = "i" & gt; & Lt; / I & gt; & Lt; / Div & gt;  

Why?

Because inline block elements present with "white-space" you can see it in this , where there is no height / width on the original element .

When you vertical-align: medium; , the "white space" element is provided before (at the top) (black line in the demo). This space takes the child element down and therefore it does not appear vertical centered.

How to fix:

You can use the display: block; Calculate the margin to apply the hair element, so that it is located in vertical and horizontal.

You can see how to talk about white space and ways to avoid them.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -