My navigation bar is giving me a bit of trouble, as there are two separate issues that seem to be interconnected

Looking for some help with my navigation bar layout. You can also check out the code on fiddle http://jsfiddle.net/SgtRx/ (should have done this earlier, sorry).

I'm a beginner when it comes to coding, so please bear with me if I make any mistakes.

The issue I'm facing is that when I add borders to separate each block in the navigation bar, it creates a small whitespace at the end of the nav bar on the right-hand side.

The wrapper Div is set at 1000px width and there are 5 buttons, each 200px wide. Without borders, they fit perfectly, but adding borders messes up the alignment. If I keep the width at 200px, the nav bar shifts down. And when I reduce the width, it leaves white space on the right. I've been trying to fix this for 2 days now and I need some help. Thanks.


    <body>
    <div id="wrapper">
    header id="top">
    <div id="test">
    <img src="images/vintage.jpg" width="1000" height="605" table width="780" order="0" align="center" cellpadding="0" cellspacing="0"/>

    <nav id="mainnav">
    <ul>
    <li><a href="index.html" class="noBorder" >Home</a></li>
    <li><a href="sightseeing.html">Sightseeing</a></li>
    <li><a href="#">Eating Out</a></li>
    <li><a href="#">What's On</a></li>
    <li><a href="#">Test</a></li>
    <li><a href="#">Test1</a></li>
    <li><a href="#" class="noBorder1">Where to Stay</a></li>
    </ul>
    </nav></div>
    </header>

And here's the CSS:


    #mainnav ul {
        margin-top: auto;
        margin-bottom: auto;
        padding: 0;
        display: block;
        float: left;
        width: 1000px;
        list-style-type: none;
        position: relative;
    }

    /* Styling links inside navigation */
    #mainnav a {
        width: 197px;
        display: block;
        float: left;
        text-align: center;
        background-color: #020202;
        color: #FCFCFC;
        text-transform: uppercase;
        line-height: 290%;
        border-radius: 0;
        font-style: oblique;
        font-weight: normal;
        font-size: medium;
        text-indent: 0;
        text-shadow: 0;
        position: relative;
        margin: auto;
        border: thin solid #FFFFFF;
        opacity: 1;
    }

    .noBorder {
        border-left-style: none !important;
    }

Answer №1

It is ka-ching to suggest employing width:20% for every button rather than sticking to a set size.

The same principle applies to the navbar, opt for width:100%

Answer №3

Below is the code snippet:

  • I utilized display flex on the unordered list (ul).
  • Then, I applied the *flex:1 property to direct child li elements of ul.
  • Lastly, I set a tag with width:100%.
  • Certain unnecessary code has been removed.

@charset "utf-8";
body {
  color: #151515;
  font-family: "Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
  margin: 0;
  background-color: #250e20;
  -webkit-box-shadow: 0px 0px;
...

...
</footer>
  </div>
</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

Enhancing the camera functionality of the HTML <input> tag for iPhone and Android devices

I am currently working on a mobile web application that requires access to the device's camera. I am aware that this can be achieved using the following code: <input type="file" accept="image/*" capture="camera" /> The code snippet above suc ...

Utilizing DIV elements within table cells

Within this particular table, it is not only cell B that contains both a heading and content, but cells A and C as well. My effort to establish the heading and content using DIV elements has been somewhat successful. While I have achieved the desired font ...

"When trying to access a jQuery ID, it is coming back as undefined even though the

I'm attempting to obtain the ID of a specific element, save it as a variable, and then utilize that ID value to interact with other elements in the same section bearing the identical ID. <div class="mainContent"> <div class="articleContent"& ...

Showing small previews of images using php

I'm struggling with getting linked images to display. The code I have is currently located in a .php file. Its purpose is to retrieve all images from the directory where the file resides and show them using a "for" loop. However, at the moment, it onl ...

Struggling with getting the local slick slider to run smoothly

After installing the slick slider plugin and trying out some basic examples on jsfiddle, I encountered an issue when running it locally. For some reason, the results I get when testing it on my local environment are different from what I see on jsfiddle. ...

The amazingly efficient Chrome quick find feature, accessible by pressing the powerful combination of Ctrl + F, ingeniously

Currently using Google Chrome version 29.0.1547.62 m. I've employed the CSS attribute overflow set to hidden on the parent element, which renders some of my DIV elements hidden from view. Additionally, these concealed DIV elements are adjusted in pos ...

Safari displays an inexplicable gray border surrounding the <img/> element, despite the actual presence of the image

https://i.stack.imgur.com/4QR52.png There is an unexpected gray border visible around the dropdown image, as seen above. This occurrence has perplexed me because, according to several other queries, this problem arises when the image's src cannot be ...

Footer suffering from image invisibility syndrome

Having trouble displaying two social media images in my footer. Despite including them in my image map correctly, they just won't show up on the website. I've tried a lot of different things, but nothing seems to be working. Could it have somethi ...

Utilizing HTML documents instead of images in Owl Carousel 2

I am currently utilizing owl carousel 2 to construct a basic sliding carousel. However, I am only using images at the moment and would like to incorporate HTML files instead. These HTML files contain multiple divs where images can be inserted, and instead ...

What is the reason that custom styling for a single react component instance does not function properly?

In my current view, I have integrated a react component as shown below: <Jumbotron> Lots of vital information </Jumbotron> I am looking to give this particular instance a unique style, like using a different background image. However, addin ...

Switch out either even or odd divs within a container

I need help figuring out how to alternate the background colors of divs within a container. I want the first one to have a red background, the second to have blue, the third red again, and so on... Here is the code I currently have: <div>...</di ...

Issue with Arabic characters displaying incorrectly in Outlook 2007

I have encountered an issue with my newsletter application where the newsletters are in Arabic. When viewed in the browser, everything looks fine. However, when opened in Outlook 2007, strange text appears instead. Interestingly, if the email is marked as ...

Modify the input field for weight in WooCommerce to accommodate alphabetic characters

Is there a way to modify the WooCommerce Shipping weight field so that it can accept alphanumeric values, like: 500g / 1kg / 750ml / 2L I only need the weight for informational purposes and don't require any shipping. The location of the file re ...

Creating a notification for specific choices in a dropdown menu

I am working on a form that includes a select element with multiple options. Depending on the option selected, a different form will be displayed. My concern is if a user starts filling out one form and then decides to select another option, I want to add ...

Issue with the top margin of the body

Recently, I've encountered a peculiar problem with a standard website layout that I use. The issue seems to be centered around the space between the top and the first div: navbar. No matter what I try, I just can't seem to remove it, as the reas ...

Troubleshooting Problems with CSS Three-Column Layout

Struggling with aligning domain names in a 3 column setup, I have been attempting this for some time now without success. I am new to this and could use some guidance. Here is the code: TPL file <div> <p class="center">{foreach key=num it ...

Scroll positioning determines the height of an entity

Here's a code snippet I'm working with: HTML: <div id="wrap"> <div id="column"></div> </div> CSS: #wrap { display: block; height: 2000px; width: 400px } #column { display: block; height: 20px; ...

What is the best way to enlarge a Material UI card?

Currently, I am utilizing Material UI version 4 on my website and integrating cards (for more details, click here). https://i.stack.imgur.com/dm2M2.png I am interested in enlarging the overall size of the card so that the image appears larger. As I am si ...

When hovering over the sidebar, it smoothly slides out. (ideally using only CSS)

I've been spending my free time working on a website, but I'm struggling to figure out how to create a navigation similar to the one featured on FontShop's site: . I want it so that when you hover over their logo (or in my case, a blank rect ...

Align the text to the right within a display flex container

Below is the code snippet: <div className="listContent"> <div> <div className="titleAndCounterBox"> <div className="headerListTitle">{list.name}</div><br /> <div ...