css - 如何使方形 div 适合父 div
问题描述
我有方形 div,它被平方padding-bottom: 100%;
并position: absolute;
为孩子设置。当父 div 的宽度大于高度时,会出现方形溢出屏幕和滚动条。有没有办法让正方形适合父 div?
更新
很抱歉误导了你。是的,我想将我的方盒放入父 div。我为示例创建了新的 js fiddle
div.stretchy-wrapper {
width: 100%;
padding-bottom: 100%;
position: relative;
opacity: 0.5;
background: darkgreen;
}
@media all and (orientation: landscape) {
div.stretchy-wrapper {
width: 100vh;
height: 100vh;
padding-bottom: 0;
}
}
div.stretchy-wrapper > div {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
color: black;
font-size: 24px;
text-align: center;
}
.outercontainer {
background: red;
width: 400px;
height: 200px;
}
<div class="outercontainer">
<div class="stretchy-wrapper"></div>
</div>
解决方案
推荐阅读
- ios - 如何使用他们的代码在 IOS 上调用 Square App?
- javascript - 如何在反应组件中使用一个类的方法?
- mysql - MySQL - 使用物化路径方法列出父母子女
- file - FaspManager 嵌入式客户端在发送多个文件时过早停止
- php - 如何通过请求将本地存储数据获取到控制器
- c++ - 使用 cin 后停止 while 循环
- python - 'array' 这个词被打印在我的 numpy 2d 浮点数和字符串数组中
- python - 如何将pdf文档转换为ocr pdf文档
- networking - 如何使用osquery查看网卡名称和制造商等?
- javascript - 如何使用 react-redux 在 wordpress rest api 中获取类别