html - 动态调整 DIV 大小以适应在不同屏幕上调整大小的空间
问题描述
我正在尝试调整布局大小,使图像为屏幕宽度的 100%。我得到了那部分,但是当我尝试放置一个 div 以使其适合图像中的框时,我似乎无法让它对于不同尺寸的屏幕可靠。有没有办法确保我的 div 放在我的盒子里?我已附上我的代码的相关部分以供参考。我正在两个不同尺寸的屏幕上进行测试(一个较小的 chromebook 和一个 17" 东芝)。我只是在学习响应式网页设计,所以我不太确定问题出在哪里。
谢谢!
<div id="banner">
<img src="http://grouptheory.sammiirose.com/group%20theory%20header%202.png" width="100">
</div>
<div id="stuff">
Test words in here
</div>
<style type="text/css">
#banner{ top: 0%; width:100%;}
#stuff { position: absolute; height: 70%; top: 25%; left: 1%; width: 72%;
border: 1px solid black; overflow: auto; color: #000000;
text-align: center;}
</style>
解决方案
我没有很好地理解你的问题,但我认为你需要这个。
<div id="stuff">
<div id="banner">
<img src="http://grouptheory.sammiirose.com/group%20theory%20header%202.png">
</div>
Test words in here
</div>
<style type="text/css">
#banner img{ width:100%;}
#stuff { position: absolute; height: 70%; top: 25%; left: 1%; width: 72%;
border: 1px solid black; color: #000000;
text-align: center;}
</style>
推荐阅读
- c - 如何以独立于平台的方式分叉、等待和终止进程?
- amazon-web-services - 每个图像使用多个类来训练 AWS Sagemaker 的正确参数
- optimization - NASM 中的 RDTSCP 总是返回相同的值(定时单条指令)
- google-cloud-platform - 回滚 GCP 项目
- dart - 底部被 Infinity 像素溢出的 RenderFlex
- android - Flutter Firebase 存储返回 FirebaseApiNotAvailableException
- python - 创建一个稀疏矩阵:TypeError: __init__() 需要 2 到 5 个位置参数,但给出了 6 个
- .htaccess - 如何使用问号和标签重定向或重写 url?
- php - 重定向到 Laravel 中的不同页面
- python - 当 ZeroDivisionError 没有出现时,如何处理 RuntimeWarning?