html - 如何在列表项周围创建价格标签(如边框)

标签 html css styles html-lists

如何在列表项的左侧创建自定义边框的边框?

像这样:

http://www.dar-ling.com.php53-12.dfw1-1.websitetestlink.com/wp-content/themes/darling/img/filters.png

我考虑过使用 css 3 Angular ...但是我无法实现带有边框的内圆或孔...并且它可能比使用图像更乏味。

我现在正在考虑使用背景图像执行此操作...并关闭了左侧的边框,并试图让图形将其自身定位在元素的左边缘,但没有运气。我的元素都有不同的长度,并且它们在水平 slider 中向左浮动,使其更加复杂。

我还需要不同的悬停和事件样式,如图所示。

最后,我需要提供一个圆形或椭圆形,可以容纳与类别中的元素数量相关的数字,并将其附加到样式列表项框的右上角。

这是我迄今为止的进展:

HTML:

<div class="filters">
                <div class="filters-inner">
                      <ul id="filters-slider" class="filters-list">
                    <li><a href="#">Darling</a></li>
                    <li><a href="#">Online Audience</a></li>
                    <li><a href="#">Digital Strategy</a></li>
                    <li><a href="#">Creative</a></li>
                    <li><a href="#">Mobile</a></li>
                    <li><a href="#">eCommerce</a></li>
                    <li><a href="#">Social Media</a></li>
                    <li><a href="#">Search</a></li>
                    <li><a href="#">Advertising</a></li>
                    <li><a href="#">Ramblings</a></li>
                    <li><a href="#">Ideas</a></li>
                    <li><a href="#">Newy New</a></li>
                    <li><a href="#">Freshy Fresh</a></li>
                    <li><a href="#">Search</a></li>
                    <li><a href="#">Advertising</a></li>
                    <li><a href="#">Ramblings</a></li>
                    <li><a href="#">Ideas</a></li>
                    <li><a href="#">Newy New</a></li>
                    <li><a href="#">Freshy Fresh</a></li>

                </ul>
          </div>
</div>

CSS:

.filters {
background-color: #fff;
padding-top: 3px;
padding-bottom: 5px;
width: 1145px;
height: 45px;
float: left;
-webkit-box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.1), 0 -1px 10px rgba(0, 0, 0, 0.1);
  -moz-box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.1), 0 -1px 10px rgba(0, 0, 0, 0.1);
  box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.1), 0 -1px 10px rgba(0, 0, 0, 0.1);

}
 .filters-inner {
width: 1140px;
margin-right: auto;
margin-left: auto;
font-size: 11px;
overflow: hidden;
color: #999;
    -webkit-border-radius: 0;
      -moz-border-radius: 0;
      border-radius: 0;

 }
ul.filters-list {
text-align: center;
white-space: nowrap;
display: inline-block;
padding-top: 10px;
}
ul.filters-list li {
float: left;
list-style-type: none;
padding-top: 2px;
padding-right: 20px;
padding-bottom: 2px;
padding-left:20px;
background-color: #fff;
margin-right: 10px;
margin-left: 10px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: none;
border-top-color: #CCC;
border-right-color: #CCC;
border-bottom-color: #CCC;
border-left-color: #CCC;
background-image: transparent url(http://www.dar-ling.com.php53-12.dfw1-1.websitetestlink.com/wp-content/themes/darling/img/leftside_tag_up.png);
background-repeat: no-repeat;
background-position: left center;
}
ul.filters-list li:hover {
background-color: #ECECEC;
background: transparent url(http://www.dar-ling.com.php53-12.dfw1-1.websitetestlink.com/wp-content/themes/darling/img/leftside_tag_hover.png) no-repeat left center;
}ul.filters-list li a {
color: #666666;
font-weight: bold;
}
ul.filters-list li a:hover {
text-decoration: none;
}

div.sample {
padding-top: 200px;
}

有人知道如何正确执行此操作吗?

最佳答案

这是一个适用于背景图像 Sprite 的解决方案。简而言之,我将标签用于整个“价格标签”形状(用户更容易点击),并使用背景冲刺来表示悬停/事件状态。我还将“数量”数字包装在跨度标记中。

解决方案示例:http://jsfiddle.net/alexroper/zhrwA/34/

以下是“价格标签”列表的 HTML:

<ul id="filters-slider" class="filters-list">
  <li><a href="#">Darling</a> <span class="tag-qty">103</span></li>
  <li class="active"><a href="#">Online Audience</a> <span class="tag-qty">9</span</li>
  <li><a href="#">Digital Strategy</a> <span class="tag-qty">20</span></li>
</ul>

以下是构建“价格标签”的样式:

ul.filters-list {
  text-align: center;
  white-space: nowrap;
  display: inline-block;
  padding-top: 10px;
}
ul.filters-list > li {
  color: #666666;
  font-weight: bold;
  float: left;
  list-style-type: none;
  line-height: 26px;
  margin-right: 10px;
  margin-left: 10px;
  position: relative;
}
ul.filters-list > li > a {
  color: #666666;
  padding: 0 18px 0 24px;
  background: url('https://www.dropbox.com/s/n8e74eikwf82vks/tag_sprite.png?raw=1') 0 0 no-repeat;
  border-right: 1px solid #ccc;
  display: block;
}
ul.filters-list > li > a:hover,
ul.filters-list > li.active > a {
  text-decoration:none;
  background-position: 0 -30px;
}

这些样式创建“数量”数字:

.filters-list .tag-qty {
  position: absolute;
  top: -8px;
  right: -9px;
  border: 1px solid #bbb;
  line-height: 16px;
  display: inline-block;
  padding: 0 5px;
  background: #fff;
  -webkit-border-radius: 9px;
          border-radius: 9px;
     -moz-background-clip: padding; 
  -webkit-background-clip: padding-box; 
          background-clip: padding-box;
  -webkit-box-shadow: 0px 0px 3px 0px #ccc;
          box-shadow: 0px 0px 3px 0px #ccc;
}
.filters-list .active .tag-qty {
  background:#ebebeb;
}

关于html - 如何在列表项周围创建价格标签(如边框),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13003909/

相关文章:

html - 我无法更改 font awesome 的样式

wpf - ToggleButton 悬停和单击行为

jquery - 在移动 View 而不是桌面 View 中制作响应式 slider

php - 带撇号的 PHP 查询中的搜索词

jQuery UI Droppable - 阻止覆盖区域

javascript - document.querySelectorAll 与 div.style 一起不起作用

python - 使用样式使用 Pandas 样式为单个单元格着色

表单输入的 Javascript 日期验证

css - 如何定位嵌套列表项?

javascript - 在 css 中设置固定大小并在 javascript 中使用它