Guide on placing the navigation elements at the top right corner

<header class="top-header">
    <div class="container">
        <div class="logo">
            <img src="./dist/img/usjr-logo.png" alt="" href="http://www.usjr.edu.ph" id="logo">
        </div>

        <nav class ="top-nav">
            <ul>
                <li class="current"><a href="index.html">Link A1</a></li>
                <li><a href="">Link A2</a></li>
                <li><a href="">Link A3</a></li>
            </ul>
        </nav>

    </div>
</header>

<nav class="navigation-menu">
    <ul>
        <li><a href="#">Link B1</a></li>
        <li><a href="#">Link B2</a></li>
        <li><a href="#">Link B3</a></li>
        <li><a href="#">Link B4</a></li>
    </ul>
</nav>

This code snippet represents the content of my index.html file.

Below is a section from my CSS file:

@import url('https://fonts.googleapis.com/css?family=Nunito|Open+Sans');
@import url('https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300');

/*Other styling rules and imports are included...*/

nav.top-nav > ul > li {
    display : inline-block; 
}

nav.top-nav > ul > li > a{
    color :#fff;
    text-decoration: none ;
    padding : 30px ; 
    text-align : right ;
}


header.top-header { 
    margin-top : 10px;
    background-color : #FFF;
    height :100px;
}

nav.navigation-menu > ul > li > a {
    color : #FAB301  ;
}

An image can be viewed here.

I am trying to position the Link A elements to the top right-center of the navigation in the top-header class. Any suggestions on how to achieve this?

Answer №1

Here is the code to add:

.top-nav {
  float: right;
}

The float CSS property determines whether an element should be positioned on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the webpage while still being a part of the layout, unlike absolute positioning.

Reference:https://developer.mozilla.org/en/docs/Web/CSS/float?v=example

@import url('https://fonts.googleapis.com/css?family=Nunito|Open+Sans');
@import url('https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300');

/*@import "heading.css" ; */

/*Main Elements*/

* {
  - margin: 0;
  border: 0;
  padding: 0;
}

body {
  background-color: #ececec;
  font: 14px/20px'Nunito', 'sans-serif';
  color: #444;
  margin: 0;
}

.wrapper {
  margin: 0 auto;
  width: 70%;
  clear: both;
}

.container {
  margin-left: 30px;
  margin-right: 30px;
}

img#logo {
  height: 80px;
  width: auto;
  margin: 10px;
}

ul {
  list-style: none;
}

nav.top-nav>ul>li {
  display: inline-block;
}

.top-nav {
  float: right;
}

nav.top-nav>ul>li>a {
  color: #fff;
  text-decoration: none;
  padding: 30px;
  text-align: right;
}

header.top-header {
  margin-top: 10px;
  background-color: #FFF;
  height: 100px;
}

nav.navigation-menu {
  background-color: #444;
  color: #fff;
  height: 50px;
}

nav.navigation-menu>ul>li>a {
  color: #FAB301;
}
<header class="top-header">
  <div class="container">
    <div class="logo">
      <img src="./dist/img/usjr-logo.png" alt="" href="http://www.usjr.edu.ph" id="logo">
    </div>

    <nav class="top-nav">
      <ul>
        <li class="current"><a href="index.html">Link A1</a></li>
        <li><a href="">Link A2</a></li>
        <li><a href="">Link A3</a></li>
      </ul>
    </nav>

  </div>
</header>

<nav class="navigation-menu">
  <ul>
    <li><a href="#">Link B1</a></li>
    <li><a href="#">Link B2</a></li>
    <li><a href="#">Link B3</a></li>
    <li><a href="#">Link B4</a></li>
  </ul>
</nav>

Answer №2

CODEPEN

If you'd like the navigation menu options to be positioned all the way to the right side and aligned at the top of the screen, make the following adjustments:

nav.top-nav {
  position: fixed;
  right: 0;
  top: 0;
}
nav.top-nav > ul > li > a {
  color: #333;
  text-decoration: none;
  padding: 0 10px 0 0;
  text-align: right;
}

Answer №3

To center it vertically, I would use absolute positioning over the top area and apply the following CSS properties:

top: 50%; transform: translateY(-50%));

@import url('https://fonts.googleapis.com/css?family=Nunito|Open+Sans');
@import url('https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300');

/*@import "heading.css" ; */


/*CSS Styling for Main Elements*/

* {
  - margin: 0;
  border: 0;
  padding: 0;
}

body {
  background-color: #ececec;
  font: 14px/20px'Nunito', 'sans-serif';
  color: #444;
  margin: 0;
}

.wrapper {
  margin: 0 auto;
  width: 70%;
  clear: both;
}

.container {
  margin-left: 30px;
  margin-right: 30px;
}

img#logo {
  height: 80px;
  width: auto;
  margin: 10px;
}

ul {
  list-style: none;
}

nav.top-nav > ul > li {
  display: inline-block;
}

nav.top-nav > ul > li > a {
  color: #fff;
  text-decoration: none;
  padding: 30px;
  text-align: right;
}

header.top-header {
  margin-top: 10px;
  background-color: #FFF;
  height: 100px;
}

nav.navigation-menu {
  background-color: #444;
  color: #fff;
  height: 50px;
}

nav.navigation-menu > ul > li > a {
  color: #FAB301;
}
  
.top-header .container {
    position: relative;
}
  
.top-nav {
    background: rgba(0,0,0,0.5);
    position: absolute;
    top: 50%; right: 0;
    transform: translateY(-50%);
}
<header class="top-header">
  <div class="container">
    <div class="logo">
      <img src="./dist/img/usjr-logo.png" alt="" href="http://www.usjr.edu.ph" id="logo">
    </div>

    <nav class="top-nav">
      <ul>
        <li class="current"><a href="index.html">Link A1</a></li>
        <li><a href="">Link A2</a></li>
        <li><a href="">Link A3</a></li>
      </ul>
    </nav>

  </div>
</header>

<nav class="navigation-menu">
  <ul>
    <li><a href="#">Link B1</a></li>
    <li><a href="#">Link B2</a></li>
    <li><a href="#">Link B3</a></li>
    <li><a href="#">Link B4</a></li>
  </ul>
</nav>

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

Instructions on allowing the user to enter text for searching through an array of objects, and displaying a message if a match is found. Use only pure JavaScript

As a newcomer to JavaScript, I greatly appreciate the support from everyone on this platform. Thank you in advance for your help! I am currently working on building a basic music app as a learning project in JavaScript. The main goal is to understand how J ...

Is there a trick for listening to mp3s on Android?

I am trying to implement an audio player on my website that automatically starts playing a mp3 file when the page is opened. Additionally, I want to have a button on the same page that allows users to pause and resume the audio playback by clicking it. He ...

When the window is resized, the text and images become jumbled and distorted

As a beginner in CSS, I am encountering an issue where the text and images on my website get distorted when I resize the window. How can I resolve this? HTML <img src="images\titles_03.jpg" class="tt1" > <img src="images\titles_05.jpg ...

Generating HTML using a filter

I have been working on creating a filter that will render HTML tags. Here is the code for my filter: filters: { limitStrLength: function (value, maxLength) { if (value && value.length > maxLength) { let partialVal = value.substr(0, ...

Enhance Your Website with HTML5 Video Transition Effects

Is it possible to recreate video transition effects using HTML5 similar to the ones shown in this example: Can this be achieved across all major browsers, including Safari, Firefox, Chrome, and IE9? ...

I have tried to create two apps in AngularJS, but unfortunately, they are not functioning as expected

Having trouble with implementing 2 ng-app in a single html page. The second one is not working. Please review my code and point out where I am making a mistake. <div id="App1" ng-app="shoppingCart" ng-controller="ShoppingCartController"> &l ...

Error 404: Django failing to load image on the webpage

Just starting out with Django and I've hit a snag trying to load a static file (image). Here's the error message I'm getting: 127.0.0.1/:1707 GET http://127.0.0.1:8000/static/css/static/images/background/1.jpg 404 (Not Found) I suspect th ...

Is it possible to leverage specific client-side Javascript APIs on the server-side?

Exploring APIs designed for web browsers that require their .js code to return audio streams. In a broader sense, these APIs provide byte streams (such as audio) for playback in the browser. Is it possible to use these APIs in server-side Javascript frame ...

Tips for eliminating any default white space visible between tags:

What is the best way to eliminate white space gaps between div tags and adjust pixel differences between them in HTML code? My current alignment is off and there are noticeable white spaces between div tags. I have tried using a reset link but it didn&apo ...

Creating a loading screen with JQuery for an Ajax request

I want to implement a loading screen in my web application every time an ajax call is initiated using jQuery. Currently, I have different types of ajax calls such as $.getJSON, $.post, and $.ajaxFileupload, each with their own Success function that remov ...

Ways to incorporate fixed CSS into a Dojo 7 application such as FontAwesome

Currently, I have a Dojo 7 (Dojo 2) application that was built using the dojo-cli tool. I am now looking to enhance it by incorporating FontAwesome icons. Luckily, I have a Pro subscription that provides me with a zip file containing various folders of CSS ...

Achieving Vertical Alignment of Text and Icon in the Same Line Using HTML and CSS

I am struggling to align these icons vertically center with the text. However, there seems to be a slight offset of a few pixels. I have experimented with different solutions, but this is the closest I could get to. Can anyone explain why it's not ali ...

What is the best way to use jQuery to animate a particular height up to 100%?

To provide a sneak peek of the content in the div, I have minimized it so only the first line is visible. Now, I want to add an animation that will expand the div to 100% height when you click the title. However, using animate(height:"100%") does not res ...

Is it possible for a Bootstrap modal dialog to overlay another dialog window?

<button class="btn" onClick="$('#firstModal').modal('show');">Click Here</button> <!-- Modal --> <div id="firstModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden=" ...

The error message "Undefined index" will only occur when trying to access the "file" field in an HTML form

Initially, everything was functioning properly but then suddenly it stopped. All other fields are submitting without any problems. Upon pressing submit, all the data is added to the database except for the photo_url field. Just to clarify, the crucia ...

Replicating radio button functionality using buttons in an HTML document

I am attempting to simulate radio button behavior using normal buttons for a quiz application. Currently, my code is working as intended and permanently highlights buttons with the desired color. However, I want all other buttons in a question to be white, ...

Display issue with Google Chart

Could someone please help me identify why these charts are not showing up? This code was functioning properly in a previous project. I copied the same code to a new project, only adding the master page. However, now the charts are not appearing. All I can ...

Guide on how to append input field data to a table using jQuery

My current project involves working with a table, and I have encountered some challenges along the way. Typically, I have 4 input fields where I can input data that is then sent to the table in my view. However, if I exceed 4 values and need to add more, I ...

Tips for preventing Razor from interpreting special characters as HTML code

I'm encountering an issue with special characters displaying as HTML codes on the page I'm working on. The content is retrieved from a database and shown in readonly input boxes. For example, & is displayed as &. How can I ensure that the ...

Tips for stacking objects vertically in mobile or tablet view using HTML and CSS

I have been diligently working on a project using a fiddle, and everything appears to be running smoothly in desktop view. The functionality is such that upon clicking any two product items (with one remaining selected by default), a detailed description ...