html - 只更改一个 <a> 标签的 CSS

标签 html css background-color

我的网页顶部有 3 个链接,还有一个链接嵌入到图像中。这 3 个链接的背景颜色与导航不同,但不幸的是,它还会将此添加到带有链接的图像中。如何将其从图像中删除?

html{
	font-family: abel;
	background-color: #a4bdd1;
	margin: 0;
	padding: 0;
}
body{
    overflow-x:hidden;
    margin: 0;
    padding: 0;
}
nav {
    text-align: center;
    background-color: #e4e6e5;
/*    position: fixed;
    top: 0;
  	left: 0;
  	z-index: 9999;*/
 	width: 100%;
  	border-bottom: solid #05182e 2px;
  	margin-top: -1px
}
nav li {
    display: inline-block;
    font-size: 35px;
    padding: 15px;
    font-weight: bold;
    vertical-align: middle;
}

nav a{
	border-radius: 10%;
	padding: 8px;
	background-color: #cccccc;
	color: #1f3b5a;
	text-decoration: none;
	font-size: 30px;
	transition: all 0.5s ease-in-out;
}
nav a:hover{
	font-size: 40px;
	transition: all 0.5s ease-in-out;
}
nav img{
	width: 30%;
	border: none;
	transition: all 0.5s ease-in-out;
}
nav img:hover{
	width: 40%;
	transition: all 0.5s ease-in-out;
}
ul {
   margin: 0;
}
<!DOCTYPE html>
<html>
<head>
  	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="style.css">
	<link href='https://fonts.googleapis.com/css?family=Abel' rel='stylesheet' type='text/css'>
	<link href='https://fonts.googleapis.com/css?family=Bitter:700' rel='stylesheet' type='text/css'>
	<link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" />
	<link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" />
	<title>Brampton Thunder</title>
</head>

<body>

	<nav> 
	    <ul> 
	    	<li><img src="images/logo.png" alt="Canadian Women's Hockey League Logo"></li>
	        <li> <a href="index.html" target="_blank">Home</a></li>
	        <li> <a href="roster.html" target="_blank">Roster</a></li>
	        <li> <a href="schedule.html" target="_blank">Schedule</a></li>
	        <li><a href="http://cwhl.ca" target="_blank"><img src="images/cwhllogo.png"></a></li>

	    </ul>
	</nav>

最佳答案

你可以这样做:

nav ul li:last-child a {
  background-color:#e4e6e5; 
} 

检查下面的片段

html {
  font-family: abel;
  background-color: #a4bdd1;
  margin: 0;
  padding: 0;
}
body {
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}
nav {
  text-align: center;
  background-color: #e4e6e5;
  /*    position: fixed;
    top: 0;
  	left: 0;
  	z-index: 9999;*/
  width: 100%;
  border-bottom: solid #05182e 2px;
  margin-top: -1px
}
nav li {
  display: inline-block;
  font-size: 35px;
  padding: 15px;
  font-weight: bold;
  vertical-align: middle;
}
nav a {
  border-radius: 10%;
  padding: 8px;
  background-color: #cccccc;
  color: #1f3b5a;
  text-decoration: none;
  font-size: 30px;
  transition: all 0.5s ease-in-out;
}
nav ul li:last-child a {
  background-color: #e4e6e5;
}
nav a:hover {
  font-size: 40px;
  transition: all 0.5s ease-in-out;
}
nav img {
  width: 30%;
  border: none;
  transition: all 0.5s ease-in-out;
}
nav img:hover {
  width: 40%;
  transition: all 0.5s ease-in-out;
}
ul {
  margin: 0;
}
<nav>
  <ul>
    <li>
      <img src="images/logo.png" alt="Canadian Women's Hockey League Logo">
    </li>
    <li> <a href="index.html" target="_blank">Home</a>
    </li>
    <li> <a href="roster.html" target="_blank">Roster</a>
    </li>
    <li> <a href="schedule.html" target="_blank">Schedule</a>
    </li>
    <li>
      <a href="http://cwhl.ca" target="_blank">
        <img src="images/cwhllogo.png">
      </a>
    </li>

  </ul>
</nav>

关于html - 只更改一个 <a> 标签的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35677910/

相关文章:

CSS 文本背景颜色被切断

javascript - 为什么我的 jquery 插件在我将它放入 div 容器后停止工作?

jQuery 悬停函数

javascript - 使用 css 顶部和左侧居中我的 div 时出现滚动条问题

css - webkit 动画停止和反转

css - Ionic-v4 中的侧边菜单背景颜色

javascript - Javascript通过ID改变元素的颜色

html - 如何在html中的一个单元格中使用多个链接

javascript - MeteorJS 模板不显示数据,不出现

css - 是否有我必须支持和测试的移动浏览器列表?