html - 不会显示 Sprite 图像?

标签 html css menu

为什么这不会显示我的 Sprite 图像作为黄色边框框的背景?
这里有一个例子:

如果有人能举例说明我应该改变什么,那就太好了。

这是我的代码:

HTML:

<div class="repeat">
    <div style='width:100%;'>
        <div style='float:left;margin-top:107px;margin-left:50px;width:80px;height:100px;border:1px solid yellow;'>
            <div class="menu">
                <ul id='nav'>
                    <li class='front'><a href='?p=front'>Front</a></li>
                </ul>
            </div>
        </div>
        <div style='float:left;margin-top:107px;margin-left:10px;width:80px;height:100px;border:1px solid yellow;'></div>
        <div style='clear:both;'></div>
    </div>
</div>

CSS:

.repeat {
    float:left;
    width: 884px;
    height: auto;
    min-height:700px;
    background: url(images/repeat.png) repeat-y;
    z-index:2;
}

.menu {
    width:80px;
    height:100px;
    position:relative;
    }
    ul#nav {
        list-style: none inside;
        }
        ul#nav li {
            display: inline;
            }
            ul#nav li a {
                display: block;
                height: 40px;
                float: left;
                }
                ul#nav li.front  a{
                    width:80px;
                    background: url(images/menu/p1.png) top center no-repeat;
                    }               
                    ul#nav li a:hover {
                        background-position: bottom center;
                    }
                ul#nav li.front2  a{
                    width:80px;
                    background: url(images/menu/p1.png) bottom center no-repeat;
                }

最佳答案

您的 Sprite 显示得很好...
只是它在整体设置中不可见。 尝试将 height: 80px 添加到您的“ul#nav li.front a”选择器,您会发现哪里出错了。
从那里试穿自己。

提示:使用浏览器开发工具(我更喜欢 Chrome)并将鼠标悬停在每个元素上以查看它们占据的区域。在您的情况下,请检查“div menu”和“li a”元素。

关于html - 不会显示 Sprite 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12805016/

相关文章:

html - 将两个按钮放在 HTML 中的同一行

android - 网页上的图像在 Android 8/9 上的 Chrome 78 上不可见(但在 Chrome 76 和 Android 10 上工作)——可能是什么问题?

javascript - 点击元素跨容器遍历

html - 图像调整到父 div 保持比例并尊重图像高度

jQuery Sortable 用于两列重新排序?

jquery - 多级推送菜单问题,链接不可点击

menu - 使侧边菜单滑过代号一中的表单

asp.net - .NET Ektron 8.6 : How to use value in query string for Ektron Server Control MenuModel (TreeFilter. ID)

jquery - 在选择列表之前插入标签

javascript - 无法更改表中动态附加行的样式?