【发布时间】:2021-06-30 08:57:13
【问题描述】:
一个愚蠢的简单问题,但我是 CSS 新手,对 HTML 很生疏。
我需要在以下代码中添加什么,以便在移动设备上查看时,2 列从左/右布局变为上/下布局?
<html>
<head>
<style>
{
box-sizing: border-box;
}
/* Set additional styling options for the columns*/
.column {
float: left;
width: 50%;
}
.row:after {
content: "";
display: table;
clear: both;
}
</style>
</head>
<body>
<div class="row">
<div class="column" style="background-color:#FFB695;">
<h2>Column 1</h2>
<p>Data..</p>
</div>
<div class="column" style="background-color:#96D1CD;">
<h2>Column 2</h2>
<p>Data..</p>
</div>
</div>
</body>
</html>
【问题讨论】:
-
简短回答。媒体查询。长答案。使用弹性而不是浮动。并在移动设备上使用 flex-direction 列(在媒体查询中)
标签: html css multiple-columns