<html>
<head>
<meta charset="utf-8">
<title>CSS3 实现翻转列表 by 一丝</title>
</head>
<body>
<p>如何用 CSS3 实现一个翻转的列表,要求在IE中看到是正序的,非ie用户是倒序的(包括内容)</p>
<h2>使用 Flex 和 counter-increment: list -1</h2>
<p>前提是列表个数是已知且不变的</p>
<ol class="type-toc">
<li>list 1</li>
<li>list 2</li>
<li>list 3</li>
<li>list 4</li>
</ol>
<h2>使用 Flex 和 ol 中的 reversed 属性</h2>
<p>显然该方法更加灵活</p>
<ol reversed>
<li>list 1</li>
<li>list 2</li>
<li>list 3</li>
<li>list 4</li>
</ol>
</body>
</html>
ol{
display: box; /* Chrome 4+, Safari 3.1, iOS Safari 3.2+ */
display: box; /* Firefox 17- */
display: flex; /* Chrome 21+, Safari 6.1+, iOS Safari 7+, Opera 15/16 */
display: flex; /* Firefox 18+ */
display: flex; /* IE 10 */
display: flex; /* Chrome 29+, Firefox 22+, IE 11+, Opera 12.1/17/18, Android 4.4+ */
/* 旧版本 flex */
box-direction: reverse;
box-direction: reverse;
box-orient: vertical;
box-orient: vertical;
flex-direction: column-reverse;
flex-direction: column-reverse;
flex-direction: column-reverse;
}
li{
background-color: lightblue;
margin-bottom: 5px;
}
/* ==========================================================================
display:flex 后需要重新生成列表序号
========================================================================== */
/**
* 数字编号,兼容 IE8+
* 1. 为每个 ol 元素创建新的计数器实例
* 2. 隐藏默认的列表项
*/
ol.type-toc,
.type-toc ol {
counter-reset: list 5;/* 1 */
list-style-type: none !important; /* 2 */
list-style-type: decimal\9 !important;
margin-top: 16px;
width: 100%;
width: auto\9;
}
.type-toc li {
position: relative;
}
.type-toc li:before {
color: blue;
position: absolute;
left: -29px;
top: 0;
}
/**
* 1. 降序显示列表编号
* 2. 所有计数器中间以“.”分隔的值
*/
.type-toc li:before {
counter-increment: list -1; /* 1 */
content: counters(list, ".")"."; /* 2 */
display: none\9;
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |