简体   繁体   English

CSS我在做什么错? 无序列表中的背景图像

[英]CSS What am I doing wrong? background image in unordered lists

.navbar {
    position:relative;
    height: 50px;
}
ul {
    height:inherit;
    position:absolute;
    top:19%;
}

ul li {
    height:inherit;
    padding: 10px 1px 10px 1px;
    display:inline;
    font-size:1.3125em; 
    transition: all 0.4s ease;
}

ul li:hover {
    background-color: #0E0E0E;
    background: url(img/a.svg) no-repeat;
    background-position: 0px 5px;


}

So, basically, i would like to apply an image to the highlighted unordered list items, but this image NEVER appears, how is that? 因此,基本上,我想将图像应用于突出显示的无序列表项,但是此图像从不出现,那怎么办?

You've got the image url incorrect. 您的图片网址不正确。 Either that or you have some other styles conflicting or your CSS does not correctly match your HTML . 要么是您的样式发生冲突,要么是CSS不能正确匹配HTML

See this fiddle. 看到这个小提琴。 Using what I'd expect your HTML structure to be, it works fine using an external image; 使用我期望的HTML结构,可以使用外部图像正常工作;

JS FIDDLE 1 JS FIDDLE 1

If you also want the background colour to be applied as well as the picture you'd need to change your CSS to this; 如果您还希望应用背景颜色以及图片,则需要将CSS更改为此。

ul li:hover {
    background-color: #0E0E0E;
    background-image: url(img/a.svg);
    background-repeat: no-repeat;
    background-position: 0px 5px;
}

JS FIDDLE 2 JS FIDDLE 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM