html - 居中对齐 100% 宽度的元素
问题描述
我需要一些帮助来对齐元素。
这是我正在使用的布局:
.container {
display: block;
box-sizing: border-box;
}
.heading {
margin-bottom: 10px;
}
.file-input {
display: block;
border: 2px dashed #ddd;
padding: 10px;
width: 100%;
cursor: pointer;
}
<div class="container">
<h4 class="heading">7. Attachments</h4>
<input type="file" class="file-input">
</div>
是否有可能在不更改 HTML 代码的情况下以某种方式将“选择文件”按钮与边框内的文本居中对齐?
我无法更改 HTML 代码。我只能用我所拥有的..
编辑:我只是想补充一点,我想将边界保持在width: 100%
.
解决方案
这是我能得到的最接近的。你也许可以用网格做到这一点
.container {
display: flex;
justify-content:center;
box-sizing: border-box;
flex-wrap:wrap;
}
.heading {
margin-bottom: 10px;
width:100%;
}
.file-input {
border: 2px dashed #ddd;
padding: 10px;
padding-left:35%;
padding-right:35%;
width: 30%;
cursor: pointer;
}
<div class="container">
<h4 class="heading">7. Attachments</h4>
<input type="file" class="file-input">
</div>
推荐阅读
- opencv - opencv中RGB图像的色调图
- centos6 - mysql 连接器 32 与 64 位,CentOS 上的 yum 更新
- ios - Swift - 一个月后重置数据
- javascript - XNAT SimpleUploadPlugin - 如何包含 jQuery 插件
- python - 显示 ['and', 'and', 'and', 'and', 'and', 'and'] 而不是实际值
- javascript - testCafe 如何将标题添加到主页 url
- python - 关于如何在 tkinter 中为 gif 设置动画的问题
- java - 如何缩放基本图纸?
- python - 将每周时间序列转换为每日(使用比例标准)
- python - 如何获得列表所需的实际内存大小?