2011-10-06 133 views
1

上午使用我的李项目的css。CSS李的背景宽度

div.categories li.selected 
{ 
    background-color:#d6d6d6; 
    white-space: nowrap; 
    list-style-type: square; 
    padding-right: 5px; 
    padding-left: 5px; 
    margin-left: 0px; 
    margin-bottom: 0px; 
    margin-right: 0px; 
    white-space: nowrap; 
    line-height: 20px; 
    width: 50px; 
} 

的问题是在锂的项目的内容的宽度不断变化,但根据Li的含量我不能改变的背景的宽度。如果我保持宽度不变,问题如下所示,否则,如果我不保持固定宽度,背景会延伸到最后。

enter image description here

+0

CSS背景不舒展,悲伤。 – Blender

+2

'ul'有宽度吗? – Chris

+0

@Chris - 在图像中是 –

回答

1

它很难说没有看到周围的代码中的元素,但在我看来,这种含有UL或div.categories的宽度设置,以及一些LI的被打破了,因为宽的内容长度。默认情况下,无论宽度如何,LI的宽度将扩展到所需的任何宽度,并且背景颜色将填充整个空间。

尝试取消您对UL或div.container宽度或上面锁定UL位置的任何限制。

+0

对不起,我的错误 –

0

不确定但显示:LI上的块(或LI中的跨度)可以帮助您查找什么?

+0

里没有跨度。如果有这样的问题就不存在。显示:块不起作用 –