Steps for placing two anchors next to each other

Trying to create a navigation bar with anchors aligned on the left and right sides. However, the second anchor in each div is displaying below the first one.

Despite searching online for solutions and attempting various fixes, none of them seem to work.

body {
background-color: #ec1320;
color: #ec1320;
}

.nav-bar {
background-color: #1524ea;
color: white;
height: 100px;
position: absolute;
width: 100%;
height: 8%;
left: 0px;
top: 0px;
}

.nav-link {
color: #d0d0d0;
font-size: 20px;
position: relative;
margin-top: 5px;
}

.nav-link:hover {
color: gray;
}

.nav-head {
color: white;
font-size: 30px;
margin-top: -4px;
}

.nav-head:hover {
color: gray;
}

.left-nav {
position: absolute;
left: 0px;
}

.right-nav {
position: absolute;
right: 0px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<body>
  <header>
    <nav class="nav-bar">
      <div class='container'>
        <div class="left-nav">
          <a href="index.html" class='nav-item nav-head nav-link'>Gamer Blog</a>
          <a href='index.html' class='nav-item nav-link'>Home</a>
        </div>
        <div class="right-nav">
          <a href='login.html' class='nav-item nav-link'>Login</a>
          <a href='register.html' class='nav-item nav-link'>Register</a>
        </div>
      </div>
    </nav>
  </header>
</body>

In need of assistance to ensure that all anchors are positioned beside each other within their respective parent divs.

Answer №1

Place your content for the .right-nav and left-nav within a flexbox container.

Give this a shot:

.right-nav, .left-nav {
  display: flex;
}

Once you do that, you'll be all set!

Hopefully, this solution works for you! Cheers

Answer №2

If you are utilizing Bootstrap, it is convenient to place all your links within the same nav container. To align your last left link, assign a right margin of auto (mr-auto). This adjustment will move the remaining links to the right. I have experimented with some styles to enhance the appearance, such as switching the Bootstrap class from container to container-fluid:

body {
  background-color: #ec1320;
  color: #ec1320;
}

.nav-bar {
  background-color: #1524ea;
  color: white;
}

.nav-link {
  color: #d0d0d0;
  font-size: 20px;
  position: relative;
}

.nav-link:hover {
  color: gray;
}

.nav-head {
  color: white;
}

.nav-head:hover {
  color: gray;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<body>
  <header>
    <nav class="nav-bar">
      <div class='container-fluid'>
        <nav class="nav">
          <a href="index.html" class='nav-item nav-head nav-link'>Gamer Blog</a>
          <a href='index.html' class='nav-item nav-link mr-auto'>Home</a>
          <a href='login.html' class='nav-item nav-link'>Login</a>
          <a href='register.html' class='nav-item nav-link'>Register</a>
        </nav>
      </div>
    </nav>
  </header>
</body>

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

Interact with one div to trigger changes in another (CSS)

I successfully influenced the style of one div when hovering over another div using the "+" selector, but I would prefer to find a different solution. My goal is for this interaction to work even if the .h div and the .t div are located in separate parent ...

Refresh all the data points displayed on the c3.js chart

I created a basic div element in my HTML code: <div class='all'> Show all </div> Accompanying that, here is the JavaScript code I implemented: $(document).ready(function () { $('.all').click(function(){ ch ...

Tips for managing the background color of a box when the function is constantly refreshing in Internet Explorer

function process(Objects) { var objectId = Objects; displayContent(objectId); } function displayContent(objectId) { var boxId = objectId.id; var color = ret ...

Once it hits the fourth tab, it must not cycle back to the first one

Hi there, I'm new to JavaScript I noticed that when I click the left and right arrows, the tabs circle back to the beginning However, I would like the circle to stop. When it reaches the fourth tab, it should not go back to the first. This should also ...

Center alignment function is not functioning correctly

I'm struggling to center the text both vertically and horizontally inside my div. No matter what I try, I can only get it to align horizontally. Here is the CSS code I have been using: #loading > h1 { text-align: center; font-size: 21px; ani ...

If the Angular Interpolation Binding format is other than "yyyy-MM-dd", the date will not be displayed

I am facing an issue with my interpolation binding when the date format is not 'yyyy-MM-dd' .html: <div class="form-group"> <label>DOB <input type="date" class="form-control" id="birth_date" value={{stu.result.birth_date}}& ...

I need help figuring out how to use a bash script to generate an HTML file by incorporating the contents of the template.vars file

I am looking to enhance the functionality of this script by having it generate an HTML file based on the data found in template.vars. Currently, the script acts as a basic template engine that prompts for user input and replaces instances of @NAME@ with th ...

tips for aligning text and buttons on the same line

Is there a way to align the button with the text on the same line, instead of it dropping down (refer to the image below)? https://i.sstatic.net/hQ3YC.png This is my current html and css code (utilizing bootstrap): <a href="#" class="mx ...

Scrolling on an iPhone's Div

When I tried to access a website () using my iPhone and other gadgets, I encountered an issue with scrolling through the content. Clicking on the "Insight" link at the top-left corner led me to another page. On a computer, I had no trouble scrolling smoo ...

If a <section> element contains a <header>, must it also include a <footer>?

Here is the current state of my code: <section id="one"> <h2>Section Title</h2> <p>Lorem ipsum...</p> <p>Lorem ipsum...</p> <p>Lorem ipsum...</p> </section> <section id="two"&g ...

Unexpected Results from Div Positioning

Here is the PHP code snippet I am working on: <?php include 'header-adminpanel.php'; ?> <div class="container"> <div class="body-content"> <div class="side-left"><?php include 'adminproduct_sidebar.ph ...

Is there a discrepancy in the display of inline-block content across various browsers?

My dilemma lies in the fact that I have a responsive form element that needs to be aligned inline with a title. Here is an example of what I'm aiming for: https://i.sstatic.net/2ckjf.png Everything looks perfect in Firefox, just as I intended. Howe ...

Looking for a straightforward way to incorporate a "Read more" and "Show Less" functionality into a Wordpress site using Javascript?

As a last resort, I am seeking a quick and simple fix. I have been experimenting with Javascript to implement a 'Read more...' & '... Read Less' feature on six different sections of a single page. The goal is to display only the fi ...

Watch the video and follow along with your mouse using jQuery

Wouldn't it be cool to have a video play and follow your mouse pointer when you hover over the red box? And then once you move away, the video stops and disappears. Check out my progress so far: jsfiddle Here's the jQuery code I've used: $ ...

Unable to show input in Javascript HTML

Every time I try to run this code on my webpage, the buttons do not seem to respond when clicked. I am aiming to have the user input for full name, date of birth, and gender displayed in the text box when the display button is clicked. When the next butt ...

Making an element transparent in CSS without affecting the text within it

Recently, I created a menu block element and decided to apply an opacity of 0.4/40 to it. However, I encountered an issue where the text within the menu block was also affected by the opacity. My aim is to have the opacity only impact the menu block itsel ...

What is the best way to prevent a single cell within a table from hovering?

Within a table cell, I have another table. The outer table has a hover effect applied to it, but I want to prevent the inner table with the id "table_I_don_not_want_to_hover" from inheriting this hover behavior like the rest of the cells and rows. I need t ...

jQuery can add scrolling buttons to a webpage

I have been trying to create a list that can be scrolled through by using buttons, while also having a visible and functional scrollbar. However, I am struggling to edit my code in a way that allows both features to work simultaneously. It seems like I can ...

Numerous Kendo windows are layered on top of each other, yet the text divisions within them remain distinct

I am currently working on a project that involves laying out multiple Kendo windows in rows. Specifically, I need to display 4 windows in each row and have them shift left when closed. My framework of choice is Bootstrap 3. Everything works as expected w ...

The feature of Jquery click and cursor: pointer only focuses on a single element at a

Recently, I created a navbar that includes a dropdown feature. I encountered an issue where I wanted the dropdown to show up when clicking on the navbar-profile class (which contains the profile picture, name, and chevron icon) in the top right corner. Ho ...