gpt4 book ai didi

css - 如何布局要堆叠在移动设备上的按钮?

转载 作者:行者123 更新时间:2023-11-28 00:05:37 25 4
gpt4 key购买 nike

我有一个包含以下代码的简单页面:

body {
font: 600 14px/24px "Open Sans", "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", Sans-Serif;
}

.container:before,
.container:after {
content: "";
display: table;
}

.container:after {
clear: both;
}

.container {
background: #eaeaed;
*zoom: 1;
}

.container,
section,
aside {
border-radius: 6px;
}

section,
aside {
background: #2db34a;
color: #fff;
margin: 1.858736059%;
padding: 20px 0;
text-align: center;
}

@media all and (min-width: 420px) {
.container {
max-width: 538px;
}
section {
float: left;
width: 63.197026%;
}
aside {
float: right;
width: 29.3680297%;
}
}
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Responsive</title>
<link rel="stylesheet" type="text/css" href="index.css">
</head>

<body>
<div class="container">
<section>Section</section>
<aside>Aside</aside>
</div>
</body>

</html>

按钮在较宽的屏幕上并排放置,但当我缩小浏览器的宽度时,它们不会像本例那样堆叠:

https://codepen.io/shayhowe/pen/KcApz

我使用相同的代码。

它在 Chrome 中不起作用,但在 Firefox 中有效。

在 Chrome 中看起来如下:

enter image description here

而且我不能再缩小它了。

如何让它在 Chrome 中工作?

最佳答案

我正在使用 Chrome,它似乎工作正常。但我会探索使用 display: grid 来帮助您在另一个元素内堆叠和移动不同的元素。

并非所有浏览器 ( https://caniuse.com/#search=grid ) 都 100% 支持它,但它在 Chrome 中有效,删除所有 ::after 的使用非常有帮助: :之前

在这里探索更多: https://www.w3schools.com/css/css_grid.asp

编辑:
您不能将 Chrome 缩小得更多,因为这是 Chrome 应用允许缩小到的限制。如果你想看到一个较小的 veiwport,启用开发者工具(按 12),然后尝试缩小你的浏览器。

此外,您的 css 样式可能会缓存在您的浏览器中。按 SHIFT+F5 刷新购买页面。

关于css - 如何布局要堆叠在移动设备上的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55719913/

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