【问题标题】:css justifying alignment of text in a 3 column layout does not workcss 在 3 列布局中对齐文本的对齐方式不起作用
【发布时间】:2022-01-22 03:55:44
【问题描述】:

我在尝试证明每一列的文本的合理性时遇到了问题,以便它们更加分开并且更好看。喜欢这个:

我进行了很多搜索并提出了很多建议(vertical aligncolumn-gap 在这些建议中),但它们似乎不适用于我的情况。此外,即使我添加了我认为必要的属性,它似乎也没有响应。

如何让列从图像的开头开始并摆脱开头的空白?

 
/*
=============== 
Policy section
===============
*/

 .Policy {
  background-color: rgb(94, 94, 94);
  background-image: url(https://fit4food2030.eu/wp-content/uploads/2018/02/policy-800x533.jpg);
  background-repeat: no-repeat;
  background-blend-mode: multiply;
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
  color: white;
  text-align: center;
  padding: 50vh 1em;
  }

  .policy-row {
    word-wrap: break-word;
  }

  .policy-row:after {
    content: "";
    display: table;
    clear: both;
  }
  
  .policy-column{
    display: grid;
    column-gap: 10px;
    float: right;
    width: 33.3%;
    vertical-align: top;
    }

  .policy p {
    max-width: 20%;
    margin: 10px;
    text-align: justify;
  }

.policy h2{
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 20%;
    margin: 10px;
    word-wrap: break-word;
    text-align: justify;
  }
  
  .policy-seperator{
    background-color: #acb930;
    margin: 5px 50px;
    padding: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  @media screen and (max-width: 980px) {
    .policy-column {
      width: 100%;
      align-items: center;
      justify-content: center;
      text-align: justify;
    }
    .policy p, .policy h2 {
      font-size: 7rem;
      display: flex;
      align-items: center;
     justify-content: center;
     max-width: 25%;
    }
  }
<section class="Policy">
    <div class="policy-row">
      <div class="policy-column" >
        <h2>overview</h2>
        <div class="policy-seperator"></div>
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
      </div>
      <div class="policy-column" >
        <h2>goals</h2>
        <div class="policy-seperator"></div>
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. </p>
      </div>
      <div class="policy-column" >
        <h2>mission</h2>
        <div class="policy-seperator"></div>
        <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). </p>
      </div>
    </div>
  </section>

【问题讨论】:

    标签: html css alignment justify


    【解决方案1】:

    我对您的代码做了一些更改,但我认为这是您想要的结果。

    我建议你检查一下以更好地了解“display: flex”和 flexbox 的所有属性如何工作。

    希望这有帮助:)

    body {
      margin: 0;
    }
    
    .Policy {
      background-color: rgb(94, 94, 94);
      background-image: url(https://fit4food2030.eu/wp-content/uploads/2018/02/policy-800x533.jpg);
      background-repeat: no-repeat;
      background-blend-mode: multiply;
      background-attachment: fixed;
      background-position: center;
      background-size: cover;
      color: white;
      text-align: left;
      padding: 0 1em;
      min-height: 100vh;
    }
    
    .policy-row {
      word-wrap: break-word;
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 15px;
    }
    
    .policy-column p {
      text-align: justify;
    }
    
    .policy-seperator {
      background-color: #acb930;
      margin: 5px 0 px;
      padding: 1px;
    }
    
    @media screen and (max-width: 980px) {
      .policy-row {
        flex-direction: column;
      }
      .policy p,
      .policy h2 {
        font-size: 7rem;
        display: flex;
        align-items: center;
        justify-content: center;
        max-width: 25%;
      }
    }
    <section class="Policy">
      <div class="policy-row">
        <div class="policy-column">
          <h2>overview</h2>
          <div class="policy-seperator"></div>
          <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
            It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
            desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
        </div>
        <div class="policy-column">
          <h2>goals</h2>
          <div class="policy-seperator"></div>
          <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked
            up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
            Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a
            line in section 1.10.32. </p>
        </div>
        <div class="policy-column">
          <h2>mission</h2>
          <div class="policy-seperator"></div>
          <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
            here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy.
            Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). </p>
        </div>
      </div>
    </section>

    【讨论】:

    • 感谢您的回答。在您的版本中,只有文本的左侧是合理的,但我希望它们在两边都是合理的。如何做到这一点?
    • 你只需添加text-align: justify
    猜你喜欢
    • 2012-09-12
    • 1970-01-01
    • 2015-04-08
    • 2012-06-11
    • 2014-12-10
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    相关资源
    最近更新 更多