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



你好,我想在我的网站中包含一张博客帖子卡,我希望文本在彼此下方,但即使设置了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>



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

.p9类中添加一个左右30px的padding,并在其上应用display: block,使其具有与上面的页眉相同的填充。(BTW:您还应该将padding: right应用于.h11类,否则如果文本内容、字体大小或容器宽度发生变化,您的文本可能会向右移动。

@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>

看,我的朋友,给你的p而不是p9类,或者让你的样式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>

最新更新