我想在css和html中创建一个垂直标尺.也许这张照片显示我的目的.创建这个垂直标尺?
我的代码是:
<div>
<li class='ruler'>0</li>
<li class='ruler'>5</li>
<li class='ruler'>10</li>
<li class='ruler'>15</li>
<li class='ruler'>20</li>
</div>
.ruler {
background: #ffffff;
box-shadow: 0 -1px 1em hsl(60, 60%, 84%) inset;
border-radius: 2px;
border-left: 6px solid #000;
border-bottom: 1px solid #CCCCCC;
color: #000000;
margin: 0;
height: 80px;
list-style: none;
text-align: right;
width: 60px;
}
Run Code Online (Sandbox Code Playgroud)

这就是我(可能)尝试实现这个想法的方式:
ol,
li {
/* removing the default list counters/markers: */
list-style-type: none;
}
ol {
/* resetting the counter so every <ol>
has an independent count: */
counter-reset: marker;
}
li {
/* 'real world' measurements are perhaps not
entirely faithful on screen: */
height: 1cm;
border-top: 1px solid #000;
/* including the border in the height of the element: */
box-sizing: border-box;
width: 2.5em;
/* incrementing the counter: */
counter-increment: marker;
/* to position the counter relative
to the <li>: */
position: relative;
border-left: 2px solid #000;
}
li:first-child,
li:nth-child(5n) {
/* longer mark for the first and
every fifth marker: */
width: 5em;
}
/* preventing a 'tail' on the <ol> from the
height of the last <li> (the counter is
displayed at the top, not the bottom): */
li:last-child {
height: 0;
}
li:first-child::after,
li:nth-child(5n)::after {
/* positioning the pseudo-element that
contains the counter: */
position: absolute;
/* vertically-centering it alongside the
top border: */
top: -0.5em;
/* moving it the full width of the element,
outside of the right side of the element: */
left: 100%;
height: 1em;
line-height: 1em;
width: 2em;
text-align: center;
/* specifying the counter to use: */
content: counter(marker);
}Run Code Online (Sandbox Code Playgroud)
<ol id="rule">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ol>Run Code Online (Sandbox Code Playgroud)
参考文献: