Мне нужен текст на картинке, поэтому я использую следующий код CSS:
.blur{
width:100%;
height: 500px;
background-image:url(./images/14.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.b-cont{
width: 100%;
height: 500px;
font-family: Raleway;
background: rgba(201, 186, 186, 0.1);
backdrop-filter: blur(5px);
color: #ffcd3c;
font-size: 72px;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
span{
color: white;
}
HTML-код:
<body>
<div class = "blur">
<div class = "b-cont">
Background of laptop is good but have to <span>blur</span> for the website
</div>
</div>
</body>
Я хотел раскрасить предложение по-другому, поэтому добавил тег span. Это дало цвет, но разделило предложение
Посмотрите на это:
Проблема, которая вызывает это, заключается в том, что вы указали div для отображения в виде гибкого макета. При удалении display:flex;
из класса b-cont
текст отображается правильно:
.blur {
width: 100%;
height: 500px;
background-image: url(./images/14.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
justify-content: center;
display: flex;
align-items: center;
text-align: center;
}
.b-cont {
width: 100%;
height: 500px;
font-family: Raleway;
background: rgba(201, 186, 186, 0.1);
backdrop-filter: blur(5px);
color: #ffcd3c;
font-size: 72px;
justify-content: center;
align-items: center;
text-align: center;
height: fit-content;
}
span {
color: white;
}
<body>
<div class = "blur">
<div class = "b-cont">
Background of laptop is good but have to <span>blur</span> for the website
</div>
</div>
</body>
Кодепен: https://codepen.io/chingucoding/pen/GRjOGrK
Должно быть исправлено сейчас, текст теперь центрирован по вертикали.
<body>
<div class = "blur">
<div class = "b-cont">
<p>Background of laptop is good but have to <span>blur</span> for the website</p>
</div>
</div>
CSS
.b-cont{
width: 100%;
height: 500px;
font-family: Raleway;
background: rgba(201, 186, 186, 0.1);
backdrop-filter: blur(5px);
color: #ffcd3c;
font-size: 72px;
display:flex;
vertical-align: middle;
justify-content: center;
align-items: center;
text-align: center;
}
span{
color: white;
display: inline-block;
vertical-align: middle;
}
Ну вот ! Текст по центру с интервалом.
Мое предложение:
.blur {
width: 100%;
height: 500px;
background-image: url(./images/14.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.b-cont {
height: 100%;
background: rgba(201, 186, 186, 0.1);
backdrop-filter: blur(5px);
display: flex;
align-items: center;
}
.text {
font-family: Raleway;
color: #ffcd3c;
font-size: 72px;
text-align: center;
}
span {
color: green; /* Changed to green in order to make it more visible */
}
<div class = "blur">
<div class = "b-cont">
<div class = "text">Background of laptop is good but have to <span>blur</span> for the website</div>
</div>
</div>
его изменение вертикального выравнивания содержимого