Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 背景颜色处于悬停状态的背景图像_Html_Css - Fatal编程技术网

Html 背景颜色处于悬停状态的背景图像

Html 背景颜色处于悬停状态的背景图像,html,css,Html,Css,我试图弄清楚如何使背景图像具有不同图像的悬停状态,并且显示白色背景 你可以更详细地理解我的意思 导航栏上CAUL/CBUA的徽标就是我试图修复的。您可以看到,当您悬停时,它确实会切换到图像,并且有一个白色背景,但背景的白色不会延伸到它的整个块。要了解我所说的完整块是什么意思,请将鼠标悬停在徽标旁边的链接上,注意它占据了完整块 编辑:这是我编辑的CSS(仅更改的部分) 这是我的原始CSS: /* Navigation bar */ #navi { height: 40px; background:

我试图弄清楚如何使背景图像具有不同图像的悬停状态,并且显示白色背景

你可以更详细地理解我的意思

导航栏上CAUL/CBUA的徽标就是我试图修复的。您可以看到,当您悬停时,它确实会切换到图像,并且有一个白色背景,但背景的白色不会延伸到它的整个块。要了解我所说的完整块是什么意思,请将鼠标悬停在徽标旁边的链接上,注意它占据了完整块

编辑:这是我编辑的CSS(仅更改的部分)

这是我的原始CSS:

/* Navigation bar */
#navi {
height: 40px;
background: #1e416f;
font-size: 14px;
color: white;
text-transform: uppercase;
margin: 0 0 20px 0;
}

#navi a:hover {
background: white;
color: #1e416f;
}

#navi .logo {
margin: 5px;
padding: 0;
float: left;
}

#navi .logo a {
float: left;
margin: 2px 10px;
width: 36px;
height: 26px;
background: url(/imgs/navi/caul_white_nav.png) left top no-repeat;
text-indent: -9999px;
}

#navi .logo a:hover {
background: url(/imgs/navi-hover/caul_blue_nav.png) left top no-repeat;
background-color: white;
}

#primary-nav, #tools-nav {
list-style: none;
margin: 0;
padding: 0;
}

#primary-nav li, #primary-nav a, #tools-nav li, #tools-nav a {
float: left;
}

#primary-nav a, #tools-nav a {
color: white;
text-decoration: none;
padding: 0 10px;
border-right: 1px solid white;
line-height: 40px;
}

#tools-nav a:hover {
color: #1e416f;
}

#primary-nav li:first-child a, #tools-nav li:first-child a {
border-left: 1px solid white;
}

#tools-nav {
float: right;
}

#tools-nav .icon a {
text-indent: -9999px;
}

#tools-nav .email a {
background: url(/imgs/navi/mail.png) no-repeat;
width: 20px;
}

#tools-nav .email a:hover {
background: url(/imgs/navi-hover/hover_mail.png) no-repeat;
width: 20px;
}

#tools-nav .twitter a {
background: url(/imgs/navi/twitter.png) no-repeat;
width: 20px;
}

#tools-nav .twitter a:hover {
background: url(/imgs/navi-hover/hover-twitter.png) no-repeat;
width: 20px;
}

#tools-nav .search a {
background: url(/imgs/navi/search.png) no-repeat;
width: 20px;
}

#tools-nav .search a:hover {
background: url(/imgs/navi-hover/hover_search.png) no-repeat;
width: 20px;
}
相关HTML:

<!-- NAVIGATION -->
<div id="navi">
<h1 class="logo"><a href="#">CAUL/CBUA</a></h1>

<ul id="primary-nav">
    <li><a href="#">Directories</a></li>
    <li><a href="#">Committees</a></li>
    <li><a href="#">Resources</a></li>
    <li><a href="#">About</a></li>
</ul>

<ul id="tools-nav">
    <li class="login"><a href="#">Log In</a></li>
    <li class="email icon"><a href="#">Email</a></li>
    <li class="twitter icon"><a href="#">Twitter</a></li>
    <li class="search icon"><a href="#">Search</a></li>
</ul>
</div>


用填充替换边距并重新定位背景图像

#navi .logo a {
float: left;
padding: 2px 10px;
width: 36px;
height: 26px;
background: url(/imgs/navi/caul_white_nav.png) no-repeat;
text-indent: -9999px;
background-position: 50%
}
编辑:只需确保在
上有相同的背景位置:悬停

使您的

CSS

#navi .logo a {
  float: left;
  width: 56px;
  height: 40px;
  background: url(/imgs/navi/caul_white_nav.png) center no-repeat; /*Center your background*/
  text-indent: -9999px;
}

#navi .logo a:hover {
  background: url(/imgs/navi-hover/caul_blue_nav.png) center no-repeat;
  background-color: white;
}
#navi .logo a {
  float: left;
  width: 56px;
  height: 40px;
  background: url(/imgs/navi/caul_white_nav.png) center no-repeat; /*Center your background*/
  text-indent: -9999px;
}

#navi .logo a:hover {
  background: url(/imgs/navi-hover/caul_blue_nav.png) center no-repeat;
  background-color: white;
}