【发布时间】:2014-04-12 02:00:09
【问题描述】:
我有一个 div 浮动在两个文本输入元素的左侧。当我在输入上设置 margin-top 时,浮动 div 的边距也会受到影响。为什么会这样,我该如何阻止它发生?!
相关 HTML:
<body>
<div class="manage-page">
<h2>Set Logo Order</h2>
<hr>
<div class="logo-container">
<div class="logo-draggable">
<div class="logo-image-box"></div>
<input type="text" />
<input type="text" />
</div>
</div>
</div>
</body>
相关CSS:
.manage-page {
margin-top: 2.5em;
margin-left: 25%;
margin-right: 25%;
min-width: 50%;
}
.logo-container {
border:1px solid #777777;
clear: left;
cursor: move;
height: 12.5%;
margin-bottom: 0.625em;
}
.logo-image-box {
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: contain;
border:1px solid #000000;
float: left;
height: 100%;
margin: 0 .875em;
width: 12.5%;
}
.logo-draggable input {
border: 1px solid #cccccc;
border-radius: 0.25em;
display: block;
font-size: 0.875em;
height: 2em;
line-height: 1.25;
margin-top: .5em;
padding: 0.375em 0.75em;
outline: none;
}
您可以在下面的 jsfiddle URL 中看到它的实际效果。只需更改 .logo-draggable input 的 margin-top 并观察 .logo-image-box 也被向上/向下颠簸:
【问题讨论】: