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

form controls disappear upon adding form tags

Currently experiencing an issue with angular and forms that I could use some help with. I have a dynamic form that is functioning properly, but now I need to add validations to it. After following this guide, I established the structure correctly. Howeve ...

Jquery refuses to conceal a particular element

I've encountered this issue before, but I'm facing a problem this time. I'm attempting to create a popup that is initially hidden. When clicked, the popup does appear, but I'm unable to close it. Additionally, when trying to change the ...

"Displaying mongoose date in the HTML5 input type date format (dd/mm/yyyy) is a simple process that can

I have a structured data in MongoDB as shown below: var Person = new Schema({ "Name": { type: String, required: true }, "DOB": { type: Date, "default": Date.now } }); An instance of this schema is created using NodeJs with mongoose ODM: { "N ...

jQuery UI DatePicker: without any styling, no picking dates

I'm struggling to configure a jQuery UI DatePicker. I moved the development-bundle folder contents to the directory res/jqueryui and initialized two datepickers as shown below: <script src="res/jquery-2.1.0.min.js"></script> <script sr ...

PHP library dompdf is having issues when rendering CSS styles

Trying to convert HTML with CSS styles into a PDF using dompdf. The CSS includes floats as well. Below is the snippet of my CSS and HTML code: $dompdf = new DOMPDF(); //create object //load html with css $dompdf->loadHtml('<html> <head ...

What could be causing my slider to malfunction?

No errors are being returned by the console. Currently utilizing Unslider. The setup includes: <div class="slider"> <ul> <li><img src="img/one.jpg" alt=""></li> <li><img src="img/one.jpg" ...

Unable to define the color of icons path using CSS in Vue 3

When using the iconify library for VueJS, the icons' paths automatically have "currentColor" as their fill color. The issue arises when trying to set a path's color via CSS, as it seems to be ineffective. Even with "!important", the color won&apo ...

Javascript Calculator with Dual Input Fields

I have been given a task to create a calculator by tomorrow using Javascript. Unfortunately, I am currently taking a distance course and Javascript has just been introduced in this assignment. While I am familiar with HTML and CSS, Javascript is something ...

KnockoutJS's data binding feature is failing to display any content within the table rows

My JavaScript function creates a model and applies it to an HTML document using knockoutJS. In the HTML file, I have two different ways of displaying the same data: 1- A select list (which is working fine) 2- A table (not showing the same data) I need a ...

Optimizing CSS for Landscape Letter Print Alignment

When attempting to print in letter size and landscape orientation, the two divs fail to align properly. However, when using "@size a4 landscape" for printing, the alignment issue is resolved. What could be missing from my print CSS that would allow them to ...

What is the method for reverting style properties back to their CSS defaults using Javascript?

The php-generated page contains multiple elements structured like this: <td class="defaultTDStyle" style="color:userDefinedCustomColor" id="myTDId"></td> There is a default style in place with additional styles ap ...

Incorporate concealed image into HTML

When I perform actions with a couple of images, I encounter delays because the browser needs to load the images. For example, if I use $('body').append(''); everything works smoothly without any delays. However, when I try using style= ...

Tips for querying multiple elements that share a common ID and verifying if the input has been modified

I have a series of text inputs that share a common id prefix but differ slightly at the end. Whenever a user enters text in any of these input fields, I want to trigger a function. Currently, I have this functionality implemented with the following code: ...

Angular 2 Dropdown Multiselect Plugin - Fully Customize Width to 100%

Currently working on integrating the angular-2-dropdown-multiselect component: https://www.npmjs.com/package/angular-2-dropdown-multiselect The component functions correctly, but I am looking to adjust its width to fit the container... I believe simply ...

One way to position a sidebar between two divs is to ensure it adjusts seamlessly to the size of the browser window when resized

In my layout, I have two grids: one for the header and one for the footer. In between these two grids, I am using a sidebar on the left side. Below is the JavaScript code I am using: function adjustSize() { var heights = window.innerHeight; docum ...

jQuery fails to modify HTML according to its intended purpose

I've been struggling to update a price using JQuery. Even though the code seems fine when I check the console, the HTML doesn't reflect the changes. Additionally, when I try to log console.log(newPrc), it gives an error saying "newPrc" is not def ...

Is there a way to remove <font> tags using Javascript designMode?

Currently, I am in the process of developing a WYSIWYG editor as a hobby project. My approach involves utilizing an iframe with design mode enabled and leveraging the execcommand feature in JavaScript to implement the editor functionalities. For instance, ...

How to Incorporate an Anchor Link into a Div as well as its Pseudo Element using CSS, Javascript, or jQuery

How can I make both the menu item and its icon clickable as a link? When either is clicked, the link should work. Here is a CodePen example: http://codepen.io/emilychews/pen/wJrqaR The red square serves as the container for the icon that will be used. ...

Change the input field to uppercase using JavaScript but do not use inline JavaScript

Hey there! I have a basic script set up (see below) with an input field allowing users to enter a query. This query is then sent to a socrata webservice to request specific data, which is displayed in an alert box. So far, everything works smoothly. var l ...

Hide/Show overflow causing a disruption in my perspective

I am puzzled as to why my paragraph is not starting on a new line despite the overflow property set on the previous element. Take a look at my plunker, adjust the overflow property in line 11 to hidden and it will display correctly. When set to visible, i ...