【发布时间】:2014-09-18 21:51:10
【问题描述】:
http://jsfiddle.net/SVJaK/1338/
在这个小提琴中,我厌倦了在绿色 div 和我的右侧 div 之间留出一小段空间。我不得不在左边距上放大量的像素来制造那个小间隙。你能告诉我为什么吗?间隙就像 50 像素之类的东西,我必须将 620 的值设置为 margin-left 以产生间隙。我的 div 嵌套有什么问题吗? 我希望 .right div 是绿色 div 的右侧。这是我的代码:
<div class="nobr">
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div style="clear:both"></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div style="clear:both"></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
<div class="className" style="background-color:green; height:100px;" id="IDName" ><a href="#" style="font-weight: bolder;"> Your Text goes here </a></div>
</div>
<div class="right">this is my right div</div>
我的 CSS 是这样的:
a{display:table-cell; height:100%;vertical-align:middle; text-align:center; }
a:hover { background-color:#000;}
div.className {display:table; width:200px; float:left;}
div.nobr {width:600px; }
div.right {margin-left:620px;}
【问题讨论】:
-
这似乎不是正确的小提琴。
-
很抱歉。我编辑了正确的小提琴。
-
我认为您未能关闭您的
div.nobrdiv。尝试在div.right元素之前添加一个结束标签。 this 是你的意思吗? -
我为我的 .nobr 编辑了结束标签。右 div 没有变化。
-
你能澄清一下你想要的行为吗?当我添加结束标签(见上面的小提琴)时,我看到
.right位于.nobr的右侧,因此它的位置没有任何大的余量。