В течение нескольких дней я пытался найти способ, чтобы заголовки и тексты отдельных карт масонства занимали определенные позиции, не затрагивая другие карты. Тем временем у меня почти было решение, но оно разрушило представление на других устройствах. Довольно неприятно, хотя решение, безусловно, очень простое.
Я хочу, чтобы текст зеленых карт находился в том же месте, что и текст других карт.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-self: center;
min-height: 100vh;
}
.container {
position: relative;
max-width: 100%;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-template-rows: minmax(100px, auto);
margin: 40px;
grid-auto-flow: dense;
grid-gap: 35px;
}
.container .box {
background: #333;
padding: 90px;
display: grid;
place-items: center;
text-align: left;
color: #000;
transition: 0.5s;
border-radius: 10px;
background: radial-gradient(#f9d423, #f83600);
font-family: "bergen mono";
font-size: 2.1vh;
display: flex;
flex-direction: column;
}
h6 {
color: #000;
font-weight: 200;
font-size: 30px;
letter-spacing: 1px;
font-family: "bergen mono";
}
.container .box:hover {
transition: all 0.3s ease;
transform: scale(1.05, 1.05);
}
.container .box img {
position: relative;
max-width: 100px;
margin-bottom: 10px;
}
.container .box:nth-child(1) {
grid-column: span 2;
grid-row: span 1;
background: radial-gradient(#2bffc3, #72afd3);
padding-top: 3vh
}
.container .box:nth-child(2) {
grid-column: span 1;
grid-row: span 2;
background: radial-gradient(#c4ff29, #89d294);
}
.container .box:nth-child(4) {
grid-column: span 1;
grid-row: span 2;
background: radial-gradient(#c4ff29, #89d294);
}
.container .box:nth-child(5) {
grid-column: span 3;
grid-row: span 1;
background: radial-gradient(#2bffc3, #72afd3);
}
@media (max-width: 960px) {
.container {
grid-template-columns: repeat(auto-fill, minmax(50%, 1fr));
grid-template-rows: minmax(auto, auto);
}
.container .box {
grid-column: unset !important;
grid-row: unset !important;
}
}
@media (max-width: 600px) {
.container {
grid-template-columns: repeat(auto-fill, minmax(50%, 1fr));
grid-template-rows: minmax(auto, auto);
}
.container .box {
grid-column: unset !important;
grid-row: unset !important;
}
}
<div class = "container">
<div class = "box">
<div class = "content">
<img src = "https://image.flaticon.com/icons/svg/2377/2377010.svg" alt = "">
<h6 >Überschrift</h6>
<p>Wash hands with soap and water after touching animals and animal products.</p>
</div>
</div>
<div class = "box">
<div class = "content">
<h6 >Überschrift</h6>
<p>When coughing and sneezing cover mouth and nose with flexed elbow or tissue.</p>
</div>
</div>
<div class = "box">
<div class = "content">
<h6 >Überschrift</h6>
<p>Avoid travelling if you have a fever or cough.</p>
</div>
</div>
<div class = "box">
<div class = "content">
<h6 >Überschrift</h6>
<p>If you have a fever, cough and difficulty breathing, seek medical care early.</p>
</div>
</div>
<div class = "box">
<div class = "content">
<h6 >Überschrift</h6>
<p>If you are coughing or sneezing, wear musk and must know how to use it and dispose it properly.</p>
</div>
</div>
<div class = "box">
<div class = "content">
<h6 >Überschrift</h6>
<p>Eat only well cooked food.</p>
</div>
</div>
<div class = "box">
<div class = "content">
<h6 >Überschrift</h6>
<p>Avoid close contact with animals that are sick.</p>
</div>
</div>
</div>
Я думаю, вам просто нужно добавить поле правила к содержимому, чтобы автоматически центрировать текст, поскольку вы находитесь в контейнере flex.
.content {
margin: auto 0;
}
введите здесь описание изображения
вы хотите, чтобы все тексты в середине их окна не было? добавил скрин результата
теперь работает отлично, вчера я ошибся :)
У вас есть селектор, который нацелен только на первое поле и устанавливает определенное заполнение. Удалите padding-top, чтобы у вас было однородное пустое пространство.
.container .box:nth-child(1) {
grid-column: span 2;
grid-row: span 1;
background: radial-gradient(#2bffc3, #72afd3);
padding-top: 3vh
}
Также мешает img-тег в первом элементе. Это необходимо?
Поскольку img является встроенным элементом, вы можете вместо этого поместить его в свой h6. Имейте в виду, что изображение будет действовать как символ, поэтому, если вы предоставите слишком большое изображение, оно сдвинет текстовую строку вниз. В качестве альтернативы вы можете вывести его из нормального потока по абсолютной позиции.
Спасибо, ответ от Цезаря и ваш ответ решают проблему.
это будет слишком просто, это не работает.