html - 如何放置框的按钮中心
问题描述
我有一个 div,我想在它的中心放置一个按钮。
1-我应该为按钮使用什么代码?<p?> <span?> <button?> (我觉得不好。我想要一个没有任何边框和点击动作的标签)
2-如何将其放置在 div 的中心?
(我想给那个按钮一个背景颜色,因此当我使用背景颜色时,所有的行都被占用了)
.box {
width: 280px;
height: 300px;
background-color: rgb(221, 20, 20);}
.button {
background-color: rgba(57, 133, 57, 0.1);
font-size: 13px;
}
<div class="box">
<p class="button">Read More</p></div>
解决方案
如果您不想要任何点击操作或边框,请使用div
标签。
要居中.button
,请尝试flexbox
通过将这些属性添加到.box
类中来使用:
display: flex;
justify-content: center;
align-items: center;
.box {
width: 280px;
height: 300px;
background-color: rgb(221, 20, 20);
display: flex;
justify-content: center;
align-items: center;
}
.button {
background-color: rgba(57, 133, 57, 0.1);
font-size: 13px;
}
<div class="box">
<div class="button">Read More</div>
</div>
推荐阅读
- mysql - 通过另一列的数据更新一列的特定部分
- angular - 一旦用户点击编辑铅笔图标,它应该打开一个新的模式对话框
- post - 在 snaplogic 上的 REST POST 快照上将文件发送到 api 端点时,如何修复错误 400“找不到文件”?
- javascript - 如果我去'/contact',我想保留以前的路线视图但显示一个模式
- dependency-management - npm eslint-config 包是否应该将它扩展的配置包放在 devDependencies 中?
- python - 在熊猫中连续获取计数唯一值
- jquery - 如何在jQuery中做一个简单的图像爆炸
- function - React Native 运行任何外部屏幕的功能
- javascript - 使用角度 2 以印度格式显示数字
- javascript - 如何创建 JavaScript 库?