Jay*_*713 5 html css jsx flexbox
我完全按照我想要的方式进行了定位,但是围绕 58 的圆圈应该是一个完美的圆圈,而是根据容器中的内容进行调整。我该如何解决这个问题?
这是它的样子https://i.stack.imgur.com/Tb75A.png 这是我需要它看起来像https://i.stack.imgur.com/LgQFI.png
这是 JSX
<div className="second-col-container">
<h2>Air Quality Index</h2>
<div className="mod-container">
<span className="index">58</span>
<div className="para-mod">
<span className="mod">Moderate</span>
<div>
Air quality is acceptable; however, for some pollutants there
may be a moderate health concern for a very small number of
people who are unusually sensitive to air pollution.
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.second-col-container {
background-color: white;
width: 250px;
grid-area: air-index;
margin-top: 20px;
border-radius: 10px;
}
.second-col-container h2 {
margin-bottom: 20px;
margin-left: 10px;
}
.para-mod {
font-size: small;
width: 60%;
color: grey;
display: flex;
flex-direction: column;
margin-left: 10px;
}
.index {
margin: 5px 0 0 5px;
color: black;
font-size: xx-large;
border: 3px solid rgb(223, 217, 217);
border-left-color: rgb(255, 170, 11);
border-bottom-color: rgb(255, 170, 11);
padding: 15px;
border-radius: 100%;
}
.mod-container {
display: flex;
}
.mod {
font-size: large;
color: black;
}
Run Code Online (Sandbox Code Playgroud)
我首先给圆一个固定的height和width。然后给它一个border-radius of 50%. 这样就解决了第一个问题(使其成为一个完美的圆)。
第二个问题是文本居中。给跨度display: flex然后使用 align-items: center;, justify-content: center;你就可以开始了。
.index {
margin: 5px 0 0 5px;
color: black;
height: 50px;
width: 50px;
position: relative;
align-items: center;
justify-content: center;
display: flex;
font-size: xx-large;
border: 3px solid rgb(223, 217, 217);
border-left-color: rgb(255, 170, 11);
border-bottom-color: rgb(255, 170, 11);
/* padding: 15px; */
border-radius: 50%;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
274 次 |
| 最近记录: |