继承相对父级 div 宽度的绝对元素
我试图将渐变定位在内联/内联块锚链接上,并让该渐变继承该父锚的宽度。问题在于跨度要么继承锚点父级的整个宽度,要么仅继承 的宽度。我无法让 span 元素正确继承宽度,同时保持锚点内联显示。
CSS
a { width: auto; display: inline-block; }
a span { background: url(../images/fade_h1.png); width: 100%; height: 12px; position: absolute; display: block; z-index: 3; }
HTML
<a href="index.php"><span> </span>Index</a>
I am trying to position a gradient over an inline / inline-block anchor link, and have that gradient inherit the width of that parent anchor. The problem is that the span either inherits the entire width of the anchor's parent, or just the width of the . I am unable to get the span element to properly inherit the width while maintaining the anchors inline display.
CSS
a { width: auto; display: inline-block; }
a span { background: url(../images/fade_h1.png); width: 100%; height: 12px; position: absolute; display: block; z-index: 3; }
HTML
<a href="index.php"><span> </span>Index</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,无法使用
position:absolute
来完成。我不确定这是否对您有用,但是提供
a
position:relative
和a span
怎么样?
Can't be done with
position: absolute
as far as I can see.I'm not sure whether this will serve you, but how about giving the
a
position: relative
and thea span
?