html - 样式列表按钮

标签 html css image hyperlink html-lists

使用列表,我想创建一个链接列表,如图所示

HTML List with CSS background images

<div id="toolbarbottom" class="toolbar" style="position: fixed; clear: both; overflow: visible; bottom: 0px; left: 0px; width: 100%;">
     <ul>
         <li id="active"><span><a id="current" href="#add" class="button">News</a></span></li>
         <li><span> <a href="#Updates" class="button">Updates</a></span> </li>
         <li><span><a href="#Contact" class="button">Contact Us</a></span></li>
         <li><span><a href="#Website" class="button">Website</a> </span></li>
         <li><span><a href="#Refresh" id="#Refresh" class="button">Refresh</a></span> </li>
     </ul>
</div>

我有点卡在 CSS(按钮)和列表元素之间的间距上。使列表以这种形式出现。有人知道我该如何解决这个问题吗?

最佳答案

或者另一种方法是使用 float ,并使 ul display: inline-block包含 float 的 li

您需要稍微更改 HTML,以便 spana 里面- 这样您就可以隐藏跨越文本,但保留 a 的图像背景和可点击区域元素,我还会给每个链接一个唯一的引用(类或 ID),以便可以单独应用背景。

示例 HTML:

<div id="toolbarbottom" class="toolbar" style="position: fixed; top: 0px; left: 0px; width: 100%;">
     <ul>
         <li class="active"><a href="#add" id="madd"><span>News</span></a></li>
         <li><a href="#Updates" id="mupdates"><span> Updates</span></a></li>
         <li><a href="#Contact" id="mcontact"><span>Contact Us</span></a></li>
         <li><a href="#Website" id="mwebsite"><span>Website </span></a></li>
         <li><a href="#Refresh" id="mrefresh"><span>Refresh</span></a> </li>
     </ul>
</div>

然后您可以将整个背景放在 ul 上,并将单独的图像放在每个链接上。

#toolbarbottom ul {
   list-style: none; 
   margin: 0; 
   padding: 0; 
   display: inline-block; 
   width: 100%; 
   background: #ff0;
}

#toolbarbottom li {
   float: left; 
   width: 80px; 
   height: 80px; 
   border: 1px solid #000; /* not required, just to show where individual links are */
} 

#toolbarbottom li a { /* make link fill the li element */
   display: block; 
   height: 80px; 
}

#toolbarbottom li span { /* hide the text */
   position: absolute;
   clip: rect(1px, 1px, 1px, 1px);
   clip: rect (1px 1px 1px 1px);
}

/* couple examples of where to put individual backgrounds */   
#toolbarbottom #mupdates {background: #dad;}
#toolbarbottom #mcontact {background: #0f0;} 

关于html - 样式列表按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6585344/

相关文章:

javascript - VideoJS : not working on IOS

javascript - 你能修复屏幕上的滚动条吗?

javascript - 两个 div 同时滚动,直到一个到达底部

python linux - 以文件名显示图像作为查看器窗口标题

java在另一个上绘制图像

javascript - IE 6 中的 HTML5 自定义数据属性是否为 “work”?

css - 100% 高度的 div 有问题

css - 如何摆脱 shadow-dom 中的用户代理样式表

image - Bing 图像搜索 API 按格式过滤

html - 在 div 的右侧垂直对齐两个 div