【发布时间】:2016-09-16 03:35:23
【问题描述】:
这是我迄今为止尝试过的:
html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
html {
position: absolute;
}
body {
position: relative;
}
.wrapper {
display: table;
}
.circle {
position: absolute;
top: 25%;
left: 25%;
border-radius: 50%;
width: 50%;
height: auto;
padding-top: 50%;
background-color: #403C36;
box-shadow: 1px 0.2px 25px 1px rgba(0, 0, 0, 0.25);
}
.content {
display: table-cell;
vertical-align: middle;
position: absolute;
top: 25%;
left: 25%;
width: 50%;
height: auto;
text-align: center;
}
<div class="wrapper">
<div class="circle"></div>
<div class="content">I want this to be centered vertically in the circle</div>
</div>
我无法将文本放入圆圈中,因为圆圈的padding-top 将其纵横比保持在 1:1。但是,如果有办法解决这个问题,我会接受的。
更新
这不能通过假设圆圈或内容的宽度和高度来解决,因为它是动态的,基于窗口的大小和用户提供的内容。可能是一两段文字。
【问题讨论】:
-
不,这是不同的,因为圆圈的宽度和高度是未知的。
标签: html css geometry aspect-ratio