【发布时间】:2021-01-22 03:22:01
【问题描述】:
我正在尝试获取一个高度为 450 像素的部分,并且在背景中应该是一张顶部带有某种文本框的图片。
我只是无法使用边距切换到图片。我希望它更加居中,但无论我使用什么,它都不起作用。即使我在任何类中将宽度设置为 100%,它也不会填充 100%。
.text-and-image {
position: relative;
width: 100%;
height: auto;
max-height: 450px;
display: flex;
overflow:hidden;
object-fit: cover;
background: steelblue;
/* background: rgb(156, 156, 156); */
}
.text-and-image-box{
position: relative;
width: 100%;
height: auto;
object-fit: cover;
}
.text-and-image-image{
width: 100%;
max-height: 600px;
height: auto;
background: yellow;
object-fit: cover;
}
.text-and-image-box2{
position: absolute;
top: 10%;
left: 55%;
width: 35%;
padding: 2%;
height: auto;
background: white;
}
.text-and-image-caption{
position: relative;
height: auto;
background: white;
font-size: 30px;
font-style: oblique;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" name="Website">
<link rel="stylesheet" href="./fragebeispiel.css">
<title>AMH Solingen</title>
</head>
<body>
<!-- Text neben Bild -->
<div class="text-and-image">
<div class="text-and-image-box">
<img class="text-with-image-image" src="https://images.unsplash.com/photo-1513135065346-a098a63a71ee?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1049&q=80">
</div>
<div class="text-and-image-box2">
<p class="text-and-image-caption">Ein schlechtes Messer fährt leichter in die Hand als ins Brot.</p>
<p class="text-and-image-text">Jeder Hobby- oder Profikoch braucht gutes Werkzeug. Nur damit macht es Spaß und ist sicher. Solinger Küchenmesser und Stahlwaren bestechen schon seit Jahrhunderten durch ausgezeichnete Qualität, hohe Langlebigkeit und innovative Lösungen. Das merkt man und hat seinen Weg schon in Millionen von Küchen in aller Welt gefunden. Unser Statement: </p>
</div>
</div>
</body>
</html>
【问题讨论】:
-
您有一个未应用的 CSS 规则
.text-and-image-image,因为 HTML 中的类是text-with-image-image。