Using flex and align properties to position two elements on the right and one on the left is a common layout challenge

I'm facing an issue with element positioning and text alignment. The navigation container consists of three elements: logo, title, and nav-list. You can find the code on CodePen.

/**{
    
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    
    }*/

header {
  background-color: orange;
  url(../images/hero.jpg);
  height: 600px;
  background-size: cover;
}

.fixed-nav {
  list-style: none;
}

.fixed-nav li {
  display: inline-block;
}

nav {
  display: flex;
  justify-content: space-between;
  padding: 30px 40px;
}

.logo {
  height: 25px;
  width: 120px;
}

.title {
  color: white;
  text-transform: uppercase;
  font-family: "Avalors Personal Use", sans-serif;
}

.nav-menu {
  display: flex;
  gap: 1rem;
  /* text-align: center;*/
  list-style: none;
  justify-content: center;
  align-content: center;
}

.nav-menu li {
  font-family: "Avenir LT Std", sans-serif;
  display: inline-block;
  color: white;
  font-size: 16px;
}

.nav-menu li a {
  text-decoration: none;
  color: white;
  /*padding-left:10px;
        padding-right:10px;*/
}
<header>
  <ul class="fixed-nav">
    <li>phone</li>
    <li>whats</li>
    <li>search</li>
  </ul>
  <nav class="navbar">
    <a href="#" class="logo">
      <img src="#" alt="logo" />
    </a>
    <h2 class="title">
      title
    </h2>
    <ul class="nav-menu">
      <li> <a href="#">HOME</a> </li>
      <li> <a href="#">ABOUT</a> </li>
      <li> <a href="#">PRODUCTS</a> </li>
      <li> <a href="#">NEWS</a> </li>
      <li> <a href="#">CONTACT</a> </li>
    </ul>
  </nav>
  <h2>Slogan</h2>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  </p>
</header>

I'm struggling to display the logo and title to the left and the nav-list to the right. When using flex to position them horizontally, the nav-list children appear at the top-left corner. You can see a demonstration here. I've tried using text-align, justify-content, but haven't been successful. Any insight would be greatly appreciated.

Answer №1

  1. Wrap your title and logo in a container.
  2. Add styles of your choice to the container.
    <header>
  <ul class="fixed-nav">
    <li>phone</li>
    <li>whats</li>
    <li>search</li>
  </ul>
  <nav class="navbar">
    <div class='wrapper'>
      <a href="#" class="logo">
        <img src="#" alt="logo" />
      </a>
      <h2 class="title">
        title 
      </h2>
    </div>
    <ul class="nav-menu">
      <li> <a href="#">HOME</a> </li>
      <li> <a href="#">ABOUT</a> </li>
      <li> <a href="#">PRODUCTS</a> </li>
      <li> <a href="#">NEWS</a> </li>
      <li> <a href="#">CONTACT</a> </li>
    </ul>
  </nav>
  <h2>Slogan</h2>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  </p>
</header>
.wrapper {
  display: flex;
  align-items: center;
}

Answer №2

Give this a shot, it should do the trick!

/**{

    margin: 0;
    padding: 0;
    box-sizing: border-box;

}*/
header {
  background-color: orange;
    url(../images/hero.jpg);
  height: 600px;
  background-size: cover;
}
.fixed-nav {
  list-style: none;
}
.fixed-nav li {
  display: inline-block;
}
nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30px 40px;
}
.logo {
  height: 25px;
}
.title {
  color: white;
  text-transform: uppercase;
  font-family: "Avalors Personal Use", sans-serif;
  margin-left: 10px;
}
.nav-menu {
  display: flex;
  gap: 1rem;
  /* text-align: center;*/
  list-style: none;
  justify-content: center;
  align-content: center;
}
.nav-menu li {
  font-family: "Avenir LT Std", sans-serif;
  display: inline-block;
  color: white;
  font-size: 16px;
}
.nav-menu li a {
  text-decoration: none;
  color: white;
  /*padding-left:10px;
    padding-right:10px;*/
}
.demo {
  display: flex;
  align-items: center;
}
<header>
  <ul class="fixed-nav">
    <li>phone</li>
    <li>whats</li>
    <li>search</li>
  </ul>
  <nav class="navbar">
    <div class="demo">
    <a href="#" class="logo">
      <img src="#" alt="logo" />
    </a>
    <h2 class="title">
      title 
    </h2>
    </div>
    <ul class="nav-menu">
      <li> <a href="#">HOME</a> </li>
      <li> <a href="#">ABOUT</a> </li>
      <li> <a href="#">PRODUCTS</a> </li>
      <li> <a href="#">NEWS</a> </li>
      <li> <a href="#">CONTACT</a> </li>
    </ul>
  </nav>
  <h2>Slogan</h2>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  </p>
</header>

Answer №3

.header-menu {
  margin-left: auto;
}

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

What is the best way to integrate Vuejs while maintaining the integrity of the HTML5 structure

According to the official Vuejs documentation, when it comes to the mounting point: The designated element only acts as a mounting point. Unlike in Vue 1.x, the mounted element will always be replaced with DOM generated by Vue. Therefore, it is advised ...

How can I resize and horizontally align an image using html/css?

Is it possible to resize, crop and center an image using only HTML/CSS? (Using the img tag or CSS sprite) For instance, if I have a 500x500 pixel image, I would like to resize it to a 250x250 pixel image To make the actual visible image 100x100 pixe ...

I'm experiencing an issue where the video from my server is not being displayed within the <video> tag in the browser, but when using the web URL, the video plays

When it comes to uploading a video, there are two options available: 1) Provide the web URL for the video, 2) Upload the actual video file. The <video> tag works smoothly with a web URL as the source, but issues may arise when trying to play an uplo ...

Combining TypeScript into HTML resulted in an error: Uncaught ReferenceError clickbutton is not defined

Attempting to create a basic CRUD frontend without the use of any frameworks. I am encountering an issue when trying to include a TypeScript file (index.ts) in my index.html, as the functions called within it are showing as undefined. I understand that bro ...

Unable to change the font-size in Bootstrap 5 is not possible

I've been exploring Bootstrap 5 and encountered an issue while trying to change the font-size of the navbar-brand element. Despite my efforts, the font-size remained unchanged. Additionally, attempts to add padding to the navbar-brand did not result i ...

Is PHP loaded prior to the `html body`?

I'm facing a unique challenge where I am currently transferring variables from a PHP page to hidden HTML inputs. The values are extracted from these hidden inputs using a JavaScript function that is called in the following manner: <body onload=" ...

Is there a file outside of the website's root that needs to be linked?

Hey there, I could use some assistance with a little issue I am having: Running the latest release of Ubuntu server 64bit with 2 virtual websites Here is my folder structure: site1 (Accessible on the web) /var/www/site1 site2 (Intranet site) /var/www ...

Can anyone explain why the background images aren't appearing correctly on iPhones and iPads?

I've been attempting to resolve the issues on this page for what seems like forever. The site in question is theafropick.co.uk. All devices seem to function properly except for iPads and iPhones, where the section with 6 tiles disappears entirely. ...

Fixing the error: Severity notice, there is an undefined variable called 'table'

My controller logic is as follows: public function index() { if ($this->session->userdata ( 'logged_in' )) { $condition = array( 'qes_status'=>'Y' ); $data = array(); $ ...

Tips for centrally zooming responsive images without altering their dimensions

I have created a custom jQuery and CSS function that allows an image to zoom in and out on mouseover while maintaining a constant box size. I modified an example code to suit my needs. Check out the demo here: https://jsfiddle.net/2fken8Lg/1/ Here is the ...

Tips for using JavaScript to style an array items individually

I have currently placed the entire array within a single div, but I would like to be able to display each element of the array separately so that I can style "date", "title", and "text" individually. This is my JSON structure: [ { "date": "Example ...

How can I utilize the LED flash on a Windows Phone using WinJS?

Currently delving into the world of WinJS and endeavoring to create an application that involves operating the LED Flash. I am seeking guidance on how to properly access the LED Flash functionality to allow for toggling it ON or OFF. Your insights on how ...

Adding space between the cells on the far left and far right of the table and the border

I need some advice on creating a table in HTML where the borders of the leftmost and right most cells do not extend all the way to the edges of the table. Here's an example: | ____ | In this example, the top border of the cells is continuous within ...

Can an XSS attack occur on a style tag with inline styling?

For example: <!DOCTYPE html> <html lang="en"> <head> <title>Test for Potential XSS Attack</title> <style> div { background-color:blue; height:120px; ...

Tips on navigating the scroller vertically as the user interacts with a selected div by scrolling up and down

On my webpage, I have various div elements displayed. Each div has the options to move it up or down using the buttons labeled "UP" and "Down". When a user selects a div, they can then use these buttons to adjust its position. I am looking for a way to au ...

Ways to eliminate dates from the text of listed items

Before finalizing their registration, users on our site are shown a review page. This panel displays all the items they have selected, creating a unique and variable list for each individual. However, each item in the list starts with a distracting date/ti ...

Overlap of a fixed right column over a fixed sidebar in Bootstrap 4, causing it to overlap the

I am struggling to fix the layout of my website's right dark column and sidebar. I've attempted several methods, including setting fixed parameters with no success. My goal is to have the content-c class (dark column) fixed and the sidebar fixed ...

Tips for integrating WMV files into an HTML5 document

I've been attempting to integrate some s3 WMV file URLs into my HTML page, but the following code doesn't seem to be functioning as expected. <object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Microsoft® Windows® ...

Issue with Div element not appearing on Azure AD B2C page customization

Utilizing PopperJS, I attempted to incorporate a popover box that appears when the user focuses on the password field within an Azure AD B2C page customization. Despite noticing the presence of the box element, it fails to display as intended. Any assistan ...

I'm having trouble getting jQuery to work properly with Bootstrap buttons

In simple terms, my objective is to have two buttons on a page where "1" is displayed when the first button is pressed and "2" is displayed when the second button is pressed. This functionality works fine with radio inputs, but when I incorporate button la ...