Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

不同设备不同大小浏览器窗口的定位问题?

image

请问大神,上面的需求如何实现,我用相对定位在电脑上做好,用手机浏览器就对不上了。

背景图片是会根着浏览器窗口大小改变而改变的。

image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
<!DOCTYPE html>
<html>
<head>
<style>
  body {margin:0;padding:0;}
  .layout {position:relative;background-color:#CCC;}
  .layout img {width:100%;}
  .box {position:absolute;width:20vw;height:20vw;background-color:rgba(0,0,0,0.5);}
  .box.box-a {top:0;left:60vw;}
  .box.box-b {bottom:0;left:30vw;}
</style>
</head>
<body>
<div class="layout">
  <img src="https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png">
  <div class="box box-a"></div>
  <div class="box box-b"></div>
</div>
</body>
</html>

div 里的 img 设宽度 100%img 只设置宽度,高度会自适应,外面的 div 的高度就是自适应 img
div 的宽度根据实际需要来定
然后 内部用 绝对定位,单位用 百分比 或者 撑满的时候用vw 都可以


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...