如何在水平图标栏中更改颜色

时间:2018-04-05 15:50:59

标签: javascript html css web icons

我希望能够更改为绿色主页图标或绿色搜索图标的颜色。但每当我尝试改变它时,它都会改变它们。我不确定我是否已经很好地解释了这一点,但任何意见或想法都会受到赞赏。感谢



console.log('Loaded')

.button {
  display: inline-block;
  border-radius: 4px;
  background-color: #4CAF50e;
  border: none;
  
  text-align: center;
  font-size: 28px;
  padding: 20px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}

.button:hover span {
  padding-right: 25px;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
}


body {margin:10}

.icon-bar {
    width: 90px;
	height: 100%;
    background-color: #555;   /*button color*/
}

.icon-bar a {
    display: block;
    text-align: center;
    padding: 16px;
    transition: all 0.3s ease;
    color: white;
    font-size: 36px;
}

.icon-bar a:hover {
    background-color: #4289b5;
}

.active {
    background-color: #4CAF50 !important;
}























body{
  font-size: 20px;
  font-family: Roboto;
  font-weight: 300;
}

a{
  
  text-decoration: none;
  ;
  padding: 10px 15px;
  line-height: 3;
  -webkit-transition: all .3s ease;
	   -moz-transition: all .3s ease;
	    -ms-transition: all .3s ease;
	     -o-transition: all .3s ease;
				  transition: all .3s ease;
}

a:hover{
  color: #FFF;
  background: #FC2121;
  -webkit-transition: all .3s ease;
	   -moz-transition: all .3s ease;
	    -ms-transition: all .3s ease;
	     -o-transition: all .3s ease;
				  transition: all .3s ease;  
}

/* Search Style */ 
#search {
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    -webkit-transition: all 0.5s ease-in-out;
       -moz-transition: all 0.5s ease-in-out;
        -ms-transition: all 0.5s ease-in-out;
	       -o-transition: all 0.5s ease-in-out;
            transition: all 0.5s ease-in-out;
    -webkit-transform: translate(0px, -100%) scale(0, 0);
	     -moz-transform: translate(0px, -100%) scale(0, 0);
	      -ms-transform: translate(0px, -100%) scale(0, 0);
         -o-transform: translate(0px, -100%) scale(0, 0);
	          transform: translate(0px, -100%) scale(0, 0);    
    opacity: 0;
    display: none;
}

#search.open {
    -webkit-transform: translate(0px, 0px) scale(1, 1);
       -moz-transform: translate(0px, 0px) scale(1, 1);
    	  -ms-transform: translate(0px, 0px) scale(1, 1);
	       -o-transform: translate(0px, 0px) scale(1, 1);
	           transform: translate(0px, 0px) scale(1, 1); 
    opacity: 1;
    z-index: 106;
    display: block;
}

#search input[type="search"] {
    position: absolute;
    top: 50%;
    left: 0;
    margin-top: -51px;
    width: 60%;
    margin-left: 20%;
    color: rgb(255, 255, 255);
  	background: transparent;
  	border-top: 1px solid rgba(255, 255, 255, .8);
  	border-bottom: 2px solid rgba(255, 255, 255, .5);
  	border-left: 0px solid transparent;
  	border-right: 0px solid transparent;
    font-size: 40px;
  	font-family: Roboto;
    font-weight: 300;
    text-align: center;
    outline: none;
  	padding: 10px;
}
  
#search .close {
    position: fixed;
    top: 15px;
    right: 15px;
	  opacity: 1;
	  font-size: 27px;
  	color: #fff;
}

#search .close:hover{
  color: #FC2121;
  cursor: pointer;
}








body {margin:0;}

.icon-bartop {
    width: 100%;
    background-color: #555;
    overflow: auto;
}

.icon-bartop a {
    float: left;
    width: 20%;
    text-align: center;
    padding: 12px 0;
    transition: all 0.3s ease;
    color: white;
    font-size: 36px;
}

.icon-bartop a:hover {
    background-color: #000;
}

.active {
    background-color: #4CAF50 !important;
}

<!DOCTYPE html>
<html>
<body>
<html lang="en">

<head>
  <title>Web Scraper</title>
  <script src="https://cdn.jsdelivr.net/npm/sweetalert"></script>
  <link rel="stylesheet" href="css/style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="js/scripts.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

<body>

<div class="icon-bartop">
  <a class="active" href="#"><i class="fa fa-home"></i></a> 
  <a href="#"><i class="fa fa-search"></i></a> 
  <a href="#"><i class="fa fa-envelope"></i></a> 
  <a href="#"><i class="fa fa-globe"></i></a>
  <a href="#"><i class="fa fa-trash"></i></a> 
</div>

<div class="sidebar">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<div class="icon-bar">
	  <a class="active" href=""><i class="fa fa-search"></i></a> 
	  <a href=""><i class="fa fa-bitcoin"></i></a> 
	  <a href=""><i class="fa fa-map"></i></a> 
	  <a href=""><i class="fa fa-anchor"></i></a>
	  <a href=""><i class="fa fa-shopping-cart"></i></a> 
	</div>
</div>

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>

</body>

</html>
&#13;
&#13;
&#13;

6 个答案:

答案 0 :(得分:2)

它们都是绿色的原因是因为它们都具有活动的类,而在css中,活动链接的背景颜色为绿色。从未激活的图标或您不想激活的图标中删除class ='active'。

console.log('Loaded')
.button {
  display: inline-block;
  border-radius: 4px;
  background-color: #4CAF50e;
  border: none;
  
  text-align: center;
  font-size: 28px;
  padding: 20px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}

.button:hover span {
  padding-right: 25px;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
}


body {margin:10}

.icon-bar {
    width: 90px;
	height: 100%;
    background-color: #555;   /*button color*/
}

.icon-bar a {
    display: block;
    text-align: center;
    padding: 16px;
    transition: all 0.3s ease;
    color: white;
    font-size: 36px;
}

.icon-bar a:hover {
    background-color: #4289b5;
}

.active {
    background-color: #4CAF50 !important;
}























body{
  font-size: 20px;
  font-family: Roboto;
  font-weight: 300;
}

a{
  
  text-decoration: none;
  ;
  padding: 10px 15px;
  line-height: 3;
  -webkit-transition: all .3s ease;
	   -moz-transition: all .3s ease;
	    -ms-transition: all .3s ease;
	     -o-transition: all .3s ease;
				  transition: all .3s ease;
}

a:hover{
  color: #FFF;
  background: #FC2121;
  -webkit-transition: all .3s ease;
	   -moz-transition: all .3s ease;
	    -ms-transition: all .3s ease;
	     -o-transition: all .3s ease;
				  transition: all .3s ease;  
}

/* Search Style */ 
#search {
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    -webkit-transition: all 0.5s ease-in-out;
       -moz-transition: all 0.5s ease-in-out;
        -ms-transition: all 0.5s ease-in-out;
	       -o-transition: all 0.5s ease-in-out;
            transition: all 0.5s ease-in-out;
    -webkit-transform: translate(0px, -100%) scale(0, 0);
	     -moz-transform: translate(0px, -100%) scale(0, 0);
	      -ms-transform: translate(0px, -100%) scale(0, 0);
         -o-transform: translate(0px, -100%) scale(0, 0);
	          transform: translate(0px, -100%) scale(0, 0);    
    opacity: 0;
    display: none;
}

#search.open {
    -webkit-transform: translate(0px, 0px) scale(1, 1);
       -moz-transform: translate(0px, 0px) scale(1, 1);
    	  -ms-transform: translate(0px, 0px) scale(1, 1);
	       -o-transform: translate(0px, 0px) scale(1, 1);
	           transform: translate(0px, 0px) scale(1, 1); 
    opacity: 1;
    z-index: 106;
    display: block;
}

#search input[type="search"] {
    position: absolute;
    top: 50%;
    left: 0;
    margin-top: -51px;
    width: 60%;
    margin-left: 20%;
    color: rgb(255, 255, 255);
  	background: transparent;
  	border-top: 1px solid rgba(255, 255, 255, .8);
  	border-bottom: 2px solid rgba(255, 255, 255, .5);
  	border-left: 0px solid transparent;
  	border-right: 0px solid transparent;
    font-size: 40px;
  	font-family: Roboto;
    font-weight: 300;
    text-align: center;
    outline: none;
  	padding: 10px;
}
  
#search .close {
    position: fixed;
    top: 15px;
    right: 15px;
	  opacity: 1;
	  font-size: 27px;
  	color: #fff;
}

#search .close:hover{
  color: #FC2121;
  cursor: pointer;
}








body {margin:0;}

.icon-bartop {
    width: 100%;
    background-color: #555;
    overflow: auto;
}

.icon-bartop a {
    float: left;
    width: 20%;
    text-align: center;
    padding: 12px 0;
    transition: all 0.3s ease;
    color: white;
    font-size: 36px;
}

.icon-bartop a:hover {
    background-color: #000;
}

.active {
    background-color: #4CAF50 !important;
}
<!DOCTYPE html>
<html>
<body>
<html lang="en">

<head>
  <title>Web Scraper</title>
  <script src="https://cdn.jsdelivr.net/npm/sweetalert"></script>
  <link rel="stylesheet" href="css/style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="js/scripts.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

<body>

<div class="icon-bartop">
  <a class="active" href="#"><i class="fa fa-home"></i></a> 
  <a href="#"><i class="fa fa-search"></i></a> 
  <a href="#"><i class="fa fa-envelope"></i></a> 
  <a href="#"><i class="fa fa-globe"></i></a>
  <a href="#"><i class="fa fa-trash"></i></a> 
</div>




<div class="sidebar">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<div class="icon-bar">
	  <a  href=""><i class="fa fa-search"></i></a> 
	  <a href=""><i class="fa fa-bitcoin"></i></a> 
	  <a href=""><i class="fa fa-map"></i></a> 
	  <a href=""><i class="fa fa-anchor"></i></a>
	  <a href=""><i class="fa fa-shopping-cart"></i></a> 
	</div>
</div>



<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>





</body>

</html>

答案 1 :(得分:2)

我假设你试图通过设置&#34; .active&#34;来改变它。选择器将像你解释的那样改变它们,因为它们都共享那个类。我建议让MDN - CSS Selectors看一看,以便更好地理解。

也就是说,解决问题的一个简单方法是确保为不同的样式使用不同的CSS选择器

&#13;
&#13;
console.log('Loaded')
&#13;
.button {
  display: inline-block;
  border-radius: 4px;
  background-color: #4CAF50e;
  border: none;
  
  text-align: center;
  font-size: 28px;
  padding: 20px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.button span:after {
  content: '\00bb';
  position: absolute;
  opacity: 0;
  top: 0;
  right: -20px;
  transition: 0.5s;
}

.button:hover span {
  padding-right: 25px;
}

.button:hover span:after {
  opacity: 1;
  right: 0;
}


body {margin:10}

.icon-bar {
    width: 90px;
	height: 100%;
    background-color: #555;   /*button color*/
}

.icon-bar a {
    display: block;
    text-align: center;
    padding: 16px;
    transition: all 0.3s ease;
    color: white;
    font-size: 36px;
}

.icon-bar a:hover {
    background-color: #4289b5;
}

/* Remove this
.active {
    background-color: #4CAF50 !important;
}
*/

/* Add this - Select the side bar active icon */
.icon-bar a.active {
  background-color: green;
}

body{
  font-size: 20px;
  font-family: Roboto;
  font-weight: 300;
}

a{
  
  text-decoration: none;
  ;
  padding: 10px 15px;
  line-height: 3;
  -webkit-transition: all .3s ease;
	   -moz-transition: all .3s ease;
	    -ms-transition: all .3s ease;
	     -o-transition: all .3s ease;
				  transition: all .3s ease;
}

a:hover{
  color: #FFF;
  background: #FC2121;
  -webkit-transition: all .3s ease;
	   -moz-transition: all .3s ease;
	    -ms-transition: all .3s ease;
	     -o-transition: all .3s ease;
				  transition: all .3s ease;  
}

/* Search Style */ 
#search {
    position: fixed;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    -webkit-transition: all 0.5s ease-in-out;
       -moz-transition: all 0.5s ease-in-out;
        -ms-transition: all 0.5s ease-in-out;
	       -o-transition: all 0.5s ease-in-out;
            transition: all 0.5s ease-in-out;
    -webkit-transform: translate(0px, -100%) scale(0, 0);
	     -moz-transform: translate(0px, -100%) scale(0, 0);
	      -ms-transform: translate(0px, -100%) scale(0, 0);
         -o-transform: translate(0px, -100%) scale(0, 0);
	          transform: translate(0px, -100%) scale(0, 0);    
    opacity: 0;
    display: none;
}

#search.open {
    -webkit-transform: translate(0px, 0px) scale(1, 1);
       -moz-transform: translate(0px, 0px) scale(1, 1);
    	  -ms-transform: translate(0px, 0px) scale(1, 1);
	       -o-transform: translate(0px, 0px) scale(1, 1);
	           transform: translate(0px, 0px) scale(1, 1); 
    opacity: 1;
    z-index: 106;
    display: block;
}

#search input[type="search"] {
    position: absolute;
    top: 50%;
    left: 0;
    margin-top: -51px;
    width: 60%;
    margin-left: 20%;
    color: rgb(255, 255, 255);
  	background: transparent;
  	border-top: 1px solid rgba(255, 255, 255, .8);
  	border-bottom: 2px solid rgba(255, 255, 255, .5);
  	border-left: 0px solid transparent;
  	border-right: 0px solid transparent;
    font-size: 40px;
  	font-family: Roboto;
    font-weight: 300;
    text-align: center;
    outline: none;
  	padding: 10px;
}
  
#search .close {
    position: fixed;
    top: 15px;
    right: 15px;
	  opacity: 1;
	  font-size: 27px;
  	color: #fff;
}

#search .close:hover{
  color: #FC2121;
  cursor: pointer;
}

body {margin:0;}

.icon-bartop {
    width: 100%;
    background-color: #555;
    overflow: auto;
}

.icon-bartop a {
    float: left;
    width: 20%;
    text-align: center;
    padding: 12px 0;
    transition: all 0.3s ease;
    color: white;
    font-size: 36px;
}

.icon-bartop a:hover {
    background-color: #000;
}
/* Remove this
.active {
    background-color: #4CAF50 !important;
}
*/

/* Add this - Select top bar active icon */
.icon-bartop a.active {
  background-color: red;
}
&#13;
<!DOCTYPE html>
<html>
<body>
<html lang="en">

<head>
  <title>Web Scraper</title>
  <script src="https://cdn.jsdelivr.net/npm/sweetalert"></script>
  <link rel="stylesheet" href="css/style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="js/scripts.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

<body>

<div class="icon-bartop">
  <a class="active" href="#"><i class="fa fa-home"></i></a> 
  <a href="#"><i class="fa fa-search"></i></a> 
  <a href="#"><i class="fa fa-envelope"></i></a> 
  <a href="#"><i class="fa fa-globe"></i></a>
  <a href="#"><i class="fa fa-trash"></i></a> 
</div>




<div class="sidebar">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<div class="icon-bar">
	  <a class="active" href=""><i class="fa fa-search"></i></a> 
	  <a href=""><i class="fa fa-bitcoin"></i></a> 
	  <a href=""><i class="fa fa-map"></i></a> 
	  <a href=""><i class="fa fa-anchor"></i></a>
	  <a href=""><i class="fa fa-shopping-cart"></i></a> 
	</div>
</div>



<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>





</body>

</html>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

只需从这两行中删除class="active"(或从中停止激活):

<a class="active" href="#"><i class="fa fa-home"></i></a>
<a class="active" href=""><i class="fa fa-search"></i></a> 

答案 3 :(得分:1)

这些是font-awesome图标,因此您可以更改定位此类的颜色:fa-homefa-search,尝试添加以下规则:

.fa.fa-home{
      color:#000000; // Change here the color
} 

.fa.fa-search{
      color:#000000; // Change here the color
}

答案 4 :(得分:1)

您正在为RUN ln -s $HOME/.cargo/env /etc/profile.d/cargo_env.sh 类分配两个元素,这会使背景变为绿色。如果你只是其中一个是绿色,你必须只分配其中一个。

为了切换&#34;绿色&#34;元素/按钮,您需要使用JavaScript从一个删除并添加到另一个。

如果这不是您正在寻找的内容,请向我提供更多详情。

答案 5 :(得分:1)

Search和Home属于同一个css类,所以它会拉出相同的背景颜色...... HTML:

    <div class="icon-bar">
      <a class="search" href=""><i class="fa fa-search"></i></a> 
      <a href=""><i class="fa fa-bitcoin"></i></a> 
      <a href=""><i class="fa fa-map"></i></a> 
      <a href=""><i class="fa fa-anchor"></i></a>
      <a href=""><i class="fa fa-shopping-cart"></i></a> 
    </div>

CSS:

.search {
    background-color: #000000 !important;
}
相关问题