JP.*_*JP. 4 html javascript css
谁能想到一种方法来使用ol/ lilist中的数字来标记图像?
<ol>
<li><img /></li>
<li><img /></li>
<li><img /></li>
</ol>
Run Code Online (Sandbox Code Playgroud)
应用一些CSS应输出以下内容:
------ ------ ------
| | | | | |
| | | | | |
| 1| | 2| | 3|
------ ------ ------
Run Code Online (Sandbox Code Playgroud)
每个正方形都是小型的图片.
我知道我可以在其中插入一个li带有数字的新元素并根据需要进行操作,但我想用内置ol编号来完成.
很容易:
ol {
counter-reset: listCount;
}
li {
float: left;
border: 3px solid #f90;
counter-increment: listCount;
position: relative;
}
li:after {
content: counter(listCount,decimal-leading-zero);
position: absolute;
bottom: 0;
right: 0;
width: 2em;
height: 2em;
color: #fff;
background-color: rgba(0,0,0,0.5);
text-align: center;
line-height: 2em;
}
Run Code Online (Sandbox Code Playgroud)
当然,这确实要求用户拥有一个能够使用css生成内容的浏览器,这很好地排除了IE.
参考文献:
似乎有点hacky恕我直言,但这工作(至少在Firefox中):
<ol>
<li><img src="http://placekitten.com/100/100" /></li>
<li><img src="http://placekitten.com/100/100" /></li>
<li><img src="http://placekitten.com/100/100" /></li>
</ol>
ol {}
ol li {
float: left;
list-style-position: inside;
position: relative;
width: 100px;
height: 100px;
margin-right: 5px;
line-height: 170px;
text-indent: 85px;
color: #fff;
}
ol li img {
position: absolute;
left: 0;
top: 0;
z-index: -1;
}
Run Code Online (Sandbox Code Playgroud)
如果我是你,我会选择其他元素解决方案.
编辑:在chrome,IE9和8中测试过.似乎在两者中都能一致地工作.然而,IE7中的问题可能会被一些额外的浏览器特定的CSS修复.