具有流动宽度的多个图像的导航链接

发布于 2024-12-29 00:46:51 字数 1150 浏览 3 评论 0原文

我正在尝试创建一个导航菜单,其中的菜单项并不总是具有固定宽度。因此,我尝试使用一种技术,将 元素作为一个背景图像,然后将 元素作为背景图像。 具有不同的背景图像。我记得很久以前就看到过这个技巧,但凭记忆回忆却行不通。这是我的菜单标记:

<div id="nav">
    <ul>
        <li>
            <a href="">Home<span></span></a>
        </li>
    </ul>
</div>

到目前为止我的 CSS:

#nav {
    height: 35px;
    width: 942px;
    background: url('images/nav_bg.png');
    border: 1px solid #74818c;
    border-radius: 3px;
}

#nav ul li a {
    display: inline-block;
    background: url('images/nav_button_left_idle.png');
    line-height: 32px;

}

#nav ul li a span {
    display: inline-block;
    background: url('images/nav_button_right_idle.png');
    line-height: 32px;
    width: 5px;
}

详细说明一下,这是我的 标签上使用的背景图像:

在此处输入图像描述

以及 元素上使用的 alt:

在此处输入图像描述

任何帮助将不胜感激,谢谢!

I'm trying to create a navigation menu with menu items that don't always have a fixed width. Because of this, I'm trying to use a technique where I have the <a> element as one background image, and then a <span> element within the <a> having a different background image. I remember seeing this technique a long time ago and recalling it from memory just isn't working. Here's my menu markup:

<div id="nav">
    <ul>
        <li>
            <a href="">Home<span></span></a>
        </li>
    </ul>
</div>

And my CSS this far:

#nav {
    height: 35px;
    width: 942px;
    background: url('images/nav_bg.png');
    border: 1px solid #74818c;
    border-radius: 3px;
}

#nav ul li a {
    display: inline-block;
    background: url('images/nav_button_left_idle.png');
    line-height: 32px;

}

#nav ul li a span {
    display: inline-block;
    background: url('images/nav_button_right_idle.png');
    line-height: 32px;
    width: 5px;
}

To elaborate a bit more, this is the background image used on my <a> tags:

enter image description here

and the one used on the <span> element:

enter image description here

Any help would be appreciated, thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

心舞飞扬 2025-01-05 00:46:51

您需要设置跨度的高度和位置”

#nav ul li a {
    display: inline-block;
    background: url('images/nav_button_left_idle.png');
    line-height: 32px;
    position:relative;
}

#nav ul li a span {
    display: inline-block;
    background: url('images/nav_button_right_idle.png');
    height: 32px;
    width: 5px;
    position:absolute;
    top: 0;
    right: 0
}

You need to set the height and position of your span"

#nav ul li a {
    display: inline-block;
    background: url('images/nav_button_left_idle.png');
    line-height: 32px;
    position:relative;
}

#nav ul li a span {
    display: inline-block;
    background: url('images/nav_button_right_idle.png');
    height: 32px;
    width: 5px;
    position:absolute;
    top: 0;
    right: 0
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文