[英]color in button background with css
I'm building my navigation bar and I currently am using 3 images for each option on the menu. 我正在构建我的导航栏,我目前正在为菜单上的每个选项使用3个图像。 I'm using css to replace the images based on when its non-selected, hovered, and selected.
我正在使用css来替换基于未选择,悬停和选择的图像。 Using html and css, i only knew how to highlight the actual words (ie home, order, how it works...), i couldn't figure out a way to color in the whole box when selected.
使用html和css,我只知道如何突出显示实际的单词(即主页,顺序,它是如何工作的......),当我选择时,我无法想出一种在整个框中着色的方法。
Is there a way to do this with html/css without using image files? 有没有办法用html / css做这个而不使用图像文件?
So little information provided but still I will try assuming the most general way. 提供的信息很少,但我仍然会尝试采用最一般的方式。
In a basic ul
and li
menu structure, like the following. 在基本的
ul
和li
菜单结构中,如下所示。
<ul>
<li>
<a href="#">Link Text</a>
</li>
</ul>
The box surrounding all the menus are selected by simply 简单地选择围绕所有菜单的框
ul {
/* Styles */
}
The box surrounding a menu item ( probably what you are asking ) is selected by ul > li
菜单项周围的框( 可能是你要问的 )由
ul > li
ul > li {
/* Style */
background-color: red;
}
Note: You can also use ul li { ... }
for more general way. 注意:您也可以使用
ul li { ... }
来获得更一般的方法。
Where as, link itself is selected by ul > li a
其中,链接本身由
ul > li a
ul > li a {
/* Style */
}
Try to implement this on your case. 尝试在你的情况下实现这一点。
应该可以使用color
和background-color
的组合来实现这种效果。
........................... Hi now do this easily as like this ...........................嗨,现在就这样轻松做到这一点
css CSS
ul{
list-style:none;
width:200px;
padding:0;
margin:0;
background:green;
}
ul li{
display:block;
background:pink;
margin:3px;
}
a:hover{
background:red;
}
a{
text-decoration:none;
display:block;
padding:0 30px;
line-height:35px;
position:relative;
}
.shope{
padding-left:60px;
}
.shope:hover{
background:none;
}
.shope:after{
content:'';
position:absolute;
left:10px;
top:8px;
width:30px;
height:20px;
background:lightgreen;
}
.shope:before{
content:'';
position:absolute;
right:20px;
top:8px;
width:30px;
height:20px;
background:darkred;
}
html HTML
<ul>
<li><a href="#">home</a></li>
<li><a href="#">home</a></li>
<li><a href="#">home</a></li>
<li><a href="#">home</a></li>
<li><a href="#">home</a></li>
<li><a href="#" class="shope">my cart 1</a></li>
</ul>
to have different colors of menus on hover 在悬停时使用不同颜色的菜单
have your css something like this: 你的css是这样的:
div.home:hover{
color: #4C787E;
}
div.aboutus:hover{
color: #616D7E;
}
div.contact:hover{
color: #808000;
}
and html goes like this: 和HTML这样:
<div id="menu">
<ul>
<li class="menu1"><div class="home"><a href="#">home</a></div>
</li>
<li class="menu2"><div class="aboutus"><a href="...">about us</a></div></li>
<li class="menu3"><div class="contact"><a href="...">contact</a></div></li>
</ul>
</div>
same as above you can apply it on the sub-menus also. 与上面相同,您也可以在子菜单上应用它。
Try it. 试试吧。
Hope it helps you. 希望它能帮到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.