html - 如何使我的网站的特定部分看起来像这样?(使用 HTML 和 CSS。)
问题描述
我目前正在尝试使用 HTML、CSS 和 Javascript 构建一个基本网站。但是,我在构建该网站的特定部分时遇到了困难。这就是该部分的外观,左边的部分是最让我绊倒的部分。这是一个包含四个彼此相邻的基本方块的部分;图 1(之前链接)提供了视觉效果。
这是我目前设法获得的图像:所有四个正方形都存在,但它们彼此堆叠在一起。我无法更接近它。
这是它背后的html代码:
<div class="top-large-left">
<h3 id="hot">Interaction</h3>
</div>
<div class="small-top-right">
<h3 id="item">Location</h3>
</div>
<div class="large-left-section">
<div>
<section class="left-section">
<div class="btn-group button">
<div class="button1">
<button type="button1">Display X, Y</button>
</div>
<div class="button2">
<button type="button2">Theme</button>
</div>
<div class="button3">
<button type="button3">Modal</button>
</div>
<div class="button4">
<button type="button4">Swap Image</button>
</div>
</section>
</div>
以及CSS:
.btn-group button {
background-color: #428bca;
border-radius: 5px;
font-weight: bold;
font-size: 15px;
color: white;
padding: 32px 19px;
cursor: pointer;
display: inline-block;
margin: 2px 2px;
border: 1px;
text-align: center;
line-height: 25px;
}
.button1 {
width: 130px;
}
.button2 {
width: 130px;
}
.button3 {
width: 130px;
}
.button4 {
width: 130px;
}
我如何能够实现第一张图片中显示的内容?我需要使用 css-grid 函数还是其他什么?如果我需要提供更多信息,请随时说,谢谢。
解决方案
Flex 是您的解决方案。Flex 让您的生活更轻松。
在全窗口上运行代码段。(完整页面)
.top-large-left {
background-color: #428bca;
padding: 0 1rem;
}
.top-large-left h3 {
margin:0;
}
.wrapper {
display:flex;
flex-direction:row;
}
.large-left-section,
.large-right-section{
flex: 1 1 50%;
border: 10px solid lightgrey;
text-align: center;
margin:5px;
}
.btn-group button {
background-color: #428bca;
border-radius: 5px;
font-weight: bold;
font-size: 15px;
color: white;
padding: 32px 19px;
cursor: pointer;
display: inline-block;
margin: 2px 2px;
border: 1px;
text-align: center;
line-height: 25px;
}
.large-left-section .left-section .btn-group.button{
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.large-left-section .left-section .btn-group.button .btn {
flex: 0 0 45%;
margin:5px;
}
.large-left-section .left-section .btn-group.button .btn button {
width:100%;
}
<div class="top-large-left">
<h3 id="hot">Interaction</h3>
</div>
<div class="wrapper">
<div class="large-left-section">
<section class="left-section">
<div class="btn-group button">
<div class="btn button1">
<button type="button1">Display X, Y</button>
</div>
<div class="btn button2">
<button type="button2">Theme</button>
</div>
<div class="btn button3">
<button type="button3">Modal</button>
</div>
<div class="btn button4">
<button type="button4">Swap Image</button>
</div>
</div>
</section>
</div>
<div class="large-right-section">
</div>
</div>
推荐阅读
- java - 泛型图:读写
- ubuntu - ubuntu 16 服务器上 microsoft 包的哈希和不匹配
- reactjs - 如何使用 @testing-library/react 和 react-test-renderer 测试由 Redux 状态控制的输入值?
- python - 使用神经网络根据用户输入预测结果
- python - Python请求多部分数据
- machine-learning - 尝试过Linear、SVR进行域名价格评估,机器学习中如何预测
- c++ - 将表示为数组的两个数字相加,一个测试用例被遗漏
- c# - 使用 Ajax 从文件中获取下一个图像
- android - 列表中的可绘制图像未显示在 Android Studio 上。(科特林)
- php - 问题 - 从 php WEEK 函数和 mysql WEEK 函数显示不同的 WEEK 编号?