Preserve the formatting of the text within the list item

I'm currently working on a website where I have a ul element set up. Each list item contains text, but when I zoom in and out of the page, the text overflows the box. Is there a way to prevent the text from overflowing the list item?

HTML

<div id="navigation">
                  <ul>
          <font face="Verdana, Geneva, sans-serif">
          <li> <a href="../index.html"> HOME </a> </li>
          <li id="active-li"> <a href="#"> BIOGRAPHY </a> </li>
          <li> <a href="../News&Events/N&SAz.html"> NEWS & EVENTS </a></li>
          <li> <a href="../Books/booksAZ.html"> BOOKS </a></li>
          <li> <a> VIDEOS </a> </li>
          <li> <a href="../Picutres/picutresAZ.html" id="last-item"> PHOTOS </a> </li>
          </font>
        </ul>
            </div>
    </div>  

CSS

#navigation {
        width: 900px;
        margin: 0 auto 0px;
    }
    div#navigation ul li {
        font-size:.5em;
        list-style:none;
        background-color:transparent;
        background-color:#FFF;
        float: left;
        width:150px;
        height:40px;
        text-align:center;

    }
    div#navigation ul li:hover {
        background-color:#9C1A35;
    }
    div#navigation ul li a {
        color:#333333;
        text-decoration:none;
        display: block;
        padding:6px 0px 18px;
    }
    #navigation ul li a:hover {
        color:#fff;
    }
    ul {
        padding:0;
    }
    #active-li {
        background:#9C1A35 !important;
    }
    #active-li a {
        color:#fff !important;
    }
    #last-item {
     !important;
    }
    div#navigation ul li #active {
        background:#9C1A35 !important;
    }
    div#navigation ul li #active a {
        color:#fff;
    }

Answer №1

It is crucial to understand that when formatting lists, the key is to focus on styling the CONTENTS rather than the list itself.

To begin, reset the list with the following code:

ul, li {margin:0;padding:0}

Next, apply all styling to the anchor within the list by using display:block. You can utilize positioning like float:left on the LI element, but make sure to place all other styles on the A tag.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error encountered in Angular2 code due to a problem with inline templates

I'm grappling with the code below: import { Component } from '@angular/core'; @Component({ selector: 'character', template: `<h2 class="{{name}}">{{name}}</h2> <ul> ...

The combination of Bootstrap and Django does not support responsive design

My code is not working correctly, and I'm struggling to identify the errors. The website I'm working on has subpages, but the responsive design doesn't seem to be functioning properly. Could this issue be related to mistakes in my HTML/CSS c ...

What is the best way to include a subscript (small letter) beneath a word using html and css bootstrap 5?

Is it possible to add a small letter (sub) below a word in HTML and CSS? I have included a screenshot for reference. I want to display "Max 100, Min 1" just like shown in the image. Here is my code: <input type="text" class="textarea" ...

Choosing the div elements that have a PNG background image assigned to them

Is there a way to use jQuery to target all the div elements with a background-image property set to url(somepath/somename.png) in their style? ...

How can you correctly include a link to a plain text sitemap file in an HTML document?

Could this code effectively inform Google to index my sitemap (or acknowledge its presence)? <link rel="sitemap" href="./sitemap.txt" type="text/plain" title="Sitemap" /> Google's guidelines allow plain t ...

Is it possible to upload files without using AJAX and instead through synchronous drag-and-drop functionality in the foreground?

Currently, my website has a standard <input type="file"> file upload feature that sends data to the backend upon form submission. I am looking to enhance the functionality of the form by allowing users to drag and drop files from anywhere within the ...

How can I address the problem of adjusting the title to match the size of the image in question?

I need help creating a design where an image and h2 title appear on top of the image... Below is a reference screenshot: I am looking to achieve something similar. CSS: h2 { position: relative; letter-spacing: 1px; display: inline-block; positi ...

What is the reason behind the inconsistency of calling a function on click not always functioning properly in Chrome and FF, while working seamlessly in IE?

Consider a scenario where the code below is being used: <HTML> <HEAD> <SCRIPT> function myFunction(atlasTrackingURL) { var atlasURL = atlasTrackingURL; if (!atlasURL) return; //Creating a cache busting mechanism ...

Highlight the menu item when you reach a specific section

I am facing difficulties in creating a scrolling menu that highlights the respective item when a specific section is reached. As a beginner in design, I am struggling to achieve this effect. Any insights or guidance on how to implement this would be grea ...

Analyzing Date Strings Retrieved From a MySql Database

In my MySQL database, I have a relationship that stores dates as varchar along with other attributes. This is how it looks: Answers answerId answer questionId date I am working on a web application where the user can select a &apo ...

Tips for eliminating additional white space within a bootstrap row

I'm having trouble removing the extra space on my website while using Bootstrap 5. I've tried various Bootstrap classes like pr-0, mr-0, p-auto, m-auto but none of them seem to work. I also attempted using CSS margin-right: 0; but that didn' ...

What steps do I need to follow in order to modify a CSS style definition to create a border around

I currently have a CSS style defined as follows: [class*="col-"] { border: 1px solid #dddddd; } This particular CSS definition gives borders to all of the bootstrap grid columns on my page. However, I now want to apply borders only to the bootstrap ...

Achieving vertical center alignment for the label and btn-group in Bootstrap

Is it possible to align other elements with the Bootstrap btn-group? <div class="btn-toolbar text-center"> <div class="pull-left"> <span class="glyphicon glyphicon-envelope " style="font-size:1.5em;"></span> < ...

"Styling a cover image in CSS without the need for readjustments

I found a cool idea for creating a Facebook-like cover image on this community. Check out this jsfiddle that I stumbled upon. .cover { width: 100%; height: 180px; overflow: hidden; background-color: black; } .cover > img { position: relative; width: 10 ...

Where is the appropriate location to insert a <script> tag in NextJs?

I am facing a challenge in my NextJs application when trying to include the <script> code. I attempted to add it in a .js file but it did not work as expected. In traditional React applications, we typically use the index.html file to incorporate sc ...

Next.js and Material UI - issues with dynamic styles not functioning

I recently started using Next JS in combination with Material UI, following the example project setup provided in the documentation on Github: https://github.com/mui-org/material-ui/tree/master/examples/nextjs My main objective is to utilize Material UI&a ...

AngularJS 1: Dynamically updating input values in real-time

Hey everyone, I'm experimenting with Angular and have encountered a roadblock. I am trying to assign values to an input element using ng-repeat for a list of parameters. <input type="text" ng-model="parameters.inParameterName" class="form-control ...

Tips for achieving a standard dropdown appearance in a collapsed navbar with Bootstrap split button dropdown

Trying to create a navbar with a split dropdown button has been a challenge. The design either goes awry when the screen is narrow and the navbar is hidden behind the toggle, or it doesn't look right on a wider screen when the navbar is expanded. Cur ...

Switching Over to Burger Menu

I created a burger menu using HTML, CSS, and jQuery that switches from a full-width menu to a burger menu. However, I'm facing an issue with toggling the dropdown when the menu collapses. Here's my code: <!DOCTYPE html> <html> < ...

What is the best way to position the sign-in modal form on the top right corner of my website?

Hey there, I'm facing a bit of an issue and can't seem to figure out what went wrong. Recently, I inserted a Bootstrap Sign In modal in my HTML file. Here's the code: <div class="text-center"> <a href="" class ...