html - 如何在 flexbox div 上显示内容

标签 html css flexbox

如何在 flexbox div 上显示内容? 我有容器,在这个容器中是盒子 - bigBox,我有另一个盒子 - boxA(全屏)。一切正常,我可以简单地向下滚动,但我想把小 div 放在 boxA 的中心,这是不可能的。

.container {
        overflow: auto;
        width:100%;
        height:100%;
        display:flex;
    }
    
    .bigBox{
        width: 100%;
        height: 100%;
        display: flex;
        flex-wrap: wrap;
    }
    
    .boxA {
        background: white;
        height: 100%;
        width: 100%;
    }
<div class = "container>
    <div class = "bigBox">
            
            <div class ="boxA"><center><img src="img.jpeg" style= "width: 100%; height: 100%;">
                </center>
            </div>
    <div class ="boxA"><center><img src="img.jpeg" style= "width: 100%; height: 100%;">
                </center>
            </div>
    </div>
    </div>

最佳答案

不要使用 center 标签,如果你想让图像居中,不要给它一个 100% 的 widthheight .

.container {
        overflow: auto;
        width:100%;
        height:100%;
        display:flex;
    }
    
    .bigBox{
        width: 100%;
        height: 100%;
        display: flex;
        flex-wrap: wrap;
    }
    
    .boxA {
        background: white;
        height: 50px;
        width: 100%;
    }

    img{
        display: block;
        margin: 0 auto;
        height: 100%;
    }
<div class = "container>
    <div class = "bigBox">
        <div class ="boxA">
            <img src="http://lorempixel.com/output/cats-q-c-700-700-9.jpg">
        </div>
        <div class ="boxA">
            <img src="http://lorempixel.com/output/cats-q-c-700-700-9.jpg">
        </div>
    </div>
    </div>

关于html - 如何在 flexbox div 上显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41771645/

相关文章:

javascript - HTML5 本地存储 - 存储和加载已经下载过一次的 CSS

html - 如何在 Bootstrap alpha v6 中使用 flexbox

JavaScript 将选择菜单选项附加到 div 标签

html - 打印页面的 SEO

html - 我正在尝试将 SVG 文件放入 div 中,但调整 SVG 的大小无法正常工作

html - Flexbox 行/列等高

html - 使用CSS调整屏幕大小后水平对齐div

html - 嵌套 flexbox 和 CSS 网格布局中的空间分配问题

javascript - 背景图片轮播

css - 嵌套的 div 同样长