【发布时间】:2020-02-11 23:23:14
【问题描述】:
我很难对齐文本,我希望 div 左侧的文本和右侧的图像也从顶部居中相等。我试过 justify-content 和 text-align 但他们没有给出我需要的结果,我也在使用 css 网格。
这里是有问题的代码
/*this is just the css grid stuff*/
.contain{
display: grid;
grid-template-columns: repeat(9, minmax(120px, 1fr)) ;
text-align: center;
justify-content: center;
grid-template-rows: minmax(50px , auto);
grid-template-areas:
"s content2 content2 content2 content2 content2 content2 content2 empty2";
}
/* Here is the code */
.contentc{
background-color: white;
border-radius: 20px;
padding: 40px;
width: 100%;
grid-area: content2;
}
.text3{
margin:auto;
color: black;
}
.para3{
color: black;
margin: auto;
}
<div class="contain">
<div class= "contentc">
<img class="img-3" src="Use Any Image" >
<h2 class="text3">Twitter Clone </h2>
<p class="para3">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ratione itaque cupiditate porro ipsam quod, fugit reprehenderit autem architecto aliquam harum.</p>
</div>
</div>
【问题讨论】:
-
你的意思是这样的? jsfiddle.net/rb8skjep/2
-
是的,你非常接近,唯一的事情是我希望文本中途/降低到图像的一半。我可以使用 margin-top: 50% 但我想要一种响应方式。
-
在两者上都使用 position:absolute 样式,而不是使用 left:0 作为文本,使用 right:0 作为 img
-
wow prottay thx man 这正是我正在寻找的东西,不敢相信它这么容易