gpt4 book ai didi

html - 移动设备中垂直居中的 Div 未对齐(使用 flexbox)

转载 作者:行者123 更新时间:2023-11-28 07:39:54 25 4
gpt4 key购买 nike

我使用 flexbox 使我的 div 垂直居中。它在桌面上运行良好,但在移动设备上不起作用。它以纵向居中,但是一旦标题为横向,文本就不再居中并且看起来被切断,用户必须滚动才能阅读全文(见下面的 img)

请给我一些关于如何解决这个问题的建议。谢谢。我试过将溢出设置为隐藏,但效果不佳。

enter image description here

.vertical-align {
height:auto;
min-height: 100vh;

/* Make it a flex container */
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;

/* Align the bootstrap's container vertically */
-webkit-box-align : center;
-webkit-align-items : center;
-moz-box-align : center;
-ms-flex-align : center;
align-items : center;

-webkit-box-pack : center;
-moz-box-pack : center;
-ms-flex-pack : center;
-webkit-justify-content : center;
justify-content : center;

flex-direction: row;

width:100%;
text-align: center;

font-size: 0;
}

/*CONTENT*/
.container-fluid{
margin:0 auto;
padding:0;
/* padding:50px;

position:absolute;
top:0;
left:0;
right:0;
bottom:0;

-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
*/}
.left-col{
padding-left:50px;
}
.right-col{
padding-right:50px;
}
#story_text{
font-size: 18px;
}
/*story*/
#story_text{
text-align:left;

height:100%;
padding-left:50px;
padding-right:50px;
}
#pictures{
text-align: right;
}
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="viewport" content="width=device-width, user-scalable=no" />

<body>
<div class="container-fluid">
<div class="row vertical-align">
<div class="col-lg-4 col-md-3 col-sm-2 col-xs-12, left-col"></div>
<div class="col-lg-4 col-md-6 col-sm-8 col-xs-12" class="content">
<p id="story_text">
The Daily Roundup is the anchoring café at The Working Capitol serving the needs of the TWC community, the immediate vicinity and crepe aficionados across the island. Borne out of our desire to create something truly distinct in the café scene in Singapore. Instead of serving typical brunch items, we have consulted with one of the foremost prestigious French chefs in Singapore to perfect our crepe offering.
<br><br>
The result is a tightly curated list of classic crepes and spritzers serving a largely unmet need in the market: lighter, healthier options for the increasingly conscious palette.
</p>
</div>
<div class="col-lg-4 col-md-3 col-sm-2 col-xs-12, right-col"></div>
</div>
</div>
</body>

--编辑

添加了额外的 jQuery,以检测 flexbox 的高度变化

jQuery(document).ready(function(){

var jQuery(window) = jQuery(window),
jQuery(sections) = jQuery('vertical-align'),
windowHeight;

function adjustHeight() {

// get height of browser window on page load and resize events
windowHeight = jQuery(window.height());

// apply windowHeight to each <section>
jQuery(sections.height(windowHeight));

}

jQuery(window.resize(function() {
adjustHeight();
}));

jQuery(window.load(function() {
adjustHeight();
}));

});

最佳答案

移动 web-kit View 端口有一些问题,我建议您按如下方式重置

html, body {
width: 100%;
height: 100%;
max-height: 100%;
max-width: 100%;
border: 0 0 0 0;
padding: 0 0 0 0;
}

这可能会使 vhvhw 正常工作

-- 编辑--

我认为您遗漏了一个重要的 <meta> 标记,放入以下元数据,之后即使没有 100% 修复它也能在您的手机中正常工作

<meta name="viewport" content="width=device-width, initial-scale=1">

关于html - 移动设备中垂直居中的 Div 未对齐(使用 flexbox),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31008074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com