[英]centering div inside figure tag
why does flex solutions to center my ".time" div doesn't work? 为什么将居中“ .time” div居中的弹性解决方案不起作用? I've tried putting display:flex and justify, align content. 我试过把display:flex和证明,对齐内容。 I've tried also to display it as a block, and putting margin:0, etc. Still can't figure out how to center it (instead of top:xx%, left:xx%) 我也尝试过将其显示为一个块,并放置margin:0,依此类推。仍然不知道如何居中(而不是top:xx%,left:xx%)
<div class="container">
<h3>Pomodoro timer</h3>
<figure>
<img src="svg/food.svg" class="tomato">
<div class="inline time">
<div id="min">11</div>
<div id="sec">11</div>
</div>
</figure>
<div id="start">st</div>
<div id="break"></div>
</div>
CSS: CSS:
$responsive-text: calc(20px + 3vw);
.container {
margin: 0 auto;
display:flex;
flex-direction: column;
align-items:center;
width:95vw;
max-width:450px;
height:95vh;
border:1px solid black;
position: relative;
}
.tomato {
margin-top:-30px;
width:70vw;
max-width: 350px;
max-height:80%;
}
h3 {
margin-top:0;
font-size:$responsive-text;
}
.inline {
display:inline-flex;
justify-content: center;
}
.time {
font-size: $responsive-text;
top:37.5%;
width:35%;
margin:auto;
text-align:center;
position:absolute;
border: 1px solid rgb(51, 28, 28);
left:31%;
}
figure {
display:block;
position:relative;
margin: 0 auto;
}
jsfiddle: https://jsfiddle.net/fakbj3v4/ jsfiddle: https ://jsfiddle.net/fakbj3v4/
You need to put the flexbox inside the figure element in CSS. 您需要将Flexbox放在CSS的Figure元素内。 Therefore every child in the figure element is centered which is what I assume you want 因此,Figure元素中的每个孩子都居中,这是我假设您想要的
figure {
display: flex;
justify-content: center;
align-items: center;
}
When you put this code on an element, these properties are applied to its children 当您将此代码放在元素上时,这些属性将应用于其子元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.