How come there is such a large space for clicking between my logo and the navigation bar, and what can be done to eliminate it?

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

ul {
  list-style-type: none;
}

.nav-links,
.logo {
  text-decoration: none;
  color: #000;
}

.logo {
  max-width: 80%;
  width: 20%;
  height: 20%;
}

.navbar img {
width: 10%;
height: auto;
display: in-line block;
}

.navbar {
  padding: 20px;
  height: 50vh;
}

.navbar,
ul {
  display: flex;
  flex-direction: row;
}

ul li {
  padding: 0 5px;
}

.wrapper {
  display: flex;
  justify-content: space-between;
  width: 100%;
}
<nav class="navbar">
  <a href="#"><img src="https://cdn.discordapp.com/attachments/714128376884887644/783384657366482954/Double20Hospital20Doors20push20plate20and20kickplate.png" alt=""></a>
  <div class="wrapper">
    <ul class="main-nav" id="js-menu">
      <li>
        <a href="#" class="nav-links">Home</a>
      </li>
      <li>
        <a href="#" class="nav-links">Products</a>
      </li>
      <li>
        <a href="#" class="nav-links">About Us</a>
      </li>
    </ul>
    <ul class="ul2">
      <li>
        <a href="#" class="nav-links">Contact Us</a>
      </li>
      <li>
        <a href="#" class="nav-links">Blog</a>
      </li>
    </ul>
  </div>
</nav>

Above is the code snippet provided. There seems to be a large gap between the image and the navigation links highlighted below:

https://i.sstatic.net/YwE7L.png

Additionally, it appears that the white space is clickable. The goal is to eliminate this gap so that the layout resembles the following image (maintaining the spacing between 'About Us' and 'Contact Us' but removing the space between the image and 'Home'):

https://i.sstatic.net/fS0Oy.png

Attempts have been made to remove padding and adjust the logo placement within the list, but the issue persists.

Answer №1

To optimize image display, specify size based on height, like this:

img {
   height: 30px;
   width: auto;
}

You can view a live example here

Answer №2

Experiment with adjusting the Image width to a specific number of pixels rather than a percentage, as shown in the snippet below:

.navbar img {
width: 50px;
}

Answer №3

From my observation, it seems that you are attempting to select a class called "logo" in your CSS stylesheet. However, upon reviewing your HTML code, I didn't find any instance of a class named 'logo'.

Answer №4

Here is the updated code snippet as requested in the comments:

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

ul {
  list-style-type: none;
}

.nav-links,
.logo {
  text-decoration: none;
  color: #000;
}

.logo {
  max-width: 80%;
  width: 20%;
  height: 20%;
}

.navbar img {
  width: 10%;
  height: auto;
  display: inline-block;
}

.navbar {
  padding: 20px;
  height: 50vh;
}

.navbar,
ul {
  display: flex;
  flex-direction: row;
}

ul li {
  padding: 0 5px;
}

.wrapper {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.nav-logo{
  text-decoration: none;
  color: #000;
  padding-left: 10px;
}
<nav class="navbar">
  <a href="#"><img src="https://cdn.discordapp.com/attachments/714128376884887644/783384657366482954/Double20Hospital20Doors20push20plate20and20kickplate.png" alt=""></a>
  <div class="wrapper">
    <ul class="main-nav" id="js-menu">
      <li>
        <a href="#" class="nav-links nav-logo">Home</a>
      </li>
      <li>
        <a href="#" class="nav-links">Products</a>
      </li>
      <li>
        <a href="#" class="nav-links">About Us</a>
      </li>
    </ul>
    <ul class="ul2">
      <li>
        <a href="#" class="nav-links">Contact Us</a>
      </li>
      <li>
        <a href="#" class="nav-links">Blog</a>
      </li>
    </ul>
  </div>
</nav>

Answer №5

To achieve the desired effect of having the image 10% inside the <a> tag, you need to ensure that the difference between the <a> tag and the <img> tag is 90%. This can be accomplished by either converting the percentage to pixels or adjusting the percentage values on the <a> and <img> tags.

.navbar img {
  width: 100%;
  height: auto;
  display: in-line block;
}

.navbar a {
  width: 10%;
}

If you find that your HTML/CSS is becoming too complex, you can simplify it by following this approach:

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

.navbar {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.leftbar, .rightbar {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 40%;
}

.rightbar {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 16%;
}

.navbar img {
  width: 100%
}

.navbar a {
  width: 20%;
}

.nav-links {
  text-align: center;
}
<nav class="navbar">
  <div class="leftbar">
    <a href="#"><img src="https://cdn.discordapp.com/attachments/714128376884887644/783384657366482954/Double20Hospital20Doors20push20plate20and20kickplate.png" alt=""></a>
    <a href="#" class="nav-links">Home</a>
    <a href="#" class="nav-links">Products</a>
    <a href="#" class="nav-links">About&nbsp;Us</a>
  </div>
  <div class="rightbar">
    <a href="#" class="nav-links">Contact&nbsp;Us</a>
    <a href="#" class="nav-links">Blog</a>
  </div>
</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

Avoiding the overlap of sub-menu items vertically

My nested unordered list acting as a sub-menu has an issue with overlapping list items. It seems like the padding of the links is causing the overlap: ul { padding: 12px 0; list-style: outside none none; } li { display: inline-block; margin-righ ...

Unable to expand the dropdown button collection due to the btn-group being open

Having trouble with the .open not working in Bootstrap 4.3 after adding the btn-group class to open the dropdown... I am looking for a way to load the dropdown without using JavaScript from Bootstrap. This is the directive I am trying to use: @Host ...

Creating a responsive navigation menu using Bootstrap 4 by merging data from various MySQL tables

I am struggling to create a bootstrap 4 nav-menu using the provided SQL query and code snippets. Below are the tables: TABLE menu -------------------------------------- | id | title | url | | 1 | Home | index.php | | 2 | M ...

Naming conventions for initial layout DIVs: Best approaches

As a beginner in the realm of website design, I find myself at the early stages of constructing an HTML/CSS site based on a sketch I've created. In planning out the DIVs for the homepage, I am faced with questions about how to label them and determine ...

Encountered an issue when attempting to select the password field in order to log into a Google account using

Having some trouble automating the login process for my Gmail account. Managed to find the email element with an ID, but hitting a roadblock trying to locate the Password element as it doesn't have an ID. Here's what I've attempted: passw ...

Unique design Radio Button Inputs with Custom CSS Styling and Enhanced Accessibility for Voice Controls

On my website, I have implemented custom radio buttons using this model: The custom radio buttons are working well with various browsers and are accessible with Jaws. However, I encountered an issue when trying to use Voice Over as the radio button canno ...

Challenges with dynamically adding rows using jQuery

I am trying to create a dynamic form that allows users to select a project and then populates tasks based on the selected project from a database query. The user can then enter hours for each task, which are updated based on the project id and task id comb ...

What is the best way to design unconventional grids using Bootstrap 4?

Is it possible to achieve unique grid layouts in Bootstrap 4? For instance, An irregular grid where the first column covers two rows, followed by two rows with three columns each |||||||||||||||| | | | | | | |_ |_ |_ | | | | | | |_____| ...

Utilizing two visuals within the <picture> srcset

Is there a way to include two images on the desktop version (one on the right and one on the left) within the picture tag that replaces the mobile version image? I attempted it but it didn't work as expected. <picture> <source medi ...

How can you use JavaScript to create hyperlinks for every occurrence of $WORD in a text without altering the original content?

I've hit a bit of a roadblock. I'm currently working with StockTwits data and their API requires linking 'cashtags' (similar to hashtags but using $ instead of #). The input data I have is This is my amazing message with a stock $sym ...

Nesting CSS classes allows for more specific targeting of

I am a bit rusty on CSS, it's been about 5-7 years since I last worked with it. Could someone help me come up with a solution to my problem? Here's the ideal design I have in mind: table.ctable { class:collapsible collapsed; } I know this syn ...

What is the best way to change the date format from "yyyy-MM-dd" in a JavaScript file to "dd/MM/yyyy" and "MM/dd/yyyy" formats in an HTML file?

Is there a way to transform the date string "2020-08-02" from a JavaScript file into the formats "08/02/2020" and "02/08/2020" in an html file, without relying on the new Date() function in JavaScript? I would greatly appreciate any assistance with this t ...

Tips for displaying the contents of a URL within a div element

Is there a way to load a new page into a <div></div> without opening a separate tab? I tried using an iframe, but that method is not recommended and it includes scroll bars. <div id="iframeLogin"><a href="first.php" target="_self"> ...

The width of table columns is altered upon the second rendering in JQuery DataTables

Is there a way to prevent JQuery DataTables cells from extending width after adding hyperlink to cell? I am facing an issue where I have two tables on the same page. The first table column has a link which populates the second table. It works fine when th ...

What steps should be followed to display an HTML page within an HTML div?

The question I have is a bit misleading, as I'm not looking for guidance on how to open an HTML document in a div. Rather, I am currently facing an issue where I am unable to replace the HTML file that I have already placed in a div. Initially, I pla ...

Creating a personalized audio player using HTML

I have created a design for an audio player that I would like to implement using the HTML audio player element. https://i.sstatic.net/vJpGg.jpg When I tried <audio></audio>, it just displayed the default player: https://i.sstatic.net/nyNj8.j ...

Utilizing JavaScript in Protractor, explore a list to identify the selected checkboxes and those that remain unchecked

Currently, I am working on developing an end-to-end test using Protractor. My main objective is to extract the names from a list and then determine which checkboxes have been selected and which ones haven't. To check the state of the checkbox, I pla ...

Modify the color of an Ionic button for a single button, rather than changing the color for all buttons

How can I modify this code so that only the clicked button changes its color, not all of them? Here is the current code: .html: <ion-col size="6" *ngFor="let data of dataArray" > <ion-card> <ion-card-header> ...

Submitting the form may cause disruptions for others

I currently have an email subscription form for my newsletter that is managed through PHP. This form appears in the footer of every page on my website. Check out a demonstration on JSFIDDLE While the form itself functions properly, I am encountering issu ...

Adaptable data table featuring varying sizes of columns and rows

I'm attempting to design a grid that resembles the following: https://i.sstatic.net/Sf7M9.png The challenge I'm facing is how to ensure that the column and row names adjust properly with the grid in the center. Currently, this is the code I hav ...