我有按钮框,应该在导航菜单下居中。由于某种原因,方框没有居中,元素正在浏览导航菜单。
如果您使用dev tools并选择div(按钮框),您将看到元素的位置。这影响了我的垫子。底部的垫子看上去很好,但在顶部是混乱的。
下面是一个工作示例:
section.settingsBox {
width: 100%;
padding-top: 0;
float: left;
background-color: white;
border: 2px solid #000099;
}
nav.xNavigationSetting {
width: 100%;
margin-left: 0;
margin-right: 0;
padding-top: 2px;
background-color: #c8e2db;
float: left;
border-bottom: 2px solid #000099;
height: 18px;
}
nav.xNavigationSetting a {
color: black;
text-decoration: none;
cursor: pointer;
font-weight: bold;
padding-left: 5px;
padding-right: 5px;
}
nav.xNavigationSetting a:hover {
color: #999999;
}
div.buttonBox {
background-color: #c8e2db;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
border-bottom: 2px solid #000099;
}<section class="settingsBox">
<div id="htmlSetting">
<nav class="xNavigationSetting">
<a href="#" data-id="settingMain">Menu</a> |
</nav>
<div id="settingTbl">
<div class="buttonBox">
<input type="button" name="settingButton" id="settingAdd" value="Add" />
</div>
<div class="settingsTblMaster">
<table>
<thead>
<tr>
<th>Test</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
如果有人能帮我解决这个问题,请告诉我。我非常肯定我的一些CSS属性导致了这个问题。提前谢谢。
发布于 2017-08-30 15:27:59
这是因为您的.xNavigationSetting类有float: left,删除它将修复这个问题
或者,如果您想保持float: left样式,将clear: left;添加到#settingTbl中
发布于 2017-08-30 15:31:24
你可以添加
display: flex;
align-items: center;
justify-content: center;转到div.buttonbox
https://jsfiddle.net/207gsm80/
section.settingsBox{
width: 100%;
padding-top: 0;
float: left;
background-color: white;
border: 2px solid #000099;
}
nav.xNavigationSetting {
width: 100%;
margin-left: 0;
margin-right: 0;
padding-top: 2px;
background-color: #c8e2db;
float: left;
border-bottom: 2px solid #000099;
height: 18px;
}
nav.xNavigationSetting a {
color: black;
text-decoration: none;
cursor: pointer;
font-weight: bold;
padding-left: 5px;
padding-right: 5px;
}
nav.xNavigationSetting a:hover {
color: #999999;
}
div.buttonBox{
background-color: #c8e2db;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
border-bottom: 2px solid #000099;
display: flex;
align-items: center;
justify-content: center;
}<section class="settingsBox">
<div id="htmlSetting">
<nav class="xNavigationSetting">
<a href="#" data-id="settingMain">Menu</a> |
</nav>
<div id="settingTbl">
<div class="buttonBox">
<input type="button" name="settingButton" id="settingAdd" value="Add" />
</div>
<div class="settingsTblMaster">
<table>
<thead><tr><th>Test</th></tr></thead>
<tbody><tr><td>Row 1</td></tr></tbody>
</table>
</div>
</div>
</div>
</section>
发布于 2017-08-30 15:30:28
删除float: left on settingsBox,如果不能删除,则可以将clear: both添加到settingTbl
请参阅下面的示例,该演示清除了使用的float:
section.settingsBox {
width: 100%;
padding-top: 0;
float: left;
background-color: white;
border: 2px solid #000099;
}
nav.xNavigationSetting {
width: 100%;
margin-left: 0;
margin-right: 0;
padding-top: 2px;
background-color: #c8e2db;
float: left;
border-bottom: 2px solid #000099;
height: 18px;
}
nav.xNavigationSetting a {
color: black;
text-decoration: none;
cursor: pointer;
font-weight: bold;
padding-left: 5px;
padding-right: 5px;
}
nav.xNavigationSetting a:hover {
color: #999999;
}
div.buttonBox {
background-color: #c8e2db;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
border-bottom: 2px solid #000099;
}
#settingTbl {
clear: both;
}<section class="settingsBox">
<div id="htmlSetting">
<nav class="xNavigationSetting">
<a href="#" data-id="settingMain">Menu</a> |
</nav>
<div id="settingTbl">
<div class="buttonBox">
<input type="button" name="settingButton" id="settingAdd" value="Add" />
</div>
<div class="settingsTblMaster">
<table>
<thead>
<tr>
<th>Test</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
https://stackoverflow.com/questions/45964274
复制相似问题