绝对元素继承相对父div的宽度 [英] Absolute element inheriting relative parent div's width

查看:253
本文介绍了绝对元素继承相对父div的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个inline / inline-block锚点链接上放置一个渐变,并且该渐变继承父锚点的宽度。问题是,span要么继承锚的父节点的整个宽度,要么只是& nbsp的宽度。我无法获得span元素以正确继承宽度,同时保持锚点在线显示。

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>&nbsp;</span>Index</a>


推荐答案

无法用

我不知道这是否会为你服务,但如何给予

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;

这篇关于绝对元素继承相对父div的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆