search
HomeWeb Front-endHTML Tutorial求助,关于<li>宽度控制的问题_html/css_WEB-ITnose

HTML页面设计 网页布局

  • 标签的使用 这个是我网页表示层的部分代码:
    <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,但结果还是开始一样显示的。
    我就是搞不明白,三个
  • 标签加起来的不正好是100%的width么?为什么会超过
      的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的默认属性。

  • Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

    The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

    How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

    The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

    What is the purpose of the <iframe> tag? What are the security considerations when using it?What is the purpose of the <iframe> tag? What are the security considerations when using it?Mar 20, 2025 pm 06:05 PM

    The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

    What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

    The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

    What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

    The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

    What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

    Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

    What is the viewport meta tag? Why is it important for responsive design?What is the viewport meta tag? Why is it important for responsive design?Mar 20, 2025 pm 05:56 PM

    The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

    How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

    This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    Hot Tools

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SecLists

    SecLists

    SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.