首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在悬停后保持原来的字体颜色?

如何在悬停后保持原来的字体颜色?
EN

Stack Overflow用户
提问于 2017-12-12 04:23:16
回答 2查看 1K关注 0票数 0

你好,伙计们,我试图在这个悬停中保持白色,但是我做不到?,当我移动光标到元素内的下一个元素时,字体改变了它的颜色,我做了很多不同的方法来保持我想要的颜色,但是似乎没有效果,请提供一些帮助。我在这张照片上展示了发生了什么,我希望得到一些帮助。https://ibb.co/nDLQ7w https://ibb.co/j5NBfG对不起我的英语我来自日本。

代码语言:javascript
复制
@import url('https://fonts.googleapis.com/css?family=Spectral+SC');

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
html {
  font-size: 22px;
  line-height: 32px;
  background-color: #212121;
  color: #555;
  word-wrap: break-word;
  font-family: 'Spectral sc', sans-serif;
}
h1 {
  font-size: 60px;
  line-height: 70px;
  color: #fff;
  margin-top: 100px;
  text-align: center;
}
h3 {
  font-size: 30px;
  line-height: 34px;
  color: #fff;
  text-align: center;
}
p {text-align: center;}
nav {
  padding: 0;
  margin: 0;
  background-color: #fff;
}
nav:after {
  content: " ";
  display: table;
  clear: both;
}
nav ul {
  float: right;
  padding: 0;
  margin: 0;
  list-style: none;
}
nav ul li {
  float: left;
  display: inline-block;
  margin: 0;
  background-color: #fff;
}

nav a {
  display: block;
  padding: 10px 20px;
  color: #555;
  font-size: 20px;
  line-height: 60px;
  text-decoration: none;
}
.icon {
  color: #fff;
  font-size: 25px;
}
.toggle, [id^=drop] {display: none;}
nav ul li ul li:hover {background-color: #000;}
nav a:hover {
  color: #fff;
  background-color: #000;}
nav ul ul {
  display: none;
  position: absolute;
  top: 80px;
}
nav ul li:hover > ul {display: inherit;}
nav ul ul li {
  width: 170px;
  float: none;
  display: list-item;
  position: relative;
}
nav ul ul ul li {
  position: relative;
}

.logo {
  height: 70px;
  width: auto;
  margin: 5px 15px;
  float: left;
}
.container {
    display: inline-block;
    cursor: pointer;
}

.bar1, .bar2, .bar3 {
    width: 35px;
    height: 5px;
    background-color: #fff;
    margin: 6px 0;
    transition: 0.4s;
    border-radius: 5px;
}
.toggle-nav {display: none;}
.change .bar1 {
    -webkit-transform: rotate(-45deg) translate(-9px, 6px);
    transform: rotate(-45deg) translate(-9px, 6px);
}

.change .bar2 {opacity: 0;}

.change .bar3 {
    -webkit-transform: rotate(45deg) translate(-8px, -8px);
    transform: rotate(45deg) translate(-8px, -8px);
}
@media all and (max-width : 767px) {
  nav {margin: 0;}
  nav ul{float: left;clear:both;}
  .toggle + a, .menu {display: none;}
  .toggle {
    display: block;
    background-color: #254441;
    padding: 10px 20px;
    color: #fff;
    font-size: 20px;
    line-height: 60px;
    text-decoration: none;
    border: none;
  }
  .toggle-nav {
    display: block;
    margin-top: 20px;
    margin-right: 25px;
    color: #fff;
  }
  .toggle:hover {background-color: #000;}
  [id^=drop]:checked + ul {display: block;}
  .logo {
   left: 50%;
   position: relative;
   transform: translateX(-50%);
  }
  nav ul li {
    display: block;
    width: 100%;
  }
  nav ul {
    width: 100%;
  }
  nav ul ul .toggle,
  nav ul ul a {padding: 0 40px;}
  nav ul ul ul a {padding: 0 80px;}

  nav a:hover,
  nav ul ul ul a {background-color: #000;}
  nav ul li ul li .toggle,
  nav ul ul a {background-color: #212121;}

  nav ul ul {
    float: none;
    position: static;
    color: #fff;
  }
  nav ul ul li:hover > ul,
  nav ul li:hover > ul {display: none;}

  nav ul ul li {
    display: block;
    width: 100%;
  }
  nav ul ul ul li {position: static;}
}
@media all and (max-width : 330px) {
  nav ul li {
    display: block;
    width: 94%;
  }
}
代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,400" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="resources/css/grid.css">
    <link rel="stylesheet" type="text/css" href="resources/css/ionicons.min.css">
    <link rel="stylesheet" type="text/css" href="resources/css/normalize.css">
    <link rel="stylesheet" type="text/css" href="resources/css/style.css">
    <link rel="stylesheet" type="text/css" href="resources/css/queries.css">
	<title>Web title</title>
</head>
<body>
	<nav>
		<img src="https://upload.wikimedia.org/wikipedia/commons/a/ab/Logo_TV_2015.png" class="logo">
		<label for="drop" class="toggle-nav" style="float: right;"><div class="container" onclick="myFunction(this)">
  <div class="bar1"></div>
  <div class="bar2"></div>
  <div class="bar3"></div>
</div></label>
		<input type="checkbox" id="drop">
		<ul class="menu">
			<li><a href="#">Home</a></li>
			<li>
				<label for="drop-1" class="toggle"">Services +</label>
				<a href="#">Services +</a>
				<input type="checkbox" id="drop-1">
				<ul>
					<li><a href="#">Service 1</a></li>
					<li><a href="#">Service 2</a></li>
					<li><a href="#">Service 3</a></li>
				</ul>
			</li>
			<li>
				<label for="drop-2" class="toggle"">Portfolio +</label>
				<a href="#">Portfolio +</a>
				<input type="checkbox" id="drop-2">
				<ul>
					<li><a href="#">Service 1</a></li>
					<li><a href="#">Service 2</a></li>
					<li><a href="#">Service 3</a></li>
					<li>
						<label for="drop-3" class="toggle"">Port +</label>
						<a href="#">Port+</a>
						<input type="checkbox" id="drop-3">
						<ul>
							<li><a href="#">Service 1</a></li>
							<li><a href="#">Service 2</a></li>
							<li><a href="#">Service 3</a></li>	
						</ul>				
					</li>
				</ul>				
			</li>
			<li><a href="#">Service 1</a></li>
			
		</ul>
	</nav>
</body>

<script>
function myFunction(x) {
    x.classList.toggle("change");
}
</script>
</html>

EN

回答 2

Stack Overflow用户

发布于 2017-12-12 05:19:25

添加这个css,也许这会对你有帮助

代码语言:javascript
复制
 ul li a, ul li a:hover, ul li a:active{
  color:#fff !important;
 }

票数 0
EN

Stack Overflow用户

发布于 2017-12-12 05:36:09

nav ul ul li a:悬停{背景颜色:#fff;颜色:#ccc;}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47765324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档