Navigation menu elements out of place

I am facing some challenges while trying to create a horizontal navigation:

  1. The first element appears to be displaced
  2. Is there a better way to position the text centered below the icon? Currently, I have used a
    tag for this purpose. Also, how can I use the optional arrow-down-icon more effectively? Currently, I have used the span tag, but I feel that the html markup could be improved.
  3. The second-level ul (subelements) is not displaying correctly and fails to enclose the subelements.

JSFiddle: http://jsfiddle.net/pqubgt2d/

nav {
background-color: #f2f2f2;
padding: .3em 0;
border-radius: 7px;
}
nav ul {
list-style: none;
height: 2.5em;
padding: .25em;
color: #555;
margin: 0;
}
nav ul li {
font-family: "Source Sans Pro";
font-size: .5em;
margin: .5em 0;
display: inline-block;
width: 4em;
text-align: center;
}
nav ul li i {
    font-size: 3em !important;
}
nav ul li ul {
font-size: 3em;
background-color: #f2f2f2;
}

.button-arrow-down {
width: 0; 
height: 0; 
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #B4B4B4;
    margin: 0 auto;
    position: relative;
    bottom: -7px;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/>
<nav>
<ul>
<li><i class="fa fa-file-o"></i><br>New</li>
<li>
<i class="fa fa-floppy-o"></i><br>
Save<br>
<span class="button-arrow-down"></span>
<ul>
<li>Subelement 1</li>
<li>Subelement 2</li>
<li>Subelement 3</li>
</ul>
</li>
</ul>
</nav>

Answer №1

    nav {
        background-color: #f2f2f2;
        padding: .3em 0;
        border-radius: 7px;
        height: 2.5em;
    }
    nav > ul {
        list-style: none;
        padding: .25em;
        color: #555;
        margin: 0;
    }
    nav > ul > li {
        font-family:"Source Sans Pro";
        font-size: .5em;
        margin: .8em;
        text-align: center;
        float:left;
        width:4em;
    }
    nav > ul > li i {
        font-size: 2.8em !important;
    }
    nav > ul > li>ul {
        font-size: 3em;
        background-color: #f2f2f2;
    }
    .button-arrow-down {
        width: 0;
        height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 5px solid #B4B4B4;
        margin: 0 auto;
        position: relative;
        bottom: -7px;
    }
    .drop {
        float:left;
        display:none;
    }
    li:hover > .drop {
        display:block;
    }
    .drop {
        list-style-type:none;
        font-family:"Source Sans Pro";
        font-size: 20px;
    }
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/>
<nav>
    <ul>
        <li class="item"><i class="fa fa-file-o"></i>New</li>
        <li class="item"><i class="fa fa-floppy-o"></i>Save<span class="button-arrow-down"></span>

            <ul class="drop">
                <li>Subelement 1</li>
                <li>Subelement 2</li>
                <li>Subelement 3</li>
            </ul>
        </li>
    </ul>
</nav>

Check out this revised code snippet. It should better align with your needs. If you find it helpful, give it a thumbs up. Edit: I made some adjustments to the answer based on your feedback.

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

Configuring the space beneath a multi-line text with a bottom border distance or shadow

I am looking to add a bottom border with less spacing than default for specific text, creating a look similar to this image: https://i.sstatic.net/sCQii.png Unfortunately, it seems the border property cannot achieve this effect. I am experimenting with t ...

Strange image movement occurs when utilizing jQuery slideDown and slideUp

My HTML structure is as follows: <div class ='profileName'> <hr> <span class='name'>Content</span> </div> <div class ='profile'> <div class='floatRightImg padded'> < ...

Creating an element in react-draggable with two sides bound and two sides open - here's how!

At the moment, I am facing an issue where the element is restricted from moving outside of the container with the class of card-width-height. My goal is to have the right and bottom sides bounded within the container while allowing the element to move beyo ...

Image element for Material UI CardMedia

There is a component in Material UI called CardMedia that allows for media content within a Card. The Mui website showcases an example using the img tag with CardMedia. https://mui.com/material-ui/react-card/#complex-interaction I am interested in using ...

Which is the better option: utilizing the submit event of the form, or incorporating ajax functionality?

Forms are an essential part of my website design, and I often find myself contemplating whether it's better to submit a form using a standard submit button or utilizing Ajax. Typically, I opt for Ajax to prevent the dreaded issue of form re-submission ...

What is the reason that (click) does not send my data within <button>, while (change) within <input> does in Angular and HTML?

I am facing an issue while trying to send data to my Glassfish RESTful server. The method is activated successfully when I use (change) inside the input tag, but it doesn't work when I try using (click) or (change) to activate the method. I attempted ...

Using CSS background-image URL in .NET MVC tutorials

What is the correct way to route to an image in an MVC web application? MVC has default routes, meaning you can access the same page in multiple ways: 1. localhost 2. localhost/home/index However, you can also do it this way, changing the root directory. ...

Unable to dial phone numbers when clicking 'Click to call' link on Android devices

Within my Cordova android application, I have a link set up like this: <a href = "tel:011123456789">Click to Call</a> While this click-to-call functionality works smoothly in IOS, it seems to be hindered in Android by an issue such as: 11- ...

Can someone guide me in altering an item within a column? I have basic knowledge of PHP, but I am not a skilled expert in the subject

Hello, I am new to coding and I have a question. I would like to make a correction in the Terminate Reason column by changing the spelling of "Resgned" to "Resigned". Can someone guide me on how to do this? Please refer to the attached image for better und ...

Chrome Canary's behavior with CSS border-radius on tiny objects

Is it possible to achieve CSS border-radius on really small objects in Chrome Canary? This experiment with a 3px high line and a 2px border radius, when zoomed in at 600%, doesn't show much difference: It works perfectly fine in regular Google Chrom ...

Changing a variable in an HTML file using a JavaScript file

I am working with JavaScript code that has been imported from another file containing a variable that I need to update in my HTML file. Is there a way to update the variable without directly inserting the JavaScript code into my HTML document? JavaScript ...

Difficulties arise when dealing with card elements and scrolling on a

Currently working on an ecommerce simulation project for a course, I successfully implemented a featured section with cards. However, when it comes to scrolling, I am facing an issue where the cards overlap with my sticky navbar as I scroll down. If anyo ...

Is there a Wordpress floating bar similar to the one seen on 9gag?

After browsing through some posts on stackoverflow, I noticed that my website is not responding as expected. You can check out my site here: To troubleshoot, you can examine the source code and utilize Firebug to inspect the css and javascript being used ...

Issue with displaying background image in h2 element

Consider me a novice who learns primarily through trial and error. Unfortunately, I'm stuck on this particular issue. My goal is to have an image appear behind the h2 text on my homepage, but despite my efforts, I can't seem to make it work. You ...

Flipping a 2-dimensional box using CSS and incorporating cascading flex divs

*Please read the note: This question is a bit lengthy as I wanted to explain my thought process. For those who prefer not to read everything, I have created codepens for easy reference. Essentially, I am looking to achieve CSS box flipping effects like t ...

Display div content depending on the clicked ID in AngularJS

Unique Header Links HTML <ul ng-controller="pageRouteCtrl"> <li ui-sref-active="active"> <a ui-sref="home" class="" ng-click="getPageId('live-view')">LIVE</a> </li> <li> <a ng-clic ...

Main content with a floating aside menu

I am currently using the CoreUI admin template. The layout I have set up is the basic one outlined on the following page: My goal is to make the aside menu appear on the right side of the main content, floating over it rather than inline and reducing the ...

Avoid letting words be separated

My question involves HTML code <div class="col-md-4">...</div> <div class="col-md-4">...</div> <div class="col-md-4">Lorem Ipsum</div> When I view this on a mobile device, the text appears as follows: Lorem Ip- sum I ...

Receive information from a form and store it in an array

Struggling to figure out how to convert this into an array. I'm having trouble grasping the concept of taking input from a form and storing it in an array. In my project instructions, it clearly states: Do NOT save the input in variables and then tra ...

"Unexpected behavior: PHP+JS getElementById() function is returning an integer value instead of a

EDIT: Apologies for the PHP section not displaying correctly. I am attempting to extract a decimal value from PHP/HTML in JavaScript using getElementByID().value. However, despite the PHP value being decimal, it is represented as an integer in JavaScript ...