html - 如何创建并排显示的两个按钮菜单?
问题描述
我正在尝试创建的此按钮菜单需要一些指导。首先,我需要在每个按钮之后留出间距,以便按钮之间有间隔。
其次,我希望绿色按钮列表位于红色按钮列表旁边,而不是在这两个按钮菜单之间再次出现间隙。我该怎么做呢?
.btn-group1 a {
background-color: red;
border: 1px solid white;
color: white;
cursor: pointer;
padding: 1em, 2em;
width: 20%;
display: block;
font: medium bold;
font-family: arial, sans-serif;
}
.btn-group2 a {
background-color: green;
border: 1px solid white;
color: white;
cursor: pointer;
padding: 1em, 2em;
width: 20%;
display: block;
font: medium bold;
font-family: arial, sans-serif;
}
.btn-group a:not(:last-child) {
border-bottom: none;
}
.btn-group a:hover {
background-color: #3e8e41;
}
<div class="btn-container">
<div class="btn-group1">
<a href="#">Introduction</a>
<a href="#">Career Development - IT Support</a>
<a href="#">Career Development - Testing</a>
</div>
<div class="btn-group2">
<a href="#">Lesson 1 - Methodologies and Development Lifecycle</a>
<a href="#">Lesson Breakdown</a>
<a href="#">Methodologies</a>
<a href="#">Waterfall SDLC</a>
<a href="#">Agile SDLC</a>
<a href="#">Scrum vs Kanban</a>
<a href="#">Ceremonies</a>
</div>
</div>
解决方案
尝试使用 flex 将它们并排放置:
.btn-container {
display: flex;
flex-direction: row;
}
至于间距,为您的课程在现有 css 中添加一个边距底部:
.btn-group1 a {
...
margin-bottom: 1em;
...
}
.btn-group2 a {
...
margin-bottom: 1em;
...
}
考虑重组你的 CSS 以消除欺骗:
.btn-group a {
border: 1px solid white;
color: white;
cursor: pointer;
padding: 1em, 2em;
width: 20%;
display: block;
font: medium bold;
font-family: arial, sans-serif;
margin-bottom: 1em;
}
.btn-group1 a {
background-color: red;
}
.btn-group2 a {
background-color: green;
}
.btn-group a:not(:last-child) {
border-bottom: none;
}
.btn-group a:hover {
background-color: #3e8e41;
}
<div class="btn-container">
<div class="btn-group btn-group1">
<a href="#">Introduction</a>
<a href="#">Career Development - IT Support</a>
<a href="#">Career Development - Testing</a>
</div>
<div class="btn-group btn-group2">
<a href="#">Lesson 1 - Methodologies and Development Lifecycle</a>
<a href="#">Lesson Breakdown</a>
<a href="#">Methodologies</a>
<a href="#">Waterfall SDLC</a>
<a href="#">Agile SDLC</a>
<a href="#">Scrum vs Kanban</a>
<a href="#">Ceremonies</a>
</div>
</div>
推荐阅读
- android - “npm start”和“react-native run-android”部署有什么区别?
- android - 为 Android 编译 PDFium 的正确选项是什么?
- azure - Azure blob 存储:从浏览器上传时检查 blob mime 类型
- javascript - 如何使用javascript在html中显示文本文件中的文本
- javascript - React 扩展组件渲染函数调用
- php - 使用 PHP 的动态 CSS
- node.js - 如何附加文档和更新密钥
- karate - 如何从项目 jar 运行空手道测试?
- sql-server - SSIS“执行报告”错误-“报告无效”-在 SSMS 中间歇性出现-原因?
- amp-html - 是否可以在不包含 v0.js 脚本的情况下创建 AMP 页面?