[英]make all the <li> elements inside a container <ul> element the same width
I've been struggling with this for a day or so now and I've gone back and started from square one a couple of times but I'm trying to get a horizontal css flyout header to work as I want. 我已经为此苦苦挣扎了一天左右,我回去了几次,从正方形开始,但是我想让水平的css弹出标题可以根据需要工作。
The dropdown bit I want to expand as wide as needs be (it'd be great if the category names were forced to be on one line) while the container expands to accommodate them. 当容器扩展以容纳它们时,我想根据需要扩展的下拉位(如果类别名称被强制在一行上,那将是很好的选择)。 A fiddle will explain better.
小提琴会更好地解释。
http://jsfiddle.net/HyuLy/ http://jsfiddle.net/HyuLy/
Any ideas? 有任何想法吗?
要使<ul>
容器内的所有<li>
元素具有相同的宽度,请添加以下内容:
div#dropMenu ul.level2 li {width: 100px;}
change code to the following to fill the <li>
element inside the <ul>
but this will not re-size the container <ul>
to get wider to accommodate the <li>
. 变更码以下面以填充
<li>
内的元素<ul>
但这不会重新大小的容器<ul>
获得更宽以容纳<li>
.subCatodd{
background-color:#7b631d;
padding:10px 0;}
.subCateven {
background-color:#665011;
padding:10px 0;}
You have a few width: 100%
's that are ruining your layout because of your padding
's. 您有一些
width: 100%
的width: 100%
由于其padding
而破坏了您的布局。 width
is the inside width of the element, so when you combine width:100%
with, let's say, padding:20px
your element is now 100% + 40px. width
是元素的内部宽度,因此当您将width:100%
与padding:20px
结合使用时,您的元素现在为100%+ 40px。
Also, you have a few float: left
's that shouldn't be there as well. 另外,您还有一些
float: left
也不应该在那里。 If you're stacking the elements vertically still, there's no need to float: left
. 如果您将元素垂直垂直堆叠,则无需
float: left
。
Take a look at this: http://jsfiddle.net/scrimothy/mxW4y/ 看看这个: http : //jsfiddle.net/scrimothy/mxW4y/
Since there's so much going on here, you may want to copy this css back into your text editor to see it better. 由于这里发生了很多事情,您可能需要将此CSS复制回文本编辑器以更好地查看它。 I've removed a few widths and floats
我删除了一些宽度和浮标
Check this 检查一下
http://jsfiddle.net/XUj5S/ http://jsfiddle.net/XUj5S/
When you start adding padding to 100% width it will be doing exactly that, that's why your li objects start to overlay their parents they are not 100% they are like 110% cuz of the padding you're adding, here's an example of what I'm saying... 当您开始将填充添加到100%的宽度时,它将完全做到这一点,这就是为什么您的li对象开始覆盖其父对象而不是它们的100%,就像您要添加的填充的110%cuz一样,这是一个示例我是说...
http://jsfiddle.net/EcENF/ http://jsfiddle.net/EcENF/
You have to define width on px if you start to add padding based on px, using % will just mess up things 如果您开始基于px添加填充,则必须在px上定义宽度,使用%只会使事情变得混乱
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.