html - 如何将盒子放在其他盒子旁边
问题描述
我想将 2 个盒子放在 1 行,另外 2 个放在下一行,但我不知道该怎么做,
现在每行只显示 1 个盒子
,请问你们中的任何人都可以解决这个问题吗
body{
background:#f4f4f4;
color:#555;
font-family:Bahnschrift SemiCondensed;
font-size:16px;
font-weight:normal;
margin:0;
}
.container{
width:80%;
margin:auto;
overflow:hidden;
}
#operator {
padding:0;
text-decoration:none;
}
.op-box {
border-radius: 15px / 50px;
background:#ccc;
margin:12px;
position: relative;
height:155px;
width: 50%;
border:green 1px solid ;
display:inline-block;
}
.op-box a {
color:#000;
text-decoration:none;
position: absolute;
padding:70px 0px;
text-align:center;
width: 100%;
height: 100%;
}
!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container">
<h4>list</h4>
<ul id="operator">
<li><div class="op-box"><a href="#">list1</a></div></li>
<li><div class="op-box"><a href="#">list2</a></div></li>
<li><div class="op-box"><a href="#">list3</a></div></li>
<li><div class="op-box"><a href="#">list4</a></div></li>
</ul>
</div>
<div style="margin-top:400px"></div>
</body>
</html>
我想将 2 个盒子放在 1 行,另外 2 个放在下一行,但我不知道该怎么做,
现在每行只显示 1 个盒子
,请问你们中的任何人都可以解决这个问题吗
解决方案
您可以通过执行以下操作来实现它:
ul {
display: grid;
grid-template-columns: repeat(2, 1fr);
}
推荐阅读
- java - 有没有办法返回多个选项的特定子类并将其保存在属性中?
- python - 查找两个椭圆之间距离的Python代码?
- github - Linux上的git克隆速度慢
- vba - 如何使用 Printer.Print 和 Microsoft Print to PDF 避免文件名对话框
- javascript - 包装器没有在 Jest 中定义
- java - 如何使用 Xuggler 查找短数组的长度以用音频填充视频?
- maven - 有没有办法查询 maven Central 的包并返回许可证?
- assembly - 在用户选择的索引 x86_64 处打印一个字符
- java - InflateException, Fragment$InstantiationException for Android Studio 中的 Fragment
- python - 如何使用字典首先替换字符串的字符?