How come my menu items are crammed together on a small screen?

My menu items are displaying properly on a large screen using CSS grid, but they overlap on a small screen. What could be causing this issue and how can I resolve it?

I have included the CSS code here, and you can access the full source code (HTML and CSS) by clicking the link below.

Full source code: http://jsfiddle.net/x89Lop5t/

The CSS code snippet is as follows:

*{
  box-sizing:border-box;
}
body {
  background-color:#003EBB;
}
 /*styling the css grid container */
.container{
  display:grid;
  grid-template-columns: repeat(6 , 1fr);
  grid-auto-row: 150px;
  grid-gap:20px;
  align-items: center;
  grid-template-areas:
    ". . . . . mh"
    ". . nv nv nv ."
}

/*end of css grid container */


/*styling the grid items */
.miniHeader{
  grid-area:mh;
}
.miniHeader ul li{
  display:inline;
  margin-left:20px;
  list-style:none;
  margin-top:1px;

}


.miniHeader ul li a{
 text-decoration: none;
 color:white;

}

nav{
  grid-area: nv;
}

nav ul li{
  display:inline;
  border: 1px solid  white;
  border-radius: 10px;
  padding:10px;
  margin-left: 5px;

}

nav ul li a{
  color:white;
  padding:20px;
  text-decoration:none;

}

Answer №1

To enhance your navigation, it is recommended to use display:inline-block instead of display:inline. The latter should be used for styling inline elements only.

* {
  box-sizing: border-box;
}

body {
  background-color: #003EBB;
}


/*styling the css grid container */

.container {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-row: 150px;
  grid-gap: 20px;
  align-items: center;
  grid-template-areas: ". . . . . mh" ". . nv nv nv ."
}


/*end of css grid container */


/*styling the grid items */

.miniHeader {
  grid-area: mh;
}

.miniHeader ul li {
  display: inline;
  margin-left: 20px;
  list-style: none;
  margin-top: 1px;
}

.miniHeader ul li a {
  text-decoration: none;
  color: white;
}

nav {
  grid-area: nv;
}

nav ul li {
  display: inline-block;
  border: 1px solid white;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 5px;
  margin-left: 5px;
}

nav ul li a {
  color: white;
  padding: 20px;
  text-decoration: none;
}
<div class="container">
  <div class="miniHeader">
    <ul>
      <li><a href="#loginsection">Login</a></li>
      <li><a href="#regsection">Register</a></li>
    </ul>
  </div>
  <nav>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Map</a></li>
      <li><a href="#">Contact Us</a></li>
    </ul>
  </nav>
</div>

Answer №2

Opt for display:inline-block over display:inline.

 nav ul li{
 display:inline-block;
 border: 1px solid  white;
 border-radius: 10px;
 padding:10px;
 margin-left: 5px;
 }

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

Autonomous boundary for list elements

I have a specific issue that can be observed in this fiddle: http://jsfiddle.net/h0qu4ffv/ where I set the margin-top of one list item to 50px, but all list items end up following this style. Is there a way to give each list item an independent margin, or ...

Displaying an element outside with reduced opacity using fabric js and controls placed above overlay

The property controlsAboveOverlay in Fabric.js is a boolean that, when set to true, will display the controls (borders, corners, etc.) of an object above the overlay image. The overlay image is an image that can be placed on top of the canvas. Currently, ...

JavaScript Application - Problem with Universal Windows Script

I recently built a website utilizing material design lite for the aesthetics: Here are the scripts included: <script src="./mdl/material.min.js"></script> <script src="Scripts/angular.min.js"></script> The necessary .css fi ...

Creating a see-through backdrop without the need for a background image

How can I create a div with a transparent background? I attempted to use background-color and opacity, but unfortunately, the border and text inside also became transparent. Check out an example here. Is there a way to achieve this without relying on a tr ...

The hamburger symbol on my website is failing to show the menu options

I'm having trouble getting my burger icon to display the navigation menu on mobile devices. I've tried adjusting functions in my JavaScript and tweaking the media queries in my CSS file, but the menu still won't show up when the page size is ...

Steps to apply styles to an iframe element directly from its inner HTML code

Looking for help with this line of code: <iframe src="http://www.google.com" name="google" style="Z-INDEX: 0; MARGIN-TOP: -1px; WIDTH: 100%; HEIGHT: 1070px"> <html> <head></head> <body> < ...

Incorporating a touch of dark opacity into an image

Check out the layout of my webpage here: https://i.sstatic.net/Ap4nx.jpg The background image I used is this one: https://i.sstatic.net/dIhLt.png I am trying to achieve a black transparent overlay on the image, similar to this: https://i.sstatic.net/FMdi ...

The background image on my screen seems to be malfunctioning and not displaying properly

I'm facing an issue with setting an image as the background of the banner section on my website. Despite trying various solutions and researching similar problems, I haven't been able to resolve it. Specifically, I am attempting to set the backgr ...

in tailwind, the position transition does not work as expected

I have a React component that I'm working on: function DivModal() { const [isOpen, setIsOpen] = useState(true) return ( <div> <button onClick={() => setIsOpen(prev => !prev)} className={buttonStyle}>Open</button> ...

Tips for designing a unique custom scrollbar

I'm in need of some CSS expertise to help me create a custom scroll bar that resembles the one shown in the image. The key requirement is for the background to be transparent, although I've temporarily positioned it against a green backdrop. ...

Does li behave like a separate element from p when it comes to pseudo-class assignments?

While experimenting with multiple pseudo-classes assignments involving p and li content, I made an interesting observation. It seems that adding an extra line of text can sometimes disrupt the pseudo-class assignments. For example, in the code provided be ...

buttons are arranged horizontally, stacked neatly on top of one another

I'm currently working on a setup for toggle buttons using absolute positioning for labels on top of checkboxes. My goal is to have them aligned horizontally, but instead, they are stacking on top of each other. <ul style="display: block; float: le ...

Why using the display:none property does not successfully conceal Struts 2 tags such as <s:textfield>

I am curious as to why the div tag is unable to hide the Struts2 tags. I have set up a div that should be hidden on load, and using onChange, I am triggering jQuery to toggle the visibility of the div tag... <%@ taglib prefix="s" uri="/ ...

Ways to Create a Webpage with a Single Color Palette

Struggling to update the background color on my webpage and hitting a wall. Even with content, the black background only extends as far as the content does. I've experimented with extending the content, using the body selector, and universal selector ...

Using JavaScript to create CSS animations triggered on hover

Looking for a CSS Animation that will play forward once when the mouse enters a specific div, and then play in reverse when the mouse leaves. Check out my JsFiddle here. The div with the class ".item" should trigger the mouse enter event. The animation co ...

I am experiencing issues with CSS functionality in my Ruby on Rails application

Currently, I am in the process of creating a blog based on Mackenzie Child's 12 in 12 RoR tutorials. I diligently followed all the steps in the tutorial and adhered strictly to his code. However, I encountered an issue with the CSS stylesheets not be ...

Ensure that the height of the bootstrap image is limited by the dimensions of another column while still preserving its

I need to develop a versatile element with bootstrap that can accommodate images of different aspect ratios. To achieve this, I must trim the right side of the picture like so. <div class="container"> <div class="row"> <div class="col-12" ...

Develop rounded edges for a div element

I am interested in developing an HTML-based chart similar to the one shown below, but I am unsure of the steps to take. https://i.sstatic.net/2jLPO.png ...

Overlap of Bootstrap Columns Occurs When Resizing the Browser

While I recognize that this issue is common, I have extensively reviewed similar questions but could not find a solution. <div class="container"> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-6"> <img style="wi ...

Resize background image to perfectly fit within div dimensions

One of my divs has a background image that is getting clipped: <div style='text-align:center;background-image: url(/media/img_1_bg.jpg);background-repeat:no-repeat;width:450px;height:900px;' id="mainpage" align="center"> Is there a soluti ...