我的问题很简单:在绝对定位的元素内嵌入块元素会发生什么?我有一个小例子来说明我的意思。否则很难解释。现在的问题是,为什么.icon
内.tag
的不定位像以前.icon
(即在线和文本的右边)嵌入块内部位置:绝对元素
下面的代码可以被看作@http://jsbin.com/itole4/5
<html>
<head>
<style>
.field { position: relative; border: 2px solid black;}
.tag { position: absolute; left: 100%; top: -2px; background: black; color: white;}
.icon { width:16px;height:16px; display: inline-block; background: gray; text-indent: -999px;}
</style>
</head>
<body>
<a>Some text <span class='icon'>X</span> </a>
<h2>
<span class='field'>Some Text<span class='tag'> tag<span class='icon'>x</span></span></span>
</h2>
<h2>
<span class='field'>Some Text</span>
</h2>
</body>
</html>
这可能是因为您未关闭所有跨度。 此行缺少一个: <跨度类= '场'>某些文本<跨度类= '标签'>标记的 X – Thorgeir 2011-04-09 17:00:35
良好的观察,这没有解决但问题。我认为Chrome浏览器很聪明,可以在看到''时关闭该标签。 – noio 2011-04-09 18:30:47
您可以尝试为.tag定义宽度,以确保它不会环绕。 – tkm256 2011-04-09 18:36:30