How to Make Anchor Tags Span the Full Width of List Items?

Linda Hamilton
Release: 2024-10-29 05:43:31
Original
412 people have browsed it

How to Make Anchor Tags Span the Full Width of List Items?

Full-Width Anchor Tags in List Items

Introduction

When designing navigation menus, it's common to want the anchor tags () to stretch across the entire width of the list items (

  • ). However, setting the width attribute on tags typically has no effect.

    Solution

    To achieve this stretching effect, we must change the display property of the anchor tag. Inline elements like cannot have their width set. Instead, we need to convert them to block or inline-block elements:

    <code class="css">a.wide {
        display: block;
    }</code>
    Copy after login

    Usage

    Once the CSS rule is defined, add the "wide" class to the anchor tags within the

  • elements:

    <code class="html"><ul id="menu">
      <li><a class="wide" href="javascript:;">Home</a></li>
      <li><a class="wide" href="javascript:;">Test</a></li>
    </ul></code>
    Copy after login

    Notes

    • In Internet Explorer 6, it may be possible to set the width of inline elements, but this is due to incorrect CSS implementation.

    The above is the detailed content of How to Make Anchor Tags Span the Full Width of List Items?. For more information, please follow other related articles on the PHP Chinese website!

  • source:php.cn
    Statement of this Website
    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
    Latest Articles by Author
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template