gpt4 book ai didi

html - 我在图像上尝试了 float div 但不起作用

转载 作者:行者123 更新时间:2023-11-28 02:24:16 24 4
gpt4 key购买 nike

My Problem

我想用 div 在图像上制作文本框/框,我已经尝试过了,但为什么不能。

我的代码在这里:

HTML/CSS:

.main{
position: relative;
margin: 8;
}
.main img{
position: relative;
height: 510px;
width: 100%;
}
.main-content{
position: absolute;
background: white;
height: 40px;
width: 40px;
}
<!DOCTYPE html>
<html>
<head>
<title>PokeMart</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<img src="valor.png">
<h3>PokeMart</h3>
<h4><a href="#">Login</a></h4>
<h4><a href="#">Register</a></h4>
</div>
<div class="main">
<img src="bg.jpg" />
<div class="main-content">Text</div>
</div>
<div class="footer">
<h5>Pokemart established 2017, powered by Pokemon Company</h5>
<h5>Copyright © 2017 LL. All Right Reserved.</h5>
<div class="contact">
<img src="facebook.png" width="25" height="25">
<img src="google.png" width="25" height="25">
<img src="twitter.png" width="25" height="25">
<img src="github.png" width="25" height="25">
<img src="instagram.png" width="25" height="25">
</div>
</div>
</body>
</html>`

CSS 代码只是 float 的 div,我试过 Display: Inline-block 仍然不起作用。

最佳答案

您使用的是绝对定位,但没有指示内容的放置位置。尝试使用top,left,right,bottom调整内容位置

top:20%;
right:100px;

.main {
position: relative;
margin: 8;
}

.main img {
position: relative;
height: 510px;
width: 100%;
}

.main-content {
position: absolute;
top: 20%;
right: 100px;
background: white;
height: 40px;
width: 40px;
}
<!DOCTYPE html>
<html>

<head>
<title>PokeMart</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<div class="header">
<img src="valor.png">
<h3>PokeMart</h3>
<h4><a href="#">Login</a></h4>
<h4><a href="#">Register</a></h4>
</div>
<div class="main">
<img src="http://via.placeholder.com/9000x500" />
<div class="main-content">Text</div>
</div>
<div class="footer">
<h5>Pokemart established 2017, powered by Pokemon Company</h5>
<h5>Copyright © 2017 LL. All Right Reserved.</h5>
<div class="contact">
<img src="facebook.png" width="25" height="25">
<img src="google.png" width="25" height="25">
<img src="twitter.png" width="25" height="25">
<img src="github.png" width="25" height="25">
<img src="instagram.png" width="25" height="25">
</div>
</div>
</body>

</html>`

关于html - 我在图像上尝试了 float div 但不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48031972/

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