Adjustable centralized menu with buttons that resize accordingly

I am currently working on making a webpage responsive. I have successfully created a logo div that resizes accordingly. Now, I am facing a challenge with centering the buttons in the menu list. Despite my efforts, the buttons are not aligning in the center as I intended, especially on larger screen sizes.

@charset"UTF-8";

/* CSS Document */

/*General*/

#wrapper {
  width: 100%;
  height: 100%;
  margin: 0px auto;
}
header {
  padding-bottom: 8%;
  width: 100%;
  height: auto;
  background-color: #88d9ce;
}
#logo {
  text-align: center;
  padding-top: 10px;
}
#logo img {
  min-width: 100px;
  max-width: 15%;
  height: auto;
}
#menu {
  text-align: center;
  margin-left: -25px;
  width: 100%;
}
ul {
  list-style-type: none;
}
li {
  float: left;
  width: 17%;
  height: auto;
  margin-right: 3%;
}
li img {
  min-width: 60px;
  max-width: 50%;
  height: auto;
}
<body>
  <div id="wrapper">
    <header>
      <div id="logo">
        <img src="http://i61.tinypic.com/13yebnr.jpg" />
      </div>
      <div id="menu">
        <ul>
          <li>
            <img src="http://i60.tinypic.com/5f0pd4.png" />
          </li>
          <li>
            <img src="http://i59.tinypic.com/2cx6xqs.png" />
          </li>
          <li>
            <img src="http://i58.tinypic.com/veu6o1.png" />
          </li>
          <li>
            <img src="http://i61.tinypic.com/24ebywg.png" />
          </li>
          <li>
            <img src="http://i62.tinypic.com/71r8ut.png" />
          </li>
        </ul>
      </div>
    </header>
  </div>
</body>

Answer №1

To center your list items, you can use display:inline-block along with text-align:center. Adding font-size:0px to the ul removes any extra spacing. Remember to set the font size on the list items if they contain text.

Check out the DEMO: https://jsbin.com/xudaz/1/

   <div id="logo">
      <img src="http://placehold.it/300x100/000000/FFFFFF&text=LOGO" />
    </div>
   
    <ul id="menu">
       <li><img src="http://placehold.it/60/B7AF90/FFFFFF&text=1"/></li>
       <li><img src="http://placehold.it/60/B7AF90/FFFFFF&text=2"/></li>
       <li><img src="http://placehold.it/60/B7AF90/FFFFFF&text=3"/></li>
       <li><img src="http://placehold.it/60/B7AF90/FFFFFF&text=4"/></li>
       <li><img src="http://placehold.it/60/B7AF90/FFFFFF&text=5"/></li>
    </ul>
  

CSS:

#logo {
    text-align:center;
    padding-top:10px;
}
#logo img {
    min-width:100px;
    max-width:15%;
    height:auto;
}

#menu {
    list-style-type:none;
    padding:0;
    font-size:0px;
    white-space:nowrap;
    min-width:240px;
    text-align:center;
    width:100%;
    max-width:980px;
    margin:0 auto;
}
#menu li {
    display:inline-block;
    box-sizing:border-box;
    border:1px solid red;
    width:17%;
}
#menu li img {
    height:auto;
    width:100%;
    max-width:60px;
}

Answer №2

Here's a different perspective on the concept of "answers" by focusing on the use of text instead of images. Using images for navigation can sometimes result in a fuzzy appearance on high-density screens, while making links too small can be difficult to tap on mobile devices. This example demonstrates a more responsive and user-friendly approach.

DEMO: https://jsbin.com/fafeya/1/

CSS

body,
html {
    background: #88d9ce;
    padding: 0;
    margin: 0;
}
.logo {
    width: 100px;
    height: 100px;
    background: yellow;
    margin: 3% auto;
    border-radius: 50%;
    box-sizing:border-box;
    border:5px solid #000;
}
#nav {
    text-align: center
}
#nav a {
    background: #9cf2e6;
    display: inline-block;
    color: #000;
    text-decoration: none;
    font-size:14px;
    font-family:monospace; /* see google fonts too or typekit etc */
    padding: 5px 20px 3px;
    box-shadow: 4px 4px 0px 0px rgba(50, 50, 50, 0.5);
    transform: rotate(2deg) skew(2deg);
    margin: 5px 3%;
}
#nav a span {
    transform: rotate(-2deg) skew(-2deg);
    display: block;
}
#nav a:nth-child(even) {
    transform: rotate(-2deg) skew(-2deg)
}
#nav a:nth-child(even) span {
    transform: rotate(2deg) skew(2deg)
}

HTML:

<div class="logo"></div>
  
  
<nav id="nav">
  <a href="#"><span>Link</span></a>
  <a href="#"><span>Link</span></a>
  <a href="#"><span>Link</span></a>
  <a href="#"><span>Link</span></a>
  <a href="#"><span>Link</span></a>
</nav>

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

Issue with importing CSS in Pug-Template

Looking to develop a Website using node.js and express with Pug as the template language, incorporating Bootstrap CSS. However, encountering an issue where Pug is not importing my custom CSS but is successfully importing Bootstrap CSS. Experimented with d ...

Manipulate inherited CSS styles from an external source

Currently, I am working on creating a pagination using the NG-Bootstrap pagination component. However, I encountered an issue where I need to modify or specifically remove some CSS properties that are applied by default in the NG-Bootstrap library. Is ther ...

jQuery User interface smooth scrolling feature

When my jQuery UI dialog is minimized, it moves to a container on the left side. How can I implement a custom jQuery UI scrollbar for that container? I attempted this approach, but only received the default bland scrollbar: #dialog_window_minimized_con ...

Tips for updating the left positioning of a Div element on the fly

Although my title may not fully explain my goal, I am dealing with dynamically created div elements. When a user triggers an ajax request to delete one of the divs, I want to remove it from the DOM upon success. The issue arises in adjusting the layout aft ...

Adjust the Font Size of Bootstrap 3 across different breakpoints

I am currently using Bootstrap 3 and I have a requirement to adjust the font-size at different breakpoints across my website. My goal is to easily modify the font size in one place and have it automatically apply to all Bootstrap components. The desired b ...

Managing field placement as the table height grows: tips and tricks

I am encountering an issue with my dynamic form. When I click on the add button, a new row is added to the table. However, once there are more than 6 rows added, the table height starts covering the fields. How can I go about setting this so that the field ...

How can we prevent floating li elements from overlapping the parent div element?

What could be causing the yellow stripe (#header) to disappear when I apply "float left;" to "#header ul li"? Despite setting a fixed size for "#header ul li", I anticipated that the list items would line up next to each other horizontally, not exceeding t ...

Attempting to align three sections horizontally

I'm having trouble with my current HTML code and I can't seem to figure out what the issue is. As a beginner in HTML, I am struggling to understand. My goal is to have three columns: one on the left taking up 20% of the space, one in the center t ...

Apply a class to every group of x elements

In order to style the products displayed on a product list page, I have an unknown amount of divs, with each row containing 4 divs for individual products. My goal is to apply a specific CSS class to the first div in each row, then another class to the sec ...

Clicking the button will remove any previously applied CSS style using jQuery

Is there a way to remove the background color that was applied to a previously clicked button when clicking on another button? The current code successfully changes the background color of the clicked button upon hover, but it doesn't reset or remove ...

Banner Text Alignment Issue: Uneven Left Alignment

Struggling to achieve consistent text alignment on a ribbon banner? Check out the issue I'm facing and see if you have any suggestions on fixing it: Link to Codepen Main issues: The first line of text appears slightly more indented on the left side ...

Verifying CSS updates with Capybara detection

I'm in the process of developing a web application that dynamically changes its CSS styles based on user input. Everything is working smoothly, but I'm facing an issue with my automated tests not confirming whether the CSS updates are actually ta ...

At what point do browsers decide to round pixel fractions to whole pixels, and when do they choose not to do

I recall reading here on SO that using pixel fractions in CSS is generally advised against because browsers tend to round them to the nearest whole pixel. As shown in the example below, 0.3 pixels are indeed rounded to a full pixel: span { border: 0. ...

Issues with Bootstrap glyphicon not functioning correctly on mobile devices and Internet Explorer

Within my template, there is a navigation button positioned on the left side of the page that remains fixed as the user scrolls down. When clicked, this button triggers a menu to appear. Embedded within this button is a bootstrap glyphicon: <div class ...

What's the best way to add animation to the send icon while hovering over the button?

<div class="text-center"> <button [disabled]="btnStatus" class="btn btn-secondary buttonSend" type="submit"> <div [hidden]="btnStatus"> Send Message&nbsp;&nbs ...

Merge multiple list groups into one with a single active selection using Bootstrap List group functionality

Currently, I am experimenting with merging Bootstrap's accordion and list group with JS behavior. My goal is to create a set of list groups where only one option can be active at a time within each accordion. <link rel="stylesheet" href="https:/ ...

The shadow is obscured by a block that has an 'overflow: scroll' property

One block on the left displays the list, while another shows detailed information with a shadow effect. The issue arises when the left block has 'overflow: scroll', causing elements' backgrounds to spill over the shadow. .div-left { flo ...

Is it necessary to install only form control styles from Bootstrap 4?

Does Bootstrap 4 offer a way to only install the form control styles like input group? I came across a resource that allows you to solely install the Bootstrap 4 Grid. Is there anything similar for downloading just the form styles? ...

Having trouble with the contact form? It seems to be experiencing issues with

Hey there! I'm encountering an issue with the following codes, where I'm getting redirected and receiving an error message stating "Undefined variable: subject in C:\wamp\www\boot\send.php on line 42." Any help would be greatl ...

Searching for columns should be at the top of an angular datatable, not at the bottom

In my Angular 7 project, I am utilizing the library found at this link. I have followed the example provided, which can be seen here. Everything is working perfectly, except for the position of the search columns. I would like the search columns to appear ...