【问题标题】:Move FontAwesome Icons OUTSIDE of li将 FontAwesome 图标移到 li 之外
【发布时间】:2021-01-15 16:58:29
【问题描述】:

我觉得应该是一个简单的问题,但事实证明这是一个棘手的问题。

我只是有一个带有各种 <li> 元素的 <ul>。 分配给每个 LI 的是一个很棒的字体图标。

我的问题是我希望图标位于列表项的外部,此时它在内部并推动第一行文本,我希望两行文本都内联在图标旁边。

我尝试过使用以下方法:-

#skills-list li{
    list-style-position: outside;
}

这似乎只适用于标准标记,如子弹等。我也尝试过针对其他类,例如:-

#skills-list li.i{...}

#skills-list li.a{...}

有人可以帮忙吗,下面是我的代码:-

<ul id="skills-list">
  <li><i class="fas fa-check-square"></i> I aim to implement modern technologies into my projects using a movile first approach.</li>
  <li><i class="fas fa-check-square"></i> Exposing myself to GIT allows me to track, comment and update my project in a team repository.</li>
  <li><i class="fas fa-check-square"></i> Working with BOOTSTRAP frameworks allows implementation of elegant and modern design.</li>
  <li><i class="fas fa-check-square"></i> Learning SASS allowed me to speed up my web design process, creating fast and efficient CSS3.</li>
  <li><i class="fas fa-check-square"></i> Basic Understanding of JavaScript and JQuery means that I understand the process of DOM Manipulation.</li>
  <li><i class="fas fa-check-square"></i> My previous background is in Animation, providing me with a good eye for detail and creativity.</li>
</ul>

【问题讨论】:

  • 您好。是将ul li 的默认点更改为在选择后使用检查或类似的东西吗?

标签: css twitter-bootstrap html-lists css-position


【解决方案1】:

使用绝对定位。

ul {
  list-style: none;
}

#skills-list li {
  position: relative;
}

#skills-list li i {
  position: absolute;
  left: -2em
}
<link href="https://use.fontawesome.com/releases/v5.0.7/css/all.css" rel="stylesheet" />
<ul id="skills-list">
  <li><i class="fas fa-check-square"></i> I aim to implement modern technologies into my projects using a movile first approach.</li>
  <li><i class="fas fa-check-square"></i> Exposing myself to GIT allows me to track, comment and update my project in a team repository.</li>
  <li><i class="fas fa-check-square"></i> Working with BOOTSTRAP frameworks allows implementation of elegant and modern design.</li>
  <li><i class="fas fa-check-square"></i> Learning SASS allowed me to speed up my web design process, creating fast and efficient CSS3.</li>
  <li><i class="fas fa-check-square"></i> Basic Understanding of JavaScript and JQuery means that I understand the process of DOM Manipulation.</li>
  <li><i class="fas fa-check-square"></i> My previous background is in Animation, providing me with a good eye for detail and creativity.</li>
</ul>

【讨论】:

  • 非常感谢,您提供了一些帮助,很有趣,您可以在如此简单的事情上拔出多少头发......
【解决方案2】:

您可以尝试使用 position: absolute; 将图标()定位在相应列表项之外;

我不知道你想要达到的实际视觉效果,但应该是这样的:

li {
  position: relative;
}

i {
  position absolute;
  left: -24px;
  top: 0;
}

【讨论】:

    【解决方案3】:

    只需使用引导排版类将列表标记为无样式

    <ul id="skills-list" class="list-unstyled">
    

    运行sn-p查看:

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
    
    
    <ul id="skills-list" class="list-unstyled">
      <li><i class="fas fa-check-square"></i> I aim to implement modern technologies into my projects using a movile first approach.</li>
      <li><i class="fas fa-check-square"></i> Exposing myself to GIT allows me to track, comment and update my project in a team repository.</li>
      <li><i class="fas fa-check-square"></i> Working with BOOTSTRAP frameworks allows implementation of elegant and modern design.</li>
      <li><i class="fas fa-check-square"></i> Learning SASS allowed me to speed up my web design process, creating fast and efficient CSS3.</li>
      <li><i class="fas fa-check-square"></i> Basic Understanding of JavaScript and JQuery means that I understand the process of DOM Manipulation.</li>
      <li><i class="fas fa-check-square"></i> My previous background is in Animation, providing me with a good eye for detail and creativity.</li>
    </ul>

    【讨论】:

      【解决方案4】:
            <ul id="skills-list">
              <i class="fas fa-check-square"></i><li> I aim to implement modern technologies into my projects using a movile first approach.</li>
            </ul>
      

      这就是你想要的吗?

      【讨论】:

      • 你是认真的吗?
      • 我是认真的吗?不,我会说我是一个很有趣的人:)
      猜你喜欢
      • 2013-08-27
      • 2014-12-24
      • 2018-04-16
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 2018-06-08
      • 2014-05-04
      相关资源
      最近更新 更多