求助,关于<li>宽度控制的问题_html/css_WEB-ITnose
Jun 21, 2016 am 09:47 AMHTML页面设计 网页布局
<body><form id="form1" ><div><ul style="width: 100%"><li style="width: 40%">abc</li><li style="width: 40%">def</li><li style="width: 20%">ghi</li></ul></div></form><body>
我的想法是让这三个列表项处在同一行,可是三个列表项并不在同一水平行。含有ghi的那个
我后来设置了所有元素的border,padding,margin为none或者0,但结果还是开始一样显示的。
我就是搞不明白,三个
- 的width。我试了把最后一个
- 标签的width改为19%,然后三个
- 就是并列显示了。(注:我已经设置了
- 的float为left了)。
大家能给我指点一下吗? 谢谢了!
回复讨论(解决方案)
li是块级元素,是会自动往下排的,而不像p,img这类行级元素会直接连在后面,style里加上float:left; 这个属性就可以了,会变成漂浮元素进行漂浮排列,最后最好在所有
- 后再加上一行清除漂浮,以免影响接下来的布局
li是块级元素,是会自动往下排的,而不像p,img这类行级元素会直接连在后面,style里加上float:left; 这个属性就可以了,会变成漂浮元素进行漂浮排列,最后最好在所有
- 后再加上一行清除漂浮,以免影响接下来的布局
不好意思,没有注意到最后你已经漂浮了,既然是19%有问题,估计是哪个margin或者padding出问题,可能没检查出来,试试在样式里面加上一句 *{margin:0;padding:0} 呢假设ul在实际显示的时候宽度是789px,那么3个li标签的宽度分别是315.6px 315.6px 157.8px,应该是这个问题吧
一些老版本的浏览器不会认识float类型的宽度,造成了误差。一般在写代码时,就要考虑padding和magin的默认属性。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?

How do I use HTML5 form validation attributes to validate user input?

What is the purpose of the <iframe> tag? What are the security considerations when using it?

How to efficiently add stroke effects to PNG images on web pages?

What is the purpose of the <meter> element?

What are the best practices for cross-browser compatibility in HTML5?

What is the purpose of the <datalist> element?

What is the purpose of the <progress> element?
