gpt4 book ai didi

html - 在带边框的 div 内对齐文本

转载 作者:行者123 更新时间:2023-11-28 01:06:35 24 4
gpt4 key购买 nike

我正在尝试在圆形 div(具有边框半径)内垂直和水平对齐文本。我尝试了 position:absoluterelative

这样的标签

我尝试添加这个:

text-align: center;
display: inline-block;
overflow: hidden;

在我的 CSS 中,但我没有成功。

下面是片段。我想知道在不添加其他 div 的情况下最佳解决方案是什么。提前致谢。

.card-container2 {
cursor: pointer;
height: auto;
perspective: 600;
position: relative;
width: auto;
margin:auto;
align-contents:center;
}

.card-container {

cursor: pointer;
height: 350px;
perspective: 600;
position: relative;
width: 350px;
border-radius: 50%;
display:block;
margin-left:auto;
margin-right:auto;

}
.card {
height: 100%;
position: absolute;
transition: all 1s ease-in-out;
transform-style: preserve-3d;
width: 100%;
border-radius: 50%;

-moz-animation-name: dropCard;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: ease-in;
-moz-animation-duration: 0.3s;

-webkit-animation-name: dropCard;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-in;
-webkit-animation-duration:0.3s;

animation-name: dropCard;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 0.3s;

}
.card:hover {
transform: rotateY(180deg);
}
.card .side {
backface-visibility: hidden;
border-radius: 6px;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
background:#000;
border-radius: 50%;
}

.card .back {
background: #F1F1F1;
color: #000;
line-height: 24px;
font-weight: bold;
text-align: center;
border-radius: 50%;
transform: rotateY(180deg);
}


@-moz-keyframes dropCard {
0% {
-moz-transform: translateY(-100px);
}

100% {
-moz-transform: translateY(0);
}
}
@-webkit-keyframes dropCard {
0% {
-webkit-transform: translateY(-100px);
}
100% {
-webkit-transform: translateY(0);
}
}

@keyframes dropCard {
0% {
transform: translateY(-100px);
}
100% {
transform: translateY(0);
}
}

IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto }
<p style="text-align: center;">&nbsp;</p>
<div class="card-container2">
<div class="card-container">
<div class="card">
<div class="side" style="text-align: center;"><img class="displayed" src="IMAGE" alt="" width="350" height="350" /></div>
<div class="side back">
<p><span style="font-size: 14pt; font-family: arial, helvetica, sans-serif; color: #000;">Campaign Name: 11111111&nbsp;</span></p>
<p><span style="color: #000; font-size: 14pt;"><span style="font-family: arial, helvetica, sans-serif;">Campaign Dates:&nbsp;</span><span style="font-family: arial, helvetica, sans-serif;">333333333333333 -&nbsp;22222222222&nbsp;</span></span></p>
<p><span style="color: #000; font-size: 14pt;">&nbsp;</span></p>
<p><span style="color: #000; font-size: 14pt;">Length of campaign:4444444444444&nbsp;</span></p>
<p><span style="color: #000; font-size: 14pt;">Days left of campaign:&nbsp;55555555555555555}&nbsp;</span></p>
</div>
</div>
</div>
</div>

最佳答案

您的计划是在 backside rounded div .back .side 内对齐文本吗?正确居中,然后从 <p> tag 中删除边距并添加 padding-top.back

.card .back {
background: #F1F1F1;
color: #000;
line-height: 24px;
font-weight: bold;
text-align: center;
border-radius: 50%;
transform: rotateY(180deg);
padding-top:75px;
box-sizing:border-box;
}
p{
margin:5px 0px;
text-align:center;
}

.card-container2 {
cursor: pointer;
height: auto;
perspective: 600;
position: relative;
width: auto;
margin:auto;
align-contents:center;
}

.card-container {

cursor: pointer;
height: 350px;
perspective: 600;
position: relative;
width: 350px;
border-radius: 50%;
display:block;
margin-left:auto;
margin-right:auto;

}
.card {
height: 100%;
position: absolute;
transition: all 1s ease-in-out;
transform-style: preserve-3d;
width: 100%;
border-radius: 50%;

-moz-animation-name: dropCard;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: ease-in;
-moz-animation-duration: 0.3s;

-webkit-animation-name: dropCard;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-in;
-webkit-animation-duration:0.3s;

animation-name: dropCard;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 0.3s;

}
.card:hover {
transform: rotateY(180deg);
}
.card .side {
backface-visibility: hidden;
border-radius: 6px;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
background:#000;
border-radius: 50%;
}

.card .back {
background: #F1F1F1;
color: #000;
line-height: 24px;
font-weight: bold;
text-align: center;
border-radius: 50%;
transform: rotateY(180deg);
padding-top:75px;
box-sizing:border-box;
}
p{
margin:5px 0px;
text-align:center;
}


@-moz-keyframes dropCard {
0% {
-moz-transform: translateY(-100px);
}

100% {
-moz-transform: translateY(0);
}
}
@-webkit-keyframes dropCard {
0% {
-webkit-transform: translateY(-100px);
}
100% {
-webkit-transform: translateY(0);
}
}

@keyframes dropCard {
0% {
transform: translateY(-100px);
}
100% {
transform: translateY(0);
}
}

IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto }
<p style="text-align: center;">&nbsp;</p>
<div class="card-container2">
<div class="card-container">
<div class="card">
<div class="side" style="text-align: center;"><img class="displayed" src="IMAGE" alt="" width="350" height="350" /></div>
<div class="side back">
<p><span style="font-size: 14pt; font-family: arial, helvetica, sans-serif; color: #000;">Campaign Name: 11111111&nbsp;</span></p>
<p><span style="color: #000; font-size: 14pt;"><span style="font-family: arial, helvetica, sans-serif;">Campaign Dates:&nbsp;</span><span style="font-family: arial, helvetica, sans-serif;">333333333333333 -&nbsp;22222222222&nbsp;</span></span></p>
<p><span style="color: #000; font-size: 14pt;">&nbsp;</span></p>
<p><span style="color: #000; font-size: 14pt;">Length of campaign:4444444444444&nbsp;</span></p>
<p><span style="color: #000; font-size: 14pt;">Days left of campaign:&nbsp;55555555555555555}&nbsp;</span></p>
</div>
</div>
</div>
</div>

关于html - 在带边框的 div 内对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39493376/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com