2014-11-14 74 views
2

我有一个div,其中包含包含输入表的表单。问题是,即使设置为220px(width:220px),div仍然使用宽度100%。DIV标记保持使用100%宽度

下面是截图http://i.imgur.com/YtEzzuI.jpg?1

这里是HTML去掉TRS和TDS

<div class="prikol_filter_div"> 
    <form name="arrFilter_form" action="" method="get" class="prikol_filter_form"> 
     <table class="data-table" cellspacing="0" cellpadding="2"> 
      <thead> 
       <tr> 
        <td colspan="2" align="center"> 
          <span class="prikol_filter_title">ПОДОБРАТЬ ПОДАРОК</span><hr> 
        </td> 
       </tr> 
      </thead> 
      <tbody>trs and tds</tbody> 
      <tfoot>trs and tds</tfoot> 
     </table> 
    </form> 
</div> 

和CSS

.prikol_filter_div { 
    margin: 0px; 
    display: block; 
    width: 220px; 
} 

.prikol_filter_form { 
    margin-bottom: 40px; 
    width: 222px; 
    background-color: #c3150d; 
    border-radius: 4px; 
    position: relative; 
    right: 17px; 
} 

没有施加其他的CSS样式。

+0

你试过width:222px!important; ?? – jrenk

+1

蓝色区域是'div's'width'橙色区域显示它是一个'block'元素,以便它后面的任何元素都将在新行中。如果这是不可取的,你可能想尝试浮动'div'。 –

+0

刚刚尝试过。仍然是100%的宽度。 – Randomius

回答

2

不是。它使用您分配的220px

你的检查员也告诉你这个蓝色高亮颜色。

您所看到的是您的检测员突出显示其他突出显示的区域是“保留”的,因为div的样式类似于block。 (这是黄色高亮)

这意味着,如果你给div邻居元素,下面将进行定位div

如果你不希望它保留这个空间,使用display:inline-block;

看看这个JsFiddle为例与display:inline-block;

+0

这是正确的,我强调它表明空间是由该div。 – Randomius

+0

它显示它需要'220px'(蓝色突出显示的颜色)。 它也告诉你,该行的其余部分被保留(黄色),因为你告诉它显示为一个“块” –

+0

问题通过给予_display:inline-block; _解决,DIV使用100%宽度和给DIV,假设要带上这个空的空间(DIV和照片上的鞋子)。 – Randomius

-1

它不能宽度问题,给看看这个链接

[http://jsfiddle.net/vipinraunchhela/toos9k96/][1] 

所有的代码是在它和它的工作很好,如果你仍然有一个问题,只是一个属性添加到您的DIV 溢出:隐藏;这将隐藏所有正在离开它的数据。他们可能是一个原因,如果你有定义div属性宽度:100%!重要;这可能是原因。 如果你不能找出你可以使用的问题width:220px!important; 它不是一个好的做法,但暂时你可以使用它。

0
.prikol_filter_div { 
    margin: 0px; 
    display: block; 
    width: 220px!Important; 
} 

.prikol_filter_form { 
    margin-bottom: 40px; 
    width: 222px!Important; 
    background-color: #c3150d; 
    border-radius: 4px; 
    position: relative; 
    right: 17px; 
} 
+2

在stackoverflow上不鼓励使用代码解答。解释代码的作用和解决问题的方式总是更好。这有助于未来的用户。 –