HTML/CSS 中的文本未正确对齐

Text Is Not Aligning Properly In HTML/CSS

你好,我想在我的网站中包含一个博客 post 卡片,我希望文本相互重叠,但即使在我设置 text:align: justify; 之后它仍然不起作用。为什么?

我的HTML/CSS的卡:

@import url('https://fonts.googleapis.com/css?family=Merriweather|Open+Sans');

.container1{
  display: flex;
  justify-content: center;
  padding: 80px;
}

.square:hover {
    -webkit-transform: translate(20px, -10px);
    -ms-transform: translate(10px, -10px);
    transform: translate(10px, -10px);
    -webkit-box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
     }


.square{
  width: 460px;
    height: 430px;
    background: white;
  border-radius: 4px;
  box-shadow: 0px 20px 50px #D9DBDF;
  -webkit-transition: all 0.3s ease;
  -o-transition: all 0.3s ease;
  transition: all 0.3s ease; 
}

.mask{
  clip: rect(0px, 460px, 220px, 0px);
  border-radius: 4px;
  position: absolute;
}

img1{
  width: 460px;
  }

.h11{
  margin: auto;
  text-align: left;
  margin-top: 240px;
  padding-left: 30px;
  
  font-family: 'Merriweather', serif;
  font-size: 24px;
}
p9{
 text-align: justify; 
 font-family: 'Open Sans', sans-serif;
 font-size: 12px;
 color: #C8C8C8;
 line-height: 18px;
}

.button56 {
    background-color: #3EDD84;
    color: white;
    width: 100px;
    padding: 10px 18px;
    border-radius: 3px;
    text-align: center;
    text-decoration: none;
    display: block;
    margin-top: 15px;
    margin-left: 30px;
    margin-right: 70px;
    font-size: 12px;
    cursor: pointer;
    font-family: 'merriweather';
 <section>
         <link rel="stylesheet" href="assets/css/blog.css">  
    <div class="container1">
      <div class="square">
        <img src="https://images.unsplash.com/photo-1504610926078-a1611febcad3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e1c8fe0c9197d66232511525bfd1cc82&auto=format&fit=crop&w=1100&q=80" class="mask">
     <div class="h11">“Chances Of My Uni/College Admission?”</div>
        <p9>It is that time of the year again (yay!) where we — high school students — are supposed to fill out the applications and land in our dream Universities/Colleges!</p9>
        
     <div><a href="https://medium.com/@laheshk/is-apple-a-design-company-f5c83514e261" target="_" class="button56">Read More</a></div>
      </div>
      
      
      
      </div>
      
</section>

忽略上面输出中的图像,但如您所见,我的文本格式不正确,我尽我所能使它工作,但我做不到。


预期输出:

@import url('https://fonts.googleapis.com/css?family=Merriweather|Open+Sans');

.container{
  display: flex;
  justify-content: center;
  padding: 80px;
}

.square:hover {
    -webkit-transform: translate(20px, -10px);
    -ms-transform: translate(10px, -10px);
    transform: translate(10px, -10px);
    -webkit-box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
     }


.square{
  width: 460px;
    height: 430px;
    background: white;
  border-radius: 4px;
  box-shadow: 0px 20px 50px #D9DBDF;
  -webkit-transition: all 0.3s ease;
  -o-transition: all 0.3s ease;
  transition: all 0.3s ease; 
}

.mask{
  clip: rect(0px, 460px, 220px, 0px);
  border-radius: 4px;
  position: absolute;
}

img{
  width: 460px;
  }

.h1{
  margin: auto;
  text-align: left;
  margin-top: 240px;
  padding-left: 30px;
  
  font-family: 'Merriweather', serif;
  font-size: 24px;
}
p{
 text-align: justify; 
 padding-left: 30px;
 padding-right: 30px;
 font-family: 'Open Sans', sans-serif;
 font-size: 12px;
 color: #C8C8C8;
 line-height: 18px;
}

.button {
    background-color: #3EDD84;
    color: white;
    width: 90px;
    padding: 10px 18px;
    border-radius: 3px;
    text-align: center;
    text-decoration: none;
    display: block;
    margin-top: 20px;
    margin-left: 30px;
    margin-right: 70px;
    font-size: 12px;
    cursor: pointer;
    font-family: 'merriweather';
<html>
  <head>
    <title>Blog card</title>
  </head>
  
  <body>
    <div class="container">
      <div class="square">
        <img src="https://images.unsplash.com/photo-1504610926078-a1611febcad3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e1c8fe0c9197d66232511525bfd1cc82&auto=format&fit=crop&w=1100&q=80" class="mask">
     <div class="h1">Is Apple a Design Company?</div>
        <p>Apple is more than a tech company; it became a culture unto itself, a passion of most of people and the birthplace of the world’s most revolutionized products.</p>
        
     <div><a href="https://medium.com/@laheshk/is-apple-a-design-company-f5c83514e261" target="_" class="button">Read More</a></div>
      </div>
      
      
      
      </div>
      
        
      
     

再次忽略上述输出中的图像,但我希望我的文本具有这样的格式。我该怎么做?

看我的朋友,给你的 p 而不是 p9 class 或者直接使用预期输出上的样式来制作你的样式 p。

p{
 text-align: justify; 
 padding-left: 30px;
 padding-right: 30px;
 font-family: 'Open Sans', sans-serif;
 font-size: 12px;
 color: #C8C8C8;
 line-height: 18px;

}

就这些了

不要忘记将 <p9> 更改为 <p>

.p9 class 中添加左右 padding 30px 并对其应用 display: block 以获得与 [=28= 中相同的填充] 它上面。 (顺便说一句:您还应该将 padding: right 应用于 .h11 class,否则如果文本内容 font-size 或容器宽度发生变化,您的文本可能会向右移动很远。

@import url('https://fonts.googleapis.com/css?family=Merriweather|Open+Sans');
.container1 {
  display: flex;
  justify-content: center;
  padding: 80px;
}

.square:hover {
  -webkit-transform: translate(20px, -10px);
  -ms-transform: translate(10px, -10px);
  transform: translate(10px, -10px);
  -webkit-box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
}

.square {
  width: 460px;
  height: 430px;
  background: white;
  border-radius: 4px;
  box-shadow: 0px 20px 50px #D9DBDF;
  -webkit-transition: all 0.3s ease;
  -o-transition: all 0.3s ease;
  transition: all 0.3s ease;
}

.mask {
  clip: rect(0px, 460px, 220px, 0px);
  border-radius: 4px;
  position: absolute;
}

img1 {
  width: 460px;
}

.h11 {
  margin: auto;
  text-align: left;
  margin-top: 240px;
  padding-left: 30px;
  font-family: 'Merriweather', serif;
  font-size: 24px;
}

p9 {
  text-align: justify;
  font-family: 'Open Sans', sans-serif;
  font-size: 12px;
  color: #C8C8C8;
  line-height: 18px;
  padding-left: 30px;
  padding-right: 30px;
  display: block;
}

.button56 {
  background-color: #3EDD84;
  color: white;
  width: 100px;
  padding: 10px 18px;
  border-radius: 3px;
  text-align: center;
  text-decoration: none;
  display: block;
  margin-top: 15px;
  margin-left: 30px;
  margin-right: 70px;
  font-size: 12px;
  cursor: pointer;
  font-family: 'merriweather';
}
<section>
  <link rel="stylesheet" href="assets/css/blog.css">
  <div class="container1">
    <div class="square">
      <img src="https://images.unsplash.com/photo-1504610926078-a1611febcad3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=e1c8fe0c9197d66232511525bfd1cc82&auto=format&fit=crop&w=1100&q=80" class="mask">
      <div class="h11">“Chances Of My Uni/College Admission?”</div>
      <p9>It is that time of the year again (yay!) where we — high school students — are supposed to fill out the applications and land in our dream Universities/Colleges!</p9>

      <div><a href="https://medium.com/@laheshk/is-apple-a-design-company-f5c83514e261" target="_" class="button56">Read More</a></div>
    </div>



  </div>

</section>