gpt4 book ai didi

html - 在图片上移动文本

转载 作者:太空宇宙 更新时间:2023-11-04 15:56:48 25 4
gpt4 key购买 nike

我想将标题文本移到图片上。将图片的底部边距更改为 -50% 会有所帮助,但文本会根据屏幕尺寸显着移动。

.banner{
height: auto;
width: 100%;
max-width: 1200px;
z-index: 1;
text-align: right;
color: white;
margin: none;
bottom margin: none;
}

.title h1{
color: red;
width: 100%;
height:100%;
margin: auto;
z-index: 1;
text-align: center;
text-shadow: black;
float:left;
}

.title p{
color: red;
text-align: center;
float: left;
}
<!DOCTYPE html>
<html>
<head>
<title>Joe's Garage</title>
<link rel="stylesheet" type="text/css" href="Garage CSS">
</head>
<body>
<div class="banner">
<img src="https://static1.squarespace.com/static/562837d1e4b0c53c5afbc078/t/5863246febbd1ab7ab5125b6/1482892406200/slide_405344_5057908_free.jpg?format=1500w">
</div>
<div class="title">
<h1>JOE'S GARAGE</h1>
<p>We Take the Worry Out of Car Trouble by Delivering Accurate Repairs at an Honest Price</p>
</div>
</body>
</html>

最佳答案

我肯定会为此使用 background-image。毕竟,这就是它的用途。

.banner {
background-image: url('https://static1.squarespace.com/static/562837d1e4b0c53c5afbc078/t/5863246febbd1ab7ab5125b6/1482892406200/slide_405344_5057908_free.jpg?format=1500w');
background-size: cover; // or 'contain', depending on what you want.
}

为了获得最佳效果,请将叠加标记放在 .banner 容器中,添加一些 height 控件、background-position 样式,以及您的最喜欢的垂直对齐技巧(假设您希望文本垂直和水平居中)。

body {
margin: 0;
}

.banner {
align-items: center;
background: url('https://static1.squarespace.com/static/562837d1e4b0c53c5afbc078/t/5863246febbd1ab7ab5125b6/1482892406200/slide_405344_5057908_free.jpg?format=1500w') center center;
background-size: cover;
display: flex;
justify-content: center;
margin: auto;
max-width: 1200px;
min-height: 100vh;
text-align: center;
width: 100%;
}

.title h1, .title p {
color: red;
line-height: 1.5;
margin: 0;
text-shadow: 1px 1px 4px black;
}
<div class="banner">
<div class="title">
<h1>JOE'S GARAGE</h1>
<p>We Take the Worry Out of Car Trouble by Delivering Accurate Repairs at an Honest Price</p>
</div>
</div>

关于html - 在图片上移动文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45023177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com