How to fix the right side spacing caused by an anchor tag after its inline image and properly align menu items

I'm currently in the process of designing a Menu bar for my website, featuring a left side logo image and right side menu items. The logo is contained within an anchor tag to allow for a clickable feature that redirects to index.html (the home page).

However, I've encountered an issue where the anchor tag is adding extra space after the image, causing two problems: 1) the hyperlink area extends too far to the right of the logo image and 2) the last menu item gets pushed onto the second line.

I've attempted various solutions, such as removing spaces between a>img>/a> or using style="display: block;", but the problem persists. How can I properly align the menu items and eliminate the excess hyperlink area to the right of the logo image?

.header_top {

    width: auto;
    max-width: 72em;
    float: none;
    display: block;
    margin-right: auto;
    margin-left: auto;
    padding-left: 20px;
    padding-right: 20px;
    margin: 0 auto;
}

.navbar {
    position: relative;
    display: flex;

}

.navbar-toggleable-md {
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    flex-wrap: nowrap;
    -webkit-box-align: center;
    align-items: center;
    margin-top: .1rem;
    margin-bottom: .1rem;
}

.bg-faded {
    background-color: #fff;
    /* padding: 1.1em 1em; */
    padding: 21px 0px;
}

.navbar-brand {
    display: inline-block;
    float: left;
    font-size: 1.25rem;
    line-height: inherit;
    white-space: nowrap;
}

.navbar-nav {

    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    padding-left: 0;
    flex-direction: row;
    margin-bottom: 0;
    list-style: none;
}

.mx-auto {
  margin-right: auto !important;
  margin-left: auto !important;
}

li.nav-item.active {
    border-bottom: 3px solid #C19506;
    background: #F5F5F5;
}
ul.navbar-nav li {
    margin: 0 6px;
}

.navbar-toggleable-md .navbar-nav .nav-link {
    padding-right: 1.1em;
    padding-left: 1.1em;
    letter-spacing: 1px;
}

.nav-link {
    display: block;
    padding: 0.5em 1em;
}

.navbar-toggleable-md .navbar-nav .nav-link {
    padding-right: 1.1em;
    padding-left: 1.1em;
    letter-spacing: 1px;
}
<!DOCTYPE html>
<html>

<head>
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">

</head>

<body>
    <header>
        <div class="header_top" id="home">
            <nav class="navbar navbar-toggleable-md bg-faded">
                <a class="navbar-brand" href="index.html">
                    <img width="37%" height="37%" src="images/Logo.png"></a>
                <ul class="navbar-nav mx-auto">
                    <li><a class="nav-link" href="index.html">Home</a></li>
                    <li><a class="nav-link" href="about.html">About</a></li>
                    <li><a class="nav-link" href="about.html">Contact</a></li>
                    <li><a class="nav-link" href="index.html">Home</a></li>
                    <li><a class="nav-link" href="about.html">About</a></li>
                    <li><a class="nav-link" href="about.html">Contact</a></li>
                    <li><a class="nav-link" href="index.html">Home</a></li>

                </ul>
            </nav>
        </div>
    </header>
</body>

</html>

Please use a 1285px x 249px image for the logo, which you can download from here as I am currently unable to upload images. One issue you may notice is that the Anchor tag takes up more width than the logo image between the logo and the first menu item 'Home'. If possible, is there a different way to add a link with the

Answer №1

Modify the width attribute of the <img> tag from a percentage value to fixed values such as 100px.

By doing this, you can eliminate the additional space issue caused by the anchor tag. However, to ensure responsiveness, you will need to adjust the width according to various screen sizes.

.header_top {
    width: auto;
    max-width: 72em;
    float: none;
    display: block;
    margin-right: auto;
    margin-left: auto;
    padding-left: 20px;
    padding-right: 20px;
    margin: 0 auto;
}

.navbar {
    position: relative;
    display: flex;
}

.navbar-toggleable-md {
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    flex-wrap: nowrap;
    -webkit-box-align: center;
    align-items: center;
    margin-top: .1rem;
    margin-bottom: .1rem;
}

.bg-faded {
    background-color: #fff;
    /* padding: 1.1em 1em; */
    padding: 21px 0px;
}

.navbar-brand {
    display: inline-block;
    float: left;
    font-size: 1.25rem;
    line-height: inherit;
    white-space: nowrap;
}

.navbar-nav {
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    padding-left: 0;
    flex-direction: row;
    margin-bottom: 0;
    list-style: none;
}

.mx-auto {
    margin-right: auto !important;
    margin-left: auto !important;
}

li.nav-item.active {
    border-bottom: 3px solid #C19506;
    background: #F5F5F5;
}

ul.navbar-nav li {
    margin: 0 6px;
}

.navbar-toggleable-md .navbar-nav .nav-link {
    padding-right: 1.1em;
    padding-left: 1.1em;
    letter-spacing: 1px;
}

.nav-link {
    display: block;
    padding: 0.5em 1em;
}

.navbar-toggleable-md .navbar-nav .nav-link {
    padding-right: 1.1em;
    padding-left: 1.1em;
    letter-spacing: 1px;
}
<!DOCTYPE html>
<html>

<head>
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">

</head>

<body>
    <header>
        <div class="header_top" id="home">
            <nav class="navbar navbar-toggleable-md bg-faded">
                <a class="navbar-brand" href="index.html">
                    <img width="100px" height="auto" src="https://media.licdn.com/dms/image/C4D12AQG20nwV6xq8lQ/article-cover_image-shrink_600_2000/0?e=1565222400&v=beta&t=-kqjXSTS6VCDVj8UX6ORuqrxKCDTR9BQwDAsycIfUio"></a>
                <ul class="navbar-nav mx-auto">
                    <li><a class="nav-link" href="index.html">Home</a></li>
                    <li><a class="nav-link" href="about.html">About</a></li>
                    <li><a class="nav-link" href="about.html">Contac</a></li>
                    <li><a class="nav-link" href="index.html">Home</a></li>
                    <li><a class="nav-link" href="about.html">About</a></li>
                    <li><a class="nav-link" href="about.html">Contac</a></li>
                    <li><a class="nav-link" href="index.html">Home</a></li>

                </ul>
            </nav>
        </div>
    </header>
</body>

</html>

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

Different methods for adjusting CSS properties that are dependent on other components

I'm currently working on a website using the React library. While I have made progress, I am stuck on how to adjust CSS properties that are interdependent. Specifically, I need help removing the blur filter from my text area .mirror-container which is ...

The XML layout to facilitate the PHP Ajax Dynamic Search

Hello everyone, I recently came across a PHP Ajax Live Search example at this link and attempted to implement it. However, I encountered difficulties with the XML structure. Can anyone provide assistance in creating the optimal XML structure for this code? ...

Shutting down the jQuery pop-up

I am struggling with trying to display this code as a popup on my website. Here is the code I have: <div id="myDialog" title="myTitle"> <div class="table_cell"> <div class="message"></div> </div> <div class="tabl ...

The issue of Bootstrap icons not displaying on the front-end arises when integrating them into a Vuejs Template

I'm in the process of constructing a web application using Vue.JS. I've integrated the [Bootstrap Icons][1] into my application, but for some reason, the icons are not showing up on the screen. Here are the steps I followed: Installed Bootstrap ...

Automatic button rotation

I managed to set up a button that works on click with a delay, making it semi-automatic. However, I'm struggling with getting it to not pause after just one click. Here's what I have so far: <!DOCTYPE html> <html> <body> &l ...

Can the current website navigation be integrated into the blog script?

People might see me as a spoil sport for not using Wordpress, but I prefer a flatfile blog system for my small site. Currently, I am using the ozjournals-3.2 blog system. I need assistance in installing a header and site navigation on top of the blog page ...

Create an unordered list using the <ul> tag

Creating a ul as input is my goal, similar to this example on jsfiddle: http://jsfiddle.net/hailwood/u8zj5/ (However, I want to avoid using the tagit plugin and implement it myself) I envision allowing users to enter text in the input field and upon hitt ...

Adjusting Image Size based on Window Width for Internet Explorer

Based on the provided code snippet <style> .x{ background: url('img.jpg') no-repeat; background-size: contain; height: 100%; } </style> <div class="x"></div> It is functioning correctly in Chrome and Firef ...

Creating an infinite loop of SVG rectangles pulled from a database

As I extract svg rectangles from a database using Python, I find myself hardcoding the process in order to change the colors of each rectangle in my CSS style sheet. With potential scalability issues in mind - if there were 100 rectangles - I am wondering ...

Clicking on text within a DIV using jQuery

How can I use jQuery to show an "alert" when text inside a DIV is clicked, excluding images and other tags? The texts are contained within various DIVs along with images and tags. Is there a way to achieve this using jQuery? Check out the jsFiddle example ...

Can HTML be transferred between browser tabs using Angular?

I'm in the process of developing a unique Angular (v17) application that allows users to drag and drop HTML elements, even across multiple browser tabs. I am inspired by the capabilities demonstrated by neo.mjs, as shown in this demo: https://www.yout ...

How can I resolve the issue with the HTML/CSS footer not functioning properly on Safari for iPhone in my mobile site?

Struggling with a mobile website issue here. The client wants text-based buttons/links at the bottom, so I added them in, but my skills with size percentages are a bit rusty. I need these buttons to line up horizontally and adjust their width accordingly ...

What is causing Firefox to consistently shave off 1px from the border of table cells?

Why is Firefox removing 1px from the border's value as defined in the CSS file? .aprovGriditem th { border-collapse: collapse; border: 4px solid #BBC6E3; padding: 0; } UPDATE <table cellpadding="0" cellspacing = "1" runat="server" id= ...

HTML tags are permitted in the contact form 7 area

Is there a way to include a contact form 7 shortcode in an HTML area that only allows HTML tags? [contact-form-7 id="2358" title="Contact Form 1"] I am trying to incorporate the 3rd slide on my website from this URL: ...

Reveal and Conceal, the ever-changing show

As I work on my blog, I want to make the layout more compact by having a link that reveals comments and entry forms when clicked. I've seen this feature on other sites as "Comments (5)", but I'm unsure how to implement it myself. Below is a snip ...

Code behind implementing a new System.Drawing.Font

Recently, I have been attempting to generate an image using the Black Rose font in c# but unfortunately, the output does not reflect the desired font. Below is the code snippet I used for creating the image: protected void Page_Load(object sender, Eve ...

Is there a way to reset the yAxes count of a chart.js chart in Angular when changing tabs?

I am currently using chart.js within an Angular framework to visually display data. Is there any method available to reset the y-axis data when changing tabs? Take a look at this Stackblitz demo for reference. Upon initial loading of the page, the data ...

Using antd icons in CSS pseudo-elements effectively involves leveraging the ::before or ::after

Currently, I have an icon displaying like this: import { Icon } from "antd"; ... // within a react component: <div className="someclass"> <Icon type="thunderbolt" /> </div> What I really aim to achieve i ...

Issue with form submission using getElementById

I am struggling to submit a form that is generated by PHP echo. The getElementById function doesn't seem to be functioning properly. <?php include 'connect.php' ; $sql=mysql_query("SELECT mess_id,receiver,subject ...

Implementing a download hyperlink attribute for a button with jQuery

How can I create a jQuery function for a button? <input type="submit" id="submit"></input> Once clicked, it should trigger the following action: <a download href="file.doc"></a> <script> $("#submit").click(function(){ ...