继承相对父级 div 宽度的绝对元素

发布于 2024-08-23 22:20:02 字数 437 浏览 4 评论 0原文

我试图将渐变定位在内联/内联块锚链接上,并让该渐变继承该父锚的宽度。问题在于跨度要么继承锚点父级的整个宽度,要么仅继承   的宽度。我无法让 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>&nbsp;</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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2024-08-30 22:20:02

据我所知,无法使用 position:absolute 来完成。

我不确定这是否对您有用,但是提供 a position:relativea span 怎么样

left: 0px;
right: 0px;
top: 0px;
bottom: 0px;

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 the a span

left: 0px;
right: 0px;
top: 0px;
bottom: 0px;

?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文