我正在开发一个简单的投资组合网站。但是当我通过浏览器元素调整大小时,会与背景图像重叠。
<div class="container">
<div class="main-heading">
<h1>Jegath S</h1>
</div>
<div class="desc">
<p>
I am a web developer and designer
from INDIA . I engoy building anything
using code . Need a website ?
Leave it to me :)
</p>
</div>
<div class="explore-button">
<button class="btn"><a href="#works">Explore</a></button>
</div>
<div class="social-media">
<i class="fa fa-facebook" aria-hidden="true"></i>
<i class="fa fa-envelope" aria-hidden="true"></i>
<i class="fa fa-phone" aria-hidden="true"></i>
</div>
</div>
这是css代码
*{
margin: 0;
padding: 0;
}
body ,html{
font-family: 'Open Sans', sans-serif;
background: f6f6f6;
height: 100%;
width: 100%;
}
.container{
font-family: 'Vollkorn', serif;
background-image: url(../images/bg-img.jpg) ;
background-repeat: no-repeat;
min-height: 100%;
background-position: right;
position: relative ;
}
.main-heading{
position: absolute;
font-family: serif;
font-size: 60px;
top: 180px;
left: 565px;
display: inline-block;
}
.desc{
width: 304px;
text-align: justify;
letter-spacing: 1px;
position: absolute;
top: 400px;
left: 410px;
line-height: 35px;
}
.explore-button a{
color: #fff;
text-decoration: none;
}
.btn{
width: 110px;
height: 42px;
background: #9A3FE0;
border: none;
font-size: 15px;
font-weight: bold;
letter-spacing: 2px;
border-radius: 5px;
text-align: center;
position: absolute;
top: 570px;
left: 500px;
}
.social-media .fa{
font-size: 25px;
display: block;
margin-bottom: 30px;
margin-left: 45px;
}
.social-media .fa-facebook{
position: absolute;
top: 50%;
}
.social-media .fa-envelope{
position: absolute;
top: 40%;
}
.social-media .fa-phone{
position: absolute;
top: 60%;
}
请给我一个解决方案。
这是浏览器全宽时的图像
这是浏览器调整大小时的图像
如果有人可以向我建议解决方案,那将非常有帮助。提前致谢 。
发生这种情况是因为您在主标题类中写道:“left:565px;”。无论您使用的设备大小如何,浏览器都会按照您的要求执行并将 h1 保持为 565。这也适用于 desc 类和探索按钮。为了使其移动友好,您需要使用媒体查询。在此处查找有关它们的更多信息。媒体查询所做的是您可以根据设备宽度编写自定义 css。所以它们是移动友好的。如果你不想打扰媒体查询,你可以用 right:x px 定位 h1、段落和按钮;而不是左:x px;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句