css - 具有缩短的水平边框的链接列表?
我正在尝试做这样的事情:
a link here
------------------
another link here
------------------
>> active link here
------------------
one more link
------------------
所有 ---
都是边框但长度相等。如果当前页面是链接(即活动链接),则显示>>
(它将是一个图像)。问题是,如果我向 li
添加填充,则会导致边框位于 >>
下方,这是不希望的。显然没有 JavaScript。
我尝试使用的一般标记是这样的:
<ul>
<li><a href="#">a link here</a></li>
<li><a href="#">another link here</a></li>
<li><a href="#">active link here</a></li>
<li><a href="#">one more link</a></li>
</ul>
I'm trying to do something like so:
a link here
------------------
another link here
------------------
>> active link here
------------------
one more link
------------------
where all the ---
are borders but equal lengths. If the current page is the link (i.e. active link) then >>
display (it'll be an image). The problem is that if I add padding to the li
s then it'll cause the border to be underneath the >>
which is not desired. No javascript obviously.
The general markup I've tried to work with is this:
<ul>
<li><a href="#">a link here</a></li>
<li><a href="#">another link here</a></li>
<li><a href="#">active link here</a></li>
<li><a href="#">one more link</a></li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议将
.active
类应用于li
,而不是链接,然后使用:JS Fiddle 演示。
考虑到使用
:before
伪元素跨浏览器的困难,似乎值得指出可以使用list-style-image
来代替:JS Fiddle 演示。
参考文献:
:before
。list-style-image
。I'd suggest applying the
.active
class to theli
, rather than the link, and then using:JS Fiddle demo.
Given the difficulties using the
:before
pseudo-element cross-browser, it seems worthwhile pointing out thatlist-style-image
can be used instead:JS Fiddle demo.
References:
:before
.list-style-image
.您始终可以将
a
标记更改为显示块,并执行类似的操作以获得您正在寻找的边框效果。由于边框应用于a
元素,因此是否向li
应用填充并不重要。You can always change your
a
tags to display block and do something like this to get the border effect you are looking for. Because the border is applied to thea
element, it shouldn't matter if you apply padding to theli
or not.