【问题标题】:How to move list items to the right?如何将列表项向右移动?
【发布时间】:2022-01-26 04:09:51
【问题描述】:

我正在开发一个投资组合网站,但页脚部分不是我想要的样子。我想将无序列表项移动到右侧。我试过 justify-content: right;、justify-content: end; 和 right,但是,它不起作用。

.footer {
  grid-area: footer;
  margin-top: 38px;
  margin-left: 10%;
  margin-right: 10%;
  height: 700px;
  margin-bottom: 100px;
}

.footer-text {
  padding: 200px 100px;
  font-family: "Khula", sans-serif;
  font-weight: 600;
  font-size: 80px;
  color: #bbbbbb;
  line-height: 80px;
  letter-spacing: -1px;
  display: inline-block;
}

.footer-contact {
  font-family: "Khula", sans-serif;
  font-weight: 600;
  font-size: 35px;
  color: #222222;
  line-height: 50px;
  letter-spacing: -1px;
  text-decoration: none;
  padding-top: 0px;
  margin-left: 60px;
  margin-right: 60px;
}

.footer-text-color {
  color: #222222;
}

ul {
  list-style-type: none;
  text-decoration: none;
  display: inline-block;
}
<footer class="content-container footer">

  <div class="footer-text">Let's <br> <span class="footer-text-color">Connect</span></div>

  <ul>

    <li><a href=a.html class="footer-contact">Email</a></li>
    <li><a href=b.html class="footer-contact">LinkedIn</a></li>
    <li><a href=c.html class="footer-contact">GitHub</a></li>
  </ul>

</footer>

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    给你的&lt;ul&gt; 上课。我称它为center。然后添加以下样式,如 CSS 中所示。另外,删除footer-contact 上的margin-left: 60px; 我用父级上的弹性框将它们隔开。

    .footer {
        grid-area: footer;
        height: 700px;
        margin-bottom: 100px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
    }
    
    .footer-text {
      padding: 200px 100px;
      font-family: "Khula", sans-serif;
      font-weight: 600;
      font-size: 80px;
      color: #bbbbbb;
      line-height: 80px;
      letter-spacing: -1px;
      display: inline-block;
    }
    
    .footer-contact {
      font-family: "Khula", sans-serif;
      font-weight: 600;
      font-size: 35px;
      color: #222222;
      line-height: 50px;
      letter-spacing: -1px;
      text-decoration: none;
      padding-top: 0px;
      margin-right: 0;
    }
    
    .footer-text-color {
      color: #222222;
    }
    
    ul {
      list-style-type: none;
      text-decoration: none;
      display: inline-block;
    }
    
    ul li {
      text-align: right;
    }
    
    .center {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 0;
        position: relative;
        right: 0;
    }
    <footer class="content-container footer">
    
      <div class="footer-text">Let's <br> <span class="footer-text-color">Connect</span></div>
      
      <ul class="center">
    
        <li><a href=a.html class="footer-contact">Email</a></li>
        <li><a href=b.html class="footer-contact">LinkedIn</a></li>
        <li><a href=c.html class="footer-contact">GitHub</a></li>
      </ul>
    
    </footer>

    【讨论】:

    • 我希望电子邮件、LinkedIn 和 GitHub 更靠右。我试过在ui上浮动,它可以工作,但它与标题不在同一行。
    • @user8 你的意思更正确,它从原始帖子向左移动。还有多少?
    • @user8 删除父级的边距,并在 flex 上使用 space-between。查看更改。
    • @user8 如果我仍然不理解您的意思,请提供标记图像。
    • 一切都好,终于让它工作了。感谢您的帮助:)。
    【解决方案2】:

    只需将footer-contact 中的margin-right: 0; 替换为margin-right: 60px;,并在CSS 下方添加即可。

    ul li {
      text-align: right;
    }
    

    我还会更新您的代码 sn-p,它会帮助您。谢谢你

    .footer {
      display: flex;
      align-items: center;
      justify-content: space-between;
      grid-area: footer;
      margin-top: 38px;
      margin-left: 10%;
      margin-right: 10%;
      height: 700px;
      margin-bottom: 100px;
    }
    
    .footer-text {
      padding: 200px 100px;
      font-family: "Khula", sans-serif;
      font-weight: 600;
      font-size: 80px;
      color: #bbbbbb;
      line-height: 80px;
      letter-spacing: -1px;
      display: inline-block;
    }
    
    .footer-contact {
      font-family: "Khula", sans-serif;
      font-weight: 600;
      font-size: 35px;
      color: #222222;
      line-height: 50px;
      letter-spacing: -1px;
      text-decoration: none;
      padding-top: 0px;
      margin-left: 60px;
      margin-right: 0;
    }
    
    .footer-text-color {
      color: #222222;
    }
    
    ul {
      list-style-type: none;
      text-decoration: none;
      display: inline-block;
    }
    
    ul li {
      text-align: right;
    }
    <footer class="content-container footer">
    
      <div class="footer-text">Let's <br> <span class="footer-text-color">Connect</span></div>
    
      <ul>
    
        <li><a href=a.html class="footer-contact">Email</a></li>
        <li><a href=b.html class="footer-contact">LinkedIn</a></li>
        <li><a href=c.html class="footer-contact">GitHub</a></li>
      </ul>
    
    </footer>

    【讨论】:

    • 我想将电子邮件、LinkedIn 和 GitHub 向右移动。
    • @user8 为了实现你的目标,我们必须使用 flex CSS,我还更新了代码 sn-p。我还建议您避免浮动并使用 flex CSS。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    相关资源
    最近更新 更多