简体   繁体   English

使用CSS和HTML上的文本将不同的图像作为按钮添加到每个LI

[英]Adding a different image as a button to each LI using css and text on html

Im trying to make it to were I can add an image to each LI not a bullet image but an image to represent the button itself, and I want to be able to use text in the html. 我试图做到这一点,因为我可以向每个LI添加图像,而不是项目符号图像,而是代表按钮本身的图像,并且我希望能够使用html中的文本。 I have tried #glass_menu ul li.shard1,.shard1 I cant figure it out can someone please help!! 我尝试了#glass_menu ul li.shard1,.shard1我不知道可以有人帮忙!

css: CSS:

#glass_menu {
width:984px;
text-align:center;
text-decoration:none;
display:inline;
position:relative;
bottom:-20px;
}
#glass_menu ul li{
padding: 0 40px 0 40px;
display: inline;
}

.shard1{
background-image:url(glasshard1.png);
background-repeat: no-repeat;
width:30px;
height:30px;

}
.shard2{
background-image:url(glasshard2.png);
background-repeat: no-repeat;
width:30px;
height:30px;    
}
.shard3{

}
.shard4{

}
.shard5{ 

}
.shard6{

}

html: 的HTML:

<div id="glass_menu">
<ul class="menu">
<li class="shard1"><a href="index.php">home</a></li>
<li class="shard2"><a href="Estimate.php"><span>Estimate</span></a></li>
<li class="shard3"><a href="why-should-you-choose-us.html"><span>help</span></a></li>
<li class="shard4"><a href="Contact.php"><span>Contact Us</span></a></li>
<li class="shard5"><a href="affiliates.html"><span>Affiliates</span></a></li>
<li class="shard6"><a href="Location.html"><span>Location</span></a></li>
</ul>
</div><!--end glass_menu div-->

1) Reset your list: 1)重置您的列表:

#glass_menu ul li {
    list-style:none;
    margin:0;
    padding:0;
}

2) Don't style the LI, except for positioning/floats. 2)除了定位/浮动以外,不要为LI设置样式。

#glass_menu li {
    float:left
}

3) Style the LINK and use display:block . 3)设置LINK的样式并使用display:block Remove the SPAN, there's no reason for it to be there. 删除SPAN,没有任何理由。

.shard1 a {
    background-image:url(glasshard1.png);
    background-repeat: no-repeat;
    width:30px;
    display:block;
    padding-left: 30px; <--- you need this to move your text to the right to uncover the background image.
}

4) Read my tutorial: I love lists. 4)阅读我的教程: 我喜欢清单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM