Styling an Unordered Vertical List with CSS: Creating Overlapping Items

Please take a look at this demo.

.sideNav {
  width: 25%;
}
.sideNav ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: 25%;
  height: 100%;
  position: fixed;
  overflow: auto;
}
.sideNav li a {
  display: block;
  color: black;
  text-align: center;
  text-decoration: none;
}
.sideNav li {
  font-family: "Comic Sans MS", cursive;
  text-align: center;
  float: left;
}
.right {
  width: 75%;
}
<div class="content">
  <div class="sideNav">
    <ul>
      <li><a href="curriculum.html">Curriculum</a>
      </li>
      <li><a href="ersea.html">ERSEA</a>
      </li>
      <li><a href="family-services.html">Family Services</a>
      </li>
      <li><a href="mental-health.html">Mental Health</a>
      </li>
      <li><a href="nutrition.html">Nutrition</a>
      </li>
      <li><a href="health.html">Health</a>
      </li>
      <li><a href="policies.html">Policies &amp; Procedures</a>
      </li>
      <li><a href="ersea.html">ERSEA</a>
      </li>
      <li><a href="family-services.html">Family Services</a>
      </li>
      <li><a href="mental-health.html">Mental Health</a>
      </li>
      <li><a href="nutrition.html">Nutrition</a>
      </li>
    </ul>
  </div>
  <div class="right">
    This is a test
  </div>
</div>

I'm facing an issue with the CSS unordered list links. The links are not displaying on separate lines as intended. Each link seems to be running into the next one. Additionally, I've set up two <div> tags where one should occupy 25% of the div and the other 75%. However, they seem to overlap each other in my demo where the text "This is a test" appears behind the list.

What I need is for the side navigation bar to remain fixed in one position and have each link displayed on its own line. Furthermore, the text "This is a test" should be placed separately on the right-hand side of the side navigation bar.

Answer №1

You are facing a couple of issues that need to be addressed:

  1. Setting your li items to float: left will cause them to merge together.

  2. The .sideNav element has been set to have position: fixed, resulting in it not being calculated into the flow of the rest of the content on the page and causing it to overlap other elements.

Below is an updated CSS snippet to provide some guidance towards resolving these issues:

.sideNav {
  width: 25%;
}

.sideNav ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: 25%;
  height: 100%;
  position: fixed;
  overflow: auto;
}

.sideNav li a {
  display: block;
  color: black;
  text-align: center;
  text-decoration: none;
}

.sideNav li {
  font-family: "Comic Sans MS", cursive;
  text-align: center;
  display: block;
}

.right {
  padding-left: 25%;
  width: 75%;
}

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

What is the best way to create square editor tabs in Eclipse without using swt-border-radius?

The design of Eclipse's rounded and/or swooshing tabs is starting to feel outdated in today's modern era. I thought that by adding the following line in my default.css file, I could get rid of the rounded corners: swt-corner-radius: 0px Howeve ...

Challenge with CSS3 Selectors

I'm struggling to understand why this code works: input[ type = "text" ]:last-of-type:focus{ border:1px solid red; } but this code doesn't work: input[ type = "checkbox" ]:last-of-type:checked{ border:1px solid red; } The example given with t ...

A sequence of seven elements lined up consecutively

After working with bootstrap on several pages, I am struggling to figure out the best way to arrange 7 equal width elements in a row of 12 spans. It's important to me to ensure that the media queries continue to work effectively. <div class="row"& ...

What steps should I take to adjust the text size in my media query?

I'm facing a challenge with a media query to decrease the font size of a text. It seems like a straightforward task, yet I can't pinpoint the issue. HTML: <div class="fp-featured"> <div class="fp-title">TITLE</div> <p class ...

Is it true that outerHeight(true) excludes margins?

As stated in the JQuery documentation, the outerHeight(true) function should return the complete height of an element, including padding, border, and margins. However, I encountered a scenario where this functionality seemed to be flawed. You can find a co ...

Is it possible to adjust the height of the dropdown menu in a mat-select component in Angular 7?

How can I adjust the height of a mat-select in Angular7 to display all items properly? Here is my component file: import { Component, ViewEncapsulation } from "@angular/core"; import { FormControl } from "@angular/forms"; /** @title Select with multiple ...

a problem with images overflowing in CSS

I am currently working on setting up a personal blog for myself, but I have encountered an issue with the overflow property. On my home page, I have a div that contains text and images for reviews. When users click on the "read more" button, the full parag ...

Blade - Assign a random CSS class from an array

I have been searching high and low for a solution to this issue, but so far, no luck. If it has already been addressed elsewhere, I apologize. Here is the code snippet I am currently working with: @{ foreach (var item in Model.Activities) ...

Group all 3 elements with a wrapper

I'm facing a challenge in trying to enclose 3 divs inside one wrapping div. I have successfully wrapped up 2 divs, but the third one is proving to be difficult. To see my progress so far, you can check out my JSFiddle here: http://jsfiddle.net/cz9eY/ ...

Creating a dropdown menu with an initial value fetched from a text file

I'm currently working on a school project that involves adjusting basic wireless parameters in a Linux router using command-line operations through an HTML interface. My experience has mostly been with PHP, and so far, I've been progressing well. ...

Is there a way to eliminate a tag that includes all attributes except for certain ones?

Here is the code I am working with: var str = `<p>paragraph<a>link</a></p> <div class="myclass"> <div>something</div> <div style="mystyle">something</div> ...

Ways to position variable width blocks so they appear to float

I'm facing an issue with floating multiple DIVs and allowing them to break out of a containing div. Below is an example of my code: <!DOCTYPE HTML> <html lang="en-GB"> <head> <meta charset="utf-8" /> <st ...

Strategies for decreasing padding or margin in Bootstrap without removing it

I am currently facing a dilemma with the grid system. Although it is supposed to be easy, I am struggling at the moment. Let's consider that I need to correctly implement the Bootstrap grid for this example: https://i.stack.imgur.com/33vse.png Initi ...

Tips for displaying HTML tags in a chatbot using JavaScript or jQuery

I'm currently working on revamping an older chatbot project I stumbled upon online. It serves as a basic "command bot" that provides specific responses based on user input. However, the chatbot is mainly text-based and does not support rendering HTML ...

Utilizing PHP to send emails via an HTML form

I spent all day attempting to send an email from my HTML contact form using PHP, but I'm struggling as a beginner. When I uploaded the form to free web hosting, I received a "success!" message upon submission, yet no actual email was sent. Any assist ...

What is the best way to display swipebox thumbnails in a grid layout instead of a single column?

I'm a novice in the world of web design and attempting to organize a group of 70 thumbnails into a grid or columns within an existing layout for a friend. Currently, they are displayed in a single lengthy column. Is there a straightforward way to adju ...

What could be causing the inconsistency in my CSS performance in IE8?

I am encountering an issue with the CSS on my website specifically in IE8. The problem lies within the CSS intended to outline input elements labeled with class="error" with a 2px red border. While this function performs as expected for some input elements ...

position: absolute is only applying to the initial item

I have a user card component with a menu button at the top that should display a menu when clicked. The issue I'm facing is that when I click on the menu button of the other user cards, the menu still shows on the first card instead of the one I click ...

Having trouble unselecting the previous item when selecting a new item in Reactjs

I have a list of items and I want to change the background color of the currently selected item only. The previously selected item should deselect. However, at the moment, all items are changing when I click on each one. Can anyone help me solve this issue ...

Unable to utilize CSS for my navigation menu

I need some help tweaking my navigation bar using CSS, but for some reason, the changes I make in the CSS file are not reflecting on the actual page. Below is the HTML and CSS code snippets: HTML: <!DOCTYPE html> <html lang=en> <head> ...