我創建使用下面的代碼,它封裝父元素中的SVG圖標的SVG圖標組件的SVG圖標孩子的身高:自動高度不堅持
HTML
<div class="icon-wrapper">
<svg class="icon">
<!--
The "icon-search" symbol comes from a SVG sprite in the doc body.
See live demo below...
-->
<use xlink:href="#icon-search"></use>
</svg>
</div>
CSS
body {
font-size: 48px;
color: black;
}
.icon-wrapper {
background-color: lightgreen;
}
.icon {
width: 1em;
height: 1em;
stroke-width: 0;
stroke: currentColor;
fill: currentColor;
background-color: red;
}
即使包裝div的高度設置爲auto
(它的初始值)它以某種方式在其底部添加了一些填充,因此比圍繞的SVG高几個像素。綠色區域不應該存在:
這是爲什麼?
這裏有一個活生生的例子,你可以玩:https://jsbin.com/huyojeniwi/1/edit?html,css,output
感謝爲什麼空間實際上是附加信息那裏! – suamikim
@disstruct這就叫*** kerning ***不*** *** spase ***,閱讀更多關於行內框[在這裏](https://www.w3.org/TR/CSS2/visuren.html#inline-盒) –
@Ahishek Pandey謝謝。看起來有趣 – disstruct