Aligning the menu links to the right on a horizontal CSS menu

I have created a horizontal menu using CSS and HTML with the following code:

.nav > li:hover {
    background: #666666;
    text-decoration:none;
}
.active {
    background: #666666;
    text-decoration:none;
}
nav, ul, li, a {
    margin: 0;
    padding: 0;
}
a {
    text-decoration: none;
}
.container {
    width: 100%;
    margin: 10px auto;
}
.toggleMenu {
    display: none;
    background: #666666;
    padding: 10px 15px;
    color: #ffffff;
    width:100%;
    text-align:center;
}
.nav {
    list-style: none;
    *zoom: 1;
    background:#f36f25;
    text-align: center;
}
.nav:before,.nav:after {
    content: " "; 
    display: table; 
}
.nav:after {
    clear: both;
}
.nav ul {
    list-style: none;
    width: 12em;
}
.nav a {
    padding: 10px 15px;
    color:#fff;
}
.nav li {
    position: relative;
    text-align: left;
}
.nav > li {
    display: inline-block;
}
.nav > li > .parent {
    background-image: url("/images/downArrow.png");
    background-repeat: no-repeat;
    background-position: right;
}
.nav > li > a {
    display: block;
}
.nav li  ul {
    position: absolute;
    left: -9999px;
}
.nav > li.hover > ul {
    left: 0;
}
.nav li li.hover ul {
    left: 100%;
    top: 0;
}
.nav li li a {
    display: block;
    background: #666666;
    position: relative;
    z-index:100;
    border-top: 1px solid #ffffff;
}
.nav li li li a {
    background:#f36f25;
    color:#ffffff;
    z-index:200;
    border-top: 1px solid #ffffff;
}

@media screen and (max-width: 760px) {
    .active {
        display: block;
    }
    .nav {
        border-top: none;
    }
    .nav > li {
        display: block;
        border-top: 1px solid #ffffff;
    }
    .nav > li > .parent {
        background-position: 95% 50%;
    }
    .nav li li .parent {
        background-image: url("/images/downArrow.png");
        background-repeat: no-repeat;
        background-position: 95% 50%;
    }
    .nav ul {
        display: block;
        width: 100%;
    }
   .nav > li.hover > ul , .nav li li.hover ul {
        position: static;
    }
}

<a class="toggleMenu" href="#">Menu</a>
<ul class="nav">
<li><a href=""><span>Homepage</span></a></li>
<li><a href=""><span>About Us</span></a>
    <ul>
        <li><a href=""><span>Who Are We?</span></a></li>
        <li><a href=""><span>Service Status</span></a></li>
        <li><a href=""><span>Contact Us</span></a></li>
        <li><a href=""><span>Terms & Conditions</span></a></li>
    </ul>
</li>
</ul>

How can I align the main menu links to the right instead of center?

Here is a link to the fiddle: http://jsfiddle.net/B5jtm/

Answer №1

Give this a shot:

.menu {align-items: flex-end;}

Answer №3

I made a modification by removing text-align from the .togglemenu class and updating the .nav class to have text-align: right.

You can view the revised version on jsFiddle here: http://jsfiddle.net/B5jtm/10/

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

Utilizing jQuery to Parse XML for an XMLHttpRequest

Upon receiving the response below, I am trying to extract the value of sessiontoken, which is -4611685691785827288. <com.abc.csm.common.LoginResponse> <sessiontoken>-4611685691785827288</sessiontoken> <isSuccess>true</isSuccess& ...

Transform the *.svg image source into inline SVG for easier CSS customization

My goal is to include <img src="some.svg"> in my HTML, as inline SVG can be cumbersome and affect page load times. However, I would like to use CSS to style elements like fill:#fff. PS.: The webpage will be hosted on a nodeJS server and the co ...

Developing novel errors in JavaScript

There are times when I overlook using the await keyword, for example: const foo = bar(); // as opposed to const foo = await bar(); Identifying these bugs can be challenging. Are there any methods, libraries, or tools that can help prevent such errors? ...

Creating a React component dynamically and applying unique custom properties

I'm currently in the process of refactoring my React code to enhance its usability in situations where direct use of Babel is not possible, such as in short snippets of JavaScript embedded on web pages. As part of this refactor, I am setting up a conc ...

Increasing height for individual Bootstrap cards, without affecting all cards within the same row

I've encountered an issue where I need to increase the height of a single bootstrap card in a tile-module layout without affecting the height of any other cards in the same row. The code snippet below shows the HTML structure I currently have: <div ...

I’m keen on utilizing JQuery with Node.js and EJS, but I’m encountering an issue where $ is not

I attempted to incorporate JQuery in my project by following these steps. Installed jquery using npm install Modified the package.json file Despite this, the functionality still does not work as intended. Below is a snippet of the .ejs page: <html& ...

Tips for incorporating a background image using bootstrap

I am facing an issue with a large background image of size 1600 X 3700. When I try to add bootstrap to my project, the background image disappears and only the first 100px are visible. Can anyone provide guidance on the correct way to use bootstrap with ...

Challenges with API arrays

Here is the response from the API: { "meals": [ { "strTags":"Fish,Breakfast,DateNight", } ] } I am aiming to achieve the following outcome: https://i.sstatic.net/Y7B8B.png This is my current code setup: &l ...

Efficiently loading <tbody> content with ajax without the need to reload the entire table

My table setup is as follows: <table> <thead> <tr> <td>col_1</td><td>col_2</td><td>col_3</td> </tr> </thead> <tbody id="content"> <tr> & ...

Converting an object to a string using AngularJS within a directive

Can anyone assist me in ensuring that AngularJS preserves non-string values in directive attributes? While searching for a method to display a tree structure in HTML from JSON data, I came across this code snippet: http://jsfiddle.net/n8dPm/ I've be ...

Using PHP to encode JSON and submit it via POST request

Issue: I am encountering difficulty in sending a JSON-encoded variable to a PHP page using jQuery/AJAX. Here is my current approach. The file is uploaded through It undergoes processing using jQuery based on the following JS code. JS code: <scrip ...

When the document is fully loaded and processed, a script will be executed immediately following

I'm facing an issue with a modal plugin on my website. The plugin is triggered on $(document).ready, but I have another function (innerHTML) that inserts an <a> element 5-10 seconds after the page loads. This causes the modal not to work properl ...

react-query: QueryOptions not functioning as expected when utilizing userQueries()

When passing certain "query options" while using useQueries() to fetch multiple queries simultaneously, these specified "query options" do not get applied during query executions (e.g. refetchOnWindowFocus has a value of true but I want it to be false). F ...

Retrieve the key from the datalist within Form.Control

Upon receiving data from the API in JSON format, I am presented with a list of staff members: const MOCK_STAFF = [{ id: 1, name: "John Doe", department: "HR" }, { id: 2, name: "Jane Doe", department: "Research" }, etc Subsequently ...

Is there a way to identify the presence of a mouse on a website?

In the process of developing a website, I encountered a dilemma with navigation buttons. They needed to be large for aesthetic reasons and ease of use but had to be small when not in use. To address this, I decided to shrink the buttons into thumbnails on ...

Generating a JavaScript array containing all elements belonging to a specific class name

As I work on my website, I am attempting to create an array from elements that have a specific class. This array should retrieve the videofile attribute value from all `a` tags with the class `videoLink`. The desired values in the final array should be: ...

Tips for adjusting column sizes in ag-grid

I'm a beginner with ag-grid and need some help. In the screenshot provided, I have 4 columns initially. However, once I remove column 3 (test3), there is empty space on the right indicating that a column is missing. How can I make sure that when a col ...

I am looking to include an SVG icon, like a separate React component, within the "title" parameter of a React-Bootstrap Drop Down

Looking to create a header with the Profile icon and Loggedin user positioned on the right side of the Bootstrap Navbar. My goal is to achieve a UI similar to the image linked below without using the Dropdown component. In the image, there are two parts ...

Looking to include a sub element in my menu items using jQuery and CSS

Using jQuery and CSS, I have created a menu item. How can I navigate from one menu item to another sub menu item, as illustrated in the image below? Below is my HTML markup: <link rel="stylesheet" href="css/style_j.css" type="text/css" media="screen"/ ...

Encountering an issue with React npm causing errors that I am unable to resolve

Hey there, I'm a newbie to React. After setting everything up, I encountered an error after running "npm start." Can anyone help me figure out how to fix this? Thanks in advance! Click here for image description ...