【问题标题】:Replace bullet points with emojis (or other Unicode characters) (But Don't change nested bullets)用表情符号(或其他 Unicode 字符)替换项目符号点(但不要更改嵌套项目符号)
【发布时间】:2020-02-08 21:37:13
【问题描述】:

在我的沙盒中:

.thunderbolt li:nth-child(1):before {content: "\26A1  ";}
.thunderbolt li:nth-child(2):before {content: "???? ";}
.thunderbolt li:nth-child(3):before {content: "???? ";}
.thunderbolt li:nth-child(4):before {content: "???? ";}
.thunderbolt li:nth-child(5):before {content: "???? ";}
.thunderbolt li:nth-child(6):before {content: "\2685";}
<div>
<ul class="thunderbolt">
<li>ThunderBolt devices only get recognized by BootCamp on boot.</li>
<li>If you unplug your ThunderBolt device while using Windows, you'll have to shut down then reboot your OS to get it recognized again.</li>
<li>Disable <b>Fast Startup </b>in Windows 8/10.</li>
<ul>
<li>Also try holding <b>Shift </b>when you click&nbsp;<b>Start </b>&gt; <b>Shut down</b>.</li>
</ul>
<li>Wait a solid chunk of seconds on the login screen after boot to allow BootCamp to configure Thunderbolt devices.</li>
<li><b>Sleep&nbsp;</b>simply does not work in BootCamp with a ThunderBolt device connected.</li>
</ul>
</div>

http://www.cssdesk.com/M6Cyz

我希望 unicode 字符替换项目符号点。相反,字符只是项目符号一起显示,与文本一致。

另外,我不希望 .thunderbolt 类应用于嵌套的 &lt;ul&gt;--我只是希望这是一个标准的要点。

我试过.thunderbolt list-style: none,但所做的只是让我的雷电符号消失。

此外,显示的结果网页会跳过 .thunderbolt li:nth-child(4):before {content: "???? ";} 中的第 4 个孩子的字符,而是显示 .thunderbolt li:nth-child(5):before {content: "???? ";} 中的字符。似乎代码将嵌套的&lt;li&gt; 视为父级&lt;ul&gt; 中的第四个孩子。


  1. 我如何替换&lt;ul&gt; 中的要点为 unicode 字符?
  2. 如何告诉 CSS 在应用 nth-child(n) 属性时跳过嵌套的 &lt;ul&gt;

【问题讨论】:

  • @MrLister 对不起,我已经有一段时间没来这里了。将代码添加到帖子内容中

标签: css unicode html-lists emoji


【解决方案1】:

ul.thunderbolt > li:nth-child(1) {
  list-style: "\26A1   ";
  list-style-position: outside;
}
ul.thunderbolt > li:nth-child(2) {
  margin-top: 10px;  
  list-style: "?  ";
  list-style-position: outside;
}
ul.thunderbolt > li:nth-child(3) {
  margin-top: 10px;
  list-style: "?  ";
  list-style-position: outside;
}
ul.thunderbolt > li:nth-child(5) {
  margin-top: 10px;
  list-style: "?  ";
  list-style-position: outside;
}
ul.thunderbolt > li:nth-child(6) {
  margin-top: 10px;
  list-style: "?  ";
  list-style-position: outside;
}
ul.thunderbolt ul li {
  margin-top: 10px;
  list-style-type: circle;
}
<ul class="thunderbolt">
<li>ThunderBolt devices only get recognized by BootCamp on boot.</li>
<li>If you unplug your ThunderBolt device while using Windows, you'll have to shut down then reboot your OS to get it recognized again.</li>
<li>Disable <b>Fast Startup </b>in Windows 8/10.</li>
<ul>
<li>Also try holding <b>Shift </b>when you click&nbsp;<b>Start </b>&gt; <b>Shut down</b>.</li>
</ul>
<li>Wait a solid chunk of seconds on the login screen after boot to allow BootCamp to configure Thunderbolt devices.</li>
<li><b>Sleep&nbsp;</b>simply does not work in BootCamp with a ThunderBolt device connected.</li>
</ul>
  • &gt; li 使样式更改仅影响父列表中的元素。
  • 我使用ul.class_name ul li 将嵌套&lt;li&gt; 项的list-style-type 更改为打开的circle,而不是关闭的disc
  • 我在 Blogspot 中执行此操作,它有一个内置样式表(我不想备份、编辑然后重新上传),所以我必须在更改后添加 !important 以便它们申请。
    • 示例:
    • list-stye: "\26A1 "!important;
    • list-style-position: outside!important;
  • CSS 仍然将嵌套的&lt;li&gt; 视为nth-child(4),因此我不得不在我的父列表中的nth-child(n) 编号中跳过它。 (请注意我是 nth-child(3),然后跳到 nth-child(5)。)

Credit

【讨论】:

    【解决方案2】:

    答案1:如果你使用unicode而不是子弹,你就需要使用,

    .thunderbolt li: {
       position: relative;
       list-style: none;
       overflow: hidden;
    }
    .thunderbolt li:after {
       position: absolute;
       top: 50%;
       left: -2%;
       transform: transletX(-50%);
    }
    

    请使用您的 unicode 作为position: absolute;,我希望您的代码是简单的解决方案。相同的 css 将适用于所有 li,但您只需更改 content: 'here is your unicode'; 我希望这将是实现 unicode 项而不是项目符号项的最简单方法。

    答案 2: 如果您使用 .thundebolt &gt; li,那么我希望它仅适用于特定列表。你可以试试看。

    注意:如果您有更好的解决方案,请告诉我,我想从您那里了解更多信息,谢谢!

    【讨论】:

    • 在去掉.thunderbolt li: { 中的: 之后,似乎所做的就是去掉了要点。我希望 unicode 字符代替项目符号点。
    猜你喜欢
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2010-10-09
    • 2016-03-22
    • 1970-01-01
    • 2020-12-04
    相关资源
    最近更新 更多