The excessive width of the navigation bar resulted in additional blank space on the right side of

My navigation bar is causing me trouble as it appears to be too wide, creating extra space on the right side. I've tried adjusting the width with some code, but as I'm working on making the site responsive, shrinking the code down to around 320px results in the text being too small and difficult to interact with. Oddly enough, it looks fine when I test it on my local computer, but once it's on a server and viewed on my phone, it looks terrible. Has anyone encountered this issue before or can offer insight into what I might be doing wrong? JSFiddle

HTML5

<div id="header-banner">
    <div class="wrapper">
        <header>    <a href="index.html">
            <img id="logo" alt="PT Logo" src="Images/PT-logo.png"></a>

            <nav id="main-nav">
                <ul id="nav">
                    <li><a href="index.html">Home</a>
                    </li>
                    <li><a href="#">CityName</a>
                    </li>
                    <li><a href="#">CityName</a>
                    </li>
                </ul>
            </nav>
        </header>
    </div>
</div>

CSS3

/* ===== HEADER NAVIGATION AREA ===== */
 #main-nav {
    position: relative;
    left: 50%;
    bottom: 20px;
    height: 40px;
    background-color: blue;
}
#nav {
    list-style: none;
    margin: auto;
}
#nav li {
    float: left;
    display: inline;
}
#nav li a {
    color: #DB7093;
    display: block;
    padding: 3px 15px;
    height: 20px;
}
#nav li a:hover {
    background-color: #DB7093;
    color: #F0F8FF;
    text-shadow: none;
}

Answer №1

Consider removing the margin:auto and modifying padding: 3px 15px to padding: 3px 1px to troubleshoot your issue.

Here's a possible solution:


#main-nav {
    position: relative;
    left: 50%;
    width:350px;
    bottom: 20px;
    height: 40px;
    background-color: blue;
}

Make sure to include the width property in your #main-nav.

Answer №2

Check out this JSFiddle example: http://jsfiddle.net/8K2bL/

/* Styles for mobile - adjusting logo and navigation */
@media only screen and (max-width: 649px) {
#logo{display:block !important;}
#main-nav{
    margin:0 auto !important;
    bottom:auto !important;
    right:auto !important;
}
header{
    width:320px !important;
    margin:0 auto;
}
}

#logo{
width:auto;
height:100%;
display:inline;
}
header{
height:100px;
width:100%;
position:relative;
}

/* Styling for header navigation */
 #main-nav {
float:right;
position:absolute;
bottom:0;
right:0;
}

Answer №3

Consider improving the organization of your HTML code. I enhanced your JS Fiddle by restructuring the HTML, incorporating new classes, and making adjustments to the existing #main-nav. You can view the updated version in this JS Fiddle link

Additionally, I suggest exploring Bootstrap for creating responsive CSS layouts

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

The <link> element in the HTML file referring to the stylesheet {% static 'css/style.css' %} is not functioning properly

I am having trouble aligning text to the center in VS Code when linking CSS to HTML. The 'center-aliend' property doesn't seem to work for me. Can someone point out what I might be doing wrong? I am trying to position the text 'Hello St ...

Organizing your thoughts: Utilizing Etherpad-Lite's list

Looking to stylize the list items with decimal, upper-alpha, lower-alpha, upper-roman, and lower-roman for each of the first five levels? I attempted to achieve this by adding CSS in my pad.css file. .list-number1 li:before { content: counter(first)") " ...

Numerous options available in a dropdown menu

I have a Dropdown menu that offers various functions. "Update" option redirects to a page for updating information "Export Form" option redirects to a page for exporting the form Although the current code allows these actions, I am facing an issue with ...

Centered content appears smaller than the surrounding div

After spending an hour trying to troubleshoot and searching for solutions, I am turning here for help. I am attempting to insert a Bootstrap Nav-Bar into a Div. I successfully centered the Nav-Bar, but now my Div is taller than the content inside it. This ...

Conceal and reveal text with a simple user click

Currently, I am working on a website project that utilizes bootstrap. However, I am facing some uncertainty regarding how to effectively hide and display text: <nav class="navbar navbar-light" style="background-color: #e3f2fd;"> ...

Tips for loading and updating data simultaneously in VUEJS from a single input

Currently, the data is displayed in a span tag with an input for updating it Is it possible to fetch data from an API, load it into an input field, update the input with new information, and send it back? What are the best approaches for achieving this? ...

Leveraging Bootstrap grid system within AngularJS elements

I am currently working on wrapping grid element divs into Angular components in order to streamline the input process and establish a standard: <bootstrap-row> <bootstrap-input-text col=6 ng-model="$ctrl.model" label="hey!"& ...

Issue with distinguishing JavaScript code from an SVG file

Seeking assistance as I have an SVG file that is mostly composed of a script. My goal is to separate the script for compression purposes, but I am struggling to find a way to achieve this. Any guidance or help on this matter would be greatly appreciated. ...

Enhance functionality in JavaScript by accessing the return value from a function

I'm trying to achieve the same outcome using a different method. The first approach is functioning correctly, but the second one is not: <script> function hello(){ var number = document.getElementById("omg").innerHTML; if(numbe ...

The Vue/Vuetify wrapper component does not automatically pass on the `hide-details` parameter to the input component

I recently crafted a custom wrapper for the v-select input using Vuetify. Along with custom properties, I utilized the v-bind="$props"attribute to inherit all props. Upon testing, I observed that while this method applies to most props, it doesn ...

Loading necessary CSS when needed in React JS

I am currently in the process of converting a bootstrap template to react framework. My question is, is there a way for me to load stylesheets on demand? For instance, if I have 2 components and I import the same stylesheet separately in both components, ...

Steps for generating instances of an HTML page and dynamically adding them to a list on the main page

I have a main HTML page and I need to insert a dynamically generated list from a template in another HTML file that I created. The template for each item in the list is located on a separate HTML page. My goal is to create multiple instances of this HTML ...

How can I incorporate classes from multiple CSS files into my WordPress theme?

Currently, I am utilizing wp_enqueue_style to incorporate two CSS files within a single function. However, the issue that arises is when I try to apply a class, it seems that only classes from one of the files can be utilized and it ends up overriding anot ...

Having trouble with sending a POST request to a URL?

I'm attempting to communicate with an API by including the parameters in the URL. I am uncertain whether it will return XML or JSON, but it will be one of the two. Unfortunately, I keep encountering an error message. Here's an example of my requ ...

How to extract text from outside a tag using Selenium in Python3 with Chrome?

I am having trouble extracting text from outside of a tag. Currently, I am working with Python3.7 and I have experimented with both Selenium and BeautifulSoup4. Below is the HTML snippet I am dealing with: <br> <span class="label">Max. Allo ...

When errors occur while printing HTML through an Ajax request, it can hinder the functionality of other JavaScript code

I recently conducted an interesting experiment on my website. The concept involved sending an AJAX request to a PHP file, which then retrieved a random website by using various random words for search queries on Google. The retrieved website content was th ...

Content overflowing beyond the boundaries of the parent DIV in Internet Explorer 6

Take a look at the code snippet below: <div style="width: 50px; border: 1px solid green;"> <div style="position: absolute;"> add whatever text you'd like </div> </div> The display in modern browsers (such as I ...

How can you prevent a draggable element from surpassing the bottom of the screen?

I'm dealing with an element that I want to make draggable only along the Y-axis. It needs to be able to go past the top of the screen, but I need to restrict it from going past the bottom of the screen. I recently came across the containment feature i ...

Adding a PHP script alters the way content is displayed in a web browser

Forgive me for what may seem like a trivial question, but I have been searching for hours without any luck. It appears that including more than one file in an already included file is causing a minor change to the page layout. The issue manifests as a sli ...

Extracting information from several span elements within the main span class using BeautifulSoup

I'm currently attempting to extract data from the following HTML code: <span class="double-line-ellipsis"> <span> ₹ 2800 for 2 (approx) </span> <span> | </span> <a data-w-onclick="stopClickPropagation|w1-re ...