#html #css #flexbox #jsx
#HTML #css #flexbox #jsx
Вопрос:
У меня есть позиционирование именно так, как я хочу, но круг вокруг 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>
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;
}
Комментарии:
1. Неважно. Я не видел JSX. Мой плохой. Снова проголосовал за это. 🙂
2. @BobRodes Они разместили разметку как JSX. Синтаксис класса — camelCase.
Ответ №1:
Я бы начал с присвоения кругу фиксированного height
и width
. Затем дайте ему border-radius of 50%
. и это решило бы первую проблему (превратить его в идеальный круг).
Вторая проблема центрирования текста. Укажите диапазон a, 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%;
}
Ответ №2:
При display: flex
применении только к родительскому div .mod-container.
ваш <span class="index">
элемент, содержащий 2-значный номер, увеличивается, чтобы заполнить содержимое его родительского контейнера.
Затем я отцентрировал .mod-container
содержимое flexbox с помощью justify-content: center
и выровнял с помощью align-items: flex-start
. Кажется, это соответствует вашему желаемому изображению. (Я могу обновить синтаксис класса до JSX, если вам нужно)
.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;
color: grey;
display: flex;
flex-direction: column;
margin-left: 10px;
}
.index {
margin: 5px 0 0 5px;
color: black;
font-size: xx-large;
border-radius: 50%;
border: 3px solid rgb(223, 217, 217);
border-left-color: rgb(255, 170, 11);
border-bottom-color: rgb(255, 170, 11);
padding: 15px;
}
.mod-container {
display: flex;
justify-content: center;
align-items: flex-start;
}
<div class="second-col-container">
<h2>Air Quality Index</h2>
<div class="mod-container">
<span class="index">58</span>
<div class="para-mod">
<span class="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>