你可以将图像分配给边界右吗? [英] Can you assign an image to border-right?
问题描述
我在html和css中制作导航菜单,但我想要每个导航项目的边框右侧是一个图像。
I am making a navigational menu in html and css, but i want the border right of each navigational item to be an image.
我试过
border-right:url(image.jpg);
但这不起作用。
推荐答案
您可以使用背景图片,然后将背景图片放置在每个元素的右侧。通常这会在 a
标签或 li
上。例如:
You can use a background image and then position the background image to the right of each element. Usually this would go on either the a
tag or li
. For example:
#primaryNav a:link {
background-image: url('image.jpg');
background-position: right;
background-repeat: no-repeat;
display: block; /* make the link background clickable */
}
边框应用于最后一个(当使用 background-position:right;
)或第一个( background-position:left;
)元素,然后尝试:last-child
和:first-child
选择器。
If you don't want the border applied to the last (when using background-position: right;
) or first (for background-position: left;
) element in your menu then try the :last-child
and :first-child
selectors.
#primaryNav a:last-child {
background: none;
}
这篇关于你可以将图像分配给边界右吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!