简体   繁体   English

项目符号如何指向<li>标签有边框顶部使用 list-style-position: inside</li>

[英]How can the bullet point inside an <li> tag have border-top using list-style-position: inside

I am putting together an unordered list.我正在整理一个无序列表。 Each line item contains several elements ( <h> tags, <p> tags, etc.) and is separated by a top-border .每个行项目包含多个元素( <h>标签、 <p>标签等),并由top-border分隔。

By default, the bullet point is not underneath the top-border.默认情况下,项目符号点不在上边框下方。 To fix this, I assigned list-style-position: inside;为了解决这个问题,我分配list-style-position: inside; to <ul> .<ul> However, the content of the list now "wraps" around the bullet point.但是,列表的内容现在“包裹”在项目符号点周围。 It would be great to separate the bullet point and the content vertically.将项目符号点和内容垂直分开会很棒。

 li { border-top: 1px solid #000000 } ul.inside { list-style-position: inside; }
 <ul> <li> Item 1 <p> Content does not wrap around bullet point. Great. But border-top is not over the bullet </p> </li> <li> Item 2 </li> <li> Item 3 </li> </ul> <hr> <ul class="inside"> <li> Item 1 <p> Content wraps around the bullet point. Boo! But border-top is over the bullet though! </p> </li> <li> Item 2 </li> <li> Item 3 </li> </ul>

Is there a clean way to do this?有没有一种干净的方法可以做到这一点?

here you go给你 go

 li { border-top: 1px solid #000000 } ul.inside { list-style-position: inside; } ul { list-style: none; padding: 0; } li::before { Content: "•"; font-size: 25px; position: relative; top: 2px; padding-right: 5px; }
 <ul> <li> Item 1 <p> Content does not wrap around bullet point. Great. But border-top is not over the bullet </p> </li> <li> Item 2 </li> <li> Item 3 </li> </ul> <ul class="inside"> <li> Item 1 <p> Content wraps around the bullet point. Boo! But border-top is over the bullet though! </p> </li> <li> Item 2 </li> <li> Item 3 </li> </ul>

Found an innovative solution using CSS Grid courtesy of Modern CSS .使用 CSS 网格找到了一个创新的解决方案,由Modern CSS提供。 It's important that the content in the <li> tags is wrapped in a <div> . <li>标签中的内容包含在<div>中,这一点很重要。

That said, this solution requires :before and does not work with ::marker .也就是说,此解决方案需要:before并且不适用于::marker

 ul { padding: 0; } li { border-top: 1px solid #000000; display: grid; grid-template-columns: 0 1fr; grid-gap: 1em; } ul li::before { content: '•'; font-size: 1em; }
 <ul> <li> <div> <div>Hello</div> <div>Second div</div> </div> </li> <li> Bullet 2 </li> <li> Bullet 3 </li> </ul>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IE list-style-position:内部问题 - IE list-style-position:inside issues 带列表样式位置的段落换行:内部 - Paragraph wrap with list-style-position: inside 使用 list-style-position: inside 使 li 内的 div 出现在数字的右侧 - Make div inside li with list-style-position: inside appear to the right of number 如何在 html 中的列表内容及其编号之间保持单独的 alignment 将列表样式位置保留在内部? - How to keep separate alignment between the list content and its numbering in html keeping list-style-position to inside? 如何获得令人惊叹的“图标作为项目符号”以获取属性列表样式位置:外部? - How to get fontawesome "icons as bullet points" to get the property list-style-position: outside? 列表样式类型为无序列表:无; &list-style-position:内部; 在Firefox中占用额外的空间 - Unordered list with list style type: none; & list-style-position: inside; takes extra space in Firefox 具有list-style-position的列表项上的意外间距:Internet Explorer中的内部 - Unexpected spacing on list-item with list-style-position: inside in Internet explorer 有没有办法在列表样式位置为“内部”时显示文本缩进? - Is there a way to show text-indent while list-style-position is ‘inside'? 如何将带有圆底角的border-top添加到 <li> 元素? - How to add border-top with rounded bottom corners to <li> elements? 如何在JavaScript标记中管理CSS Border-top? - How to manage css border-top in javascript tag?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM