html - 在编号元素符号和缩进文本的左侧添加边框

标签 html css

这是我刚刚回答的问题的后续。但是,我意识到该解决方案在我的实际代码中引起了另一个问题。

我有一个 OL 列表,其中包含编号的 LI 元素。我想在数字外部(左侧)的每个单独的 LI 元素周围放置一个左边框。我还希望这些行正确缩进,以便第 2+ 行直接出现在步骤的第 1 行下方。

这是最新的 fiddle http://jsfiddle.net/z7gkLnc7/5/

(我想保留 LI 元素周围的 div 包装器。)

<ol>
    <div class = "li_wrapper">
        <li>I am a line. A long line that keeps on going. It's what I do and who I am.</li>
    </div>
    <div class = "li_wrapper">
        <li>I am a line</li>
    </div> 
</ol>

样式:

.li_wrapper{
    font-size:20px;
    margin-top:10px;
}

li{
    border-left:red 2px solid;
    list-style-position: inside; // Fixed border position, but how to fix indent?
}

最佳答案

像这样?

.li_wrapper{
    font-size:20px;
    margin-top:10px;
    padding-left:30px;
    border-left:2px solid red;
}
li{list-style-position: outside;}
<div><b>
   I'd like for the red lines to be to the left of the numbers AND for the text to be indented. 
    </b>
</div><br/><br/>


<div>
    Red line is, incorrectly, to the right of the number:
</div>
<ol id = "one">
    <div class = "li_wrapper">
        <li>I am a line. A long line that keeps on going. It's what I do and who I am.</li>
    </div>
    <div class = "li_wrapper">
        <li>I am a line</li>
    </div>
</ol>

<div>
    Text is not indented:
</div>
<ol id = "two">
    <div class = "li_wrapper">
        <li>I am a line. A long line that keeps on going. It's what I do and who I am.</li>
    </div>
    <div class = "li_wrapper">
        <li>I am a line</li>
    </div>
</ol>

<div>
   Cannot mix and match. Not right.:
</div>
<ol id = "three">
    <div class = "li_wrapper">
        <li>I am a line. A long line that keeps on going. It's what I do and who I am.</li>
    </div>
    <div class = "li_wrapper">
        <li>I am a line</li>
    </div>
</ol>

关于html - 在编号元素符号和缩进文本的左侧添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27484427/

相关文章:

html - 如何使用 CSS3 将背景颜色应用于复选框?

javascript - 如何在按钮中包含图像或文本?

css - CSS 不支持从数字开始的 ids 和 classes 是有原因的吗?

css - 试图完成一个设计,却无法解决一个小的 CSS 问题

javascript - 如何将焦点集中的div居中? [垂直]

html - 在 ruby​​ on Rails 中添加到另一个页面的链接

javascript - 播放视频时标题栏中的音量图标 - 嘈杂的选项卡

javascript - 使用 Javascript 检查文本框上的整数验证

javascript - 将鼠标悬停在 td 上并添加一个类以跨越

javascript - 在调整窗口大小之前,在 ready 上应用 CSS 无法正确呈现