简体   繁体   English

W3.CSS - 响应式布局 - w3-cell-row

[英]W3.CSS - Responsive Layout - w3-cell-row

Just started using W3.css, and yet havent found a solution for a tiny problem, that seems to appear only on mobile version.刚开始使用W3.css,还没有找到解决一个小问题的方法,这个问题似乎只出现在移动版本上。

So made a responsive container - row, with 4 different width cells in it.因此制作了一个响应式容器 - 行,其中包含 4 个不同宽度的单元格。 When I have my phone on portrait mode it is loading the site as it supposed to.当我的手机处于纵向模式时,它会按预期加载网站。 But when i turn it to landscape - only this container with the 4 cells - jumps back into "large/medium" screen version - cells lined up next to each other and not verticaly... (attached image to make it clear).但是当我把它变成横向时——只有这个带有 4 个单元格的容器——跳回到“大/中”屏幕版本——单元格彼此相邻排列而不是垂直......(附上图像以使其清楚)。

Portrait mode - works alright人像模式 - 工作正常

Landscape mode - only this container uses different width横向模式 - 只有这个容器使用不同的宽度

Back to portrait from landscape - same problem从横向返回纵向 - 同样的问题

Any advice on this?对此有何建议?

 <div class="w3-cell-row" style="width: 100%; background: #2D9595; padding-left: 3%; padding-right: 3%;"> <div class="w3-container w3-cell w3-mobile" style="padding: 3%"> </div> <div class="w3-container w3-cell w3-mobile" style="padding: 3%"> </div> <div class="w3-container w3-cell w3-mobile" style="padding: 3%"> </div> <div class="w3-container w3-cell w3-mobile" style="padding: 3%"> </div> </div>

thank you谢谢你

After testing this, my guess is going to be that CSS display: table;对此进行测试后,我的猜测将是 CSS display: table; may be recalculating and adjusting widths on rotation.可能正在重新计算和调整旋转宽度。 To keep things consistent, try applying widths in percentages to each .w3-cell-row , which should only affect it on 600px and below.为了保持一致,请尝试将宽度以百分比形式应用于每个.w3-cell-row ,这应该只会在 600px 及以下影响它。

 .w3-cell-row { width: 100%; padding: 0 3%; background: #2D9595; } .w3-cell-row .w3-container { padding: 3%; /* table-layout: fixed; */ } .w3-cell-row .w3-container:nth-child(1) { background-color: pink; width: 30%; } .w3-cell-row .w3-container:nth-child(2) { background-color: green; width: 40%; } .w3-cell-row .w3-container:nth-child(3) { background-color: blue; width: 15%; } .w3-cell-row .w3-container:nth-child(4) { background-color: orange; width: 15%; }
 <div class="w3-cell-row"> <div class="w3-container w3-cell w3-mobile"> adipisicing elit. Rerum </div> <div class="w3-container w3-cell w3-mobile"> consectetur adipisicing </div> <div class="w3-container w3-cell w3-mobile"> Lorem ipsum dolor sit amet </div> <div class="w3-container w3-cell w3-mobile"> Eos, aut? </div> </div>

According to documentation of w3.css:根据 w3.css 的文档:

Responsive Layout响应式布局

The w3-mobile class adds mobile first responsiveness to any HTML element. w3-mobile 类为任何 HTML 元素添加了移动优先响应。

Used together with w3-cell it will display the layout columns vertically on small screens/mobile phones and horizontally on medium/large screens.与 w3-cell 一起使用,它将在小屏幕/手机上垂直显示布局列,在中/大屏幕上水平显示布局列。

So this works as expected.所以这按预期工作。

On the other hand, "the different width" is on both modes (portrait and landscape) and the problem seems fixed removing the paddings (3% , left and right) of the div with class "w3-cell-row".另一方面,“不同的宽度”在两种模式(纵向和横向)上都存在,并且问题似乎已解决,删除了类“w3-cell-row”的 div 的填充(3%,左右)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM