【发布时间】:2019-03-21 01:33:34
【问题描述】:
我需要一些帮助来集中我的一些代码。我不确定我是否使用了错误的定心方法,但它对我来说不太有效。它是 HTML 代码,但旨在为移动使用而编码。我的代码的问题是按钮容器不会以屏幕居中并保持左对齐。
.btn-container {
margin: 0 auto;
align-content: center;
display: flex;
border: none;
}
.btn-group button {
width: 150px;
height: 120px;
display: flex;
justify-content: center;
background-color: #404040;
border: none;
margin: 10px;
cursor: pointer;
float: left;
}
.btn-group button:not(:last-child) {
border-right: none;
/* Prevent double borders */
}
/* Clear floats (clearfix hack) */
.btn-group:after {
content: "";
clear: both;
display: table;
}
<body>
<div class="destination-title">
<a>Choose Your Destination</a>
</div>
<div class="btn-container">
<div class="btn-group">
<button>Opt 1</button>
<button>Opt 2</button>
<button>Opt 3</button>
<button>Opt 4</button>
<button>Opt 5</button>
<button>Opt 6</button>
</div>
</div>
<div class="button-divider"></div>
<div>
<button class="continue-button"> <ahref="customize.html">Continue</a></button>
</div>
</body>
【问题讨论】:
-
你想要什么居中的exaclty?
-
您的问题不清楚。什么是错的,什么是好的,你想得到什么?
-
对不起!我的整个按钮容器不会居中并粘在左边距
-
无论你使用 floats 还是 flexbox 项目 -
see here如果 CSS 网格是一个选项 -
不要混用float和Flexbox,你的
btn-group也需要显示为flex容器。