html - 如何让文字两边对齐

标签 html css

我有以下主要 html 页面,我正在尝试进行文本对齐:justfiy; justify:词间;但它似乎不起作用。这是否意味着在文本的两边加线以使其看起来像一个 block ?我不确定我是否解释得足够好,但希望你们明白我在追求什么:

div.service1 p {
  font-size: 20px;
  color: #000000;
  max-width: 250px;
  text-align: justify;
  text-justify: inter-word;
  margin-left: 20px;
  margin-top: 20px;
}
<div class="main-wrapper">
  <div class="first">
    <h2>At PianoCourse101, your child can now learn how to play Classical music right from the comfort of your own home! It doesn't matter if your child has no music foundation because there are lessons suitable for beginners and advanced students! Based
      on the "Bastien Piano Basics series", your child will be able to learn the basic hand positions, posture, finger numbers and letter names!<br>There are four levels in the "Bastien Piano Basics" series, beginning with the primer level, which is suitable
      for beginners. Once your child has completed the primer level, your child will be able to progress to Level 1, follow by Level 2 and Level 3.<br>Currently, PianoCourse101 lessons are mainly for children but we also encourage if you are an adult
      and also wish to learn how to play the piano to join us! In due course, there will also be lessons for adults!</h2>
  </div>
</div>

<div class="form">
  <form class="signup-form" action="newsletters.php" method="POST">
    <div class="newsletters">
      <label>Enter your E-mail Address</label>
    </div>
    <br>
    <div class="index_form">
      <input type="text" name='email' placeholder="Enter E-mail Address">
    </div>
    <br>
    <button type="submit" name="submit">Subscribe to PianoCourse101!</button>
    <br>

  </form>
</div>

<img class="snoopy" src="includes/pictures/snoopy.jpg" alt="snoopy playing the piano" />

<div class="services_heading">Services</div>
<div class="services">
  <div class="service1">
    <h1>Level 1</h1>
    <div class="image">
      <a href="signup.php">
        <p id="piano">&#127929;</p>
      </a>
    </div>
    <p>Purchase the Level 1 Subscriptionplan!<br>Learn how to play the piano right from the comfort of your own home!<br>Monthly fee: $100<br>Yearly fee: $800</p>
  </div>

  <div class="service1">
    <h1>Level 2</h1>
    <div class="image">
      <a href="signup.php">
        <p id="violin">&#127931;</p>
      </a>
    </div>
    <p>Purchase the Level 2 Subscriptionplan!<br>Learn how to play the piano right from the comfort of your own home!<br>Monthly fee: $150<br>Yearly fee: $1300</p>

  </div>
  <div class="service1">
    <h1>Level 3</h1>
    <div class="image">
      <a href="signup.php">
        <p id="sax">&#127927;</p>
      </a>
    </div>
    <p>Purchase the Level 3 Subscriptionplan!<br>Learn how to play the piano right from the comfort of your own home!<br>Monthly fee: $200<br>Yearly fee: $1800</p>
  </div>
</div>

我尝试使用词间,但它只在左侧排列...

最佳答案

从你的问题中,很难看出你到底想要什么。

如果您希望价格与右边缘对齐,您应该对部分布局使用 flexbox

如果您想在使用 text-align: justify 时将文本对齐对齐,您需要使用以下 CSS 启用连字符属性:

-webkit-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;

.main-wrapper {
  text-align: justify;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
}

div.service1 p,
dl {
  width: 250px;
  margin-top: 20px;
  margin-left: 20px
}

dl,
dl div {
  display: flex
}

dl {
  flex-direction: column
}

dl div {
  justify-content: space-between
}
<div class="main-wrapper">
  <div class="first">
    <h2>At PianoCourse101, your child can now learn how to play Classical music right from the comfort of your own home! It doesn't matter if your child has no music foundation because there are lessons suitable for beginners and advanced students! Based
      on the "Bastien Piano Basics series", your child will be able to learn the basic hand positions, posture, finger numbers and letter names!<br>There are four levels in the "Bastien Piano Basics" series, beginning with the primer level, which is suitable
      for beginners. Once your child has completed the primer level, your child will be able to progress to Level 1, follow by Level 2 and Level 3.<br>Currently, PianoCourse101 lessons are mainly for children but we also encourage if you are an adult
      and also wish to learn how to play the piano to join us! In due course, there will also be lessons for adults!</h2>
  </div>
</div>

<div class=service1>
  <h1>Level 1</h1>
  <div class=image>
    <a href=signup.php>
      <h2 id=piano>🎹</h2>
    </a>
  </div>
  <p>Purchase the Level 1 Subscription plan!<br><br> Learn how to play the piano right from the comfort of your own home!
    <dl>
      <div>
        <dt>Monthly fee:
      <dd>$100
    </div>
    <div>
      <dt>Yearly fee:
      <dd>$800
    </div>
  </dl>
</div>
  
<div class=service1>
  <h1>Level 2</h1>
  <div class=image>
    <a href=signup.php>
      <h2 id=violin>🎻</h2>
    </a>
  </div>
  <p>Purchase the Level 2 Subscription plan!<br><br>
    Learn how to play the piano right from the comfort of your own home!
  <dl>
    <div>
      <dt>Monthly fee:
      <dd>$150
    </div>
    <div>
      <dt>Yearly fee:
      <dd>$1300
    </div>
  </dl>
</div>
    
<div class=service1>
  <h1>Level 3</h1>
  <div class=image>
    <a href=signup.php>
      <h2 id=sax>🎷</h2>
    </a>
  </div>
  <p>Purchase the Level 3 Subscription plan!<br><br>
    Learn how to play the piano right from the comfort of your own home!
  <dl>
    <div>
      <dt>Monthly fee:
      <dd>$200
    </div>
    <div>
      <dt>Yearly fee:
      <dd>$1800
    </div>
  </dl>
</div>

关于html - 如何让文字两边对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52015695/

相关文章:

php - 我试图从 mysql 数据库中检索数据到 html 表中

javascript - 在另一个元素中找到一个 html,然后用 Javascript 单击它

html - header 内的 header ? (HTML5)

javascript - 无法在 JQuery 中选择元素并执行简单事件

html - 即使在元标记中声明 UTF-8 后,在使用 marathi 时显示空白框而不是空格

javascript - DataTables 可滚动表而不是折叠

javascript - 无论如何要掩盖输入字段?

html - 通过缩小内容来防止溢出

html - 无法使用填充 css 向上推图像

javascript - 谷歌美化 : Line numbers won't show