Achieving an element placement in a navigation bar with flexbox and grid layout | HTML and CSS exclusive techniques

Need help achieving the desired result using only flexbox and grid layout.

The goal is to place a search bar vertically centered and to the right of the navbar, while keeping the existing items on the left intact. Can you assist?

/* Reset */

* {
  margin: 0;
  padding: 0;
  border: 0;
  box-sizing: border-box;
  list-style: none;
  text-decoration: none;
}

/* General styles */

html {
  font-size: 100%;
  line-height: 1.5;
}

body {
  max-width: 1850px;
  font-family: "BenchNine", sans-serif;
}

/* Header */

.top-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  align-items: center;
}

.slogan {
  text-align: right;
  font-family: "Chela One", cursive;
  font-size: 4em;
  color: #527bea;
}

/* Navbar */

nav {
  background-color: #ae2123;
}

ul {
  display: flex;
  justify-content: left;
}

a {
  display: block;
  padding: 15px 25px;
  text-align: center;
  color: #fff;
}

a:hover {
  color: #999;
}

input {
  padding: 5px 20px;
  border-radius: 20px;
}
<header>
    <div class="top-container">
      <div class="logo-box">
        <img class="logo" src="/img/logo.png" alt="logo" />
      </div>
      <div class="slogan-box">
        <h1 class="slogan">La passion des films</h1>
      </div>
    </div>
    <nav>
      <ul>
        <li>
          <a href="#">Programmes</a>
        </li>
        <li>
          <a href="#">Actualités</a>
        </li>
        <li>
          <a href="#">Jeune Public</a>
        </li>
        <li>
          <a href="#">Tarifs</a>
        </li>
        <li>
          <a href="#">Accés</a>
        </li>
        <div class="form-container">
          <form class="form" action="#">
            <input type="text" placeholder="Rechercher" />
          </form>
        </div>
      </ul>
    </nav>
  </header>

Answer №1

It appears that your HTML is not properly structured. A div should not be a direct child of a ul. Consider using another li element instead.

To center the content vertically within the ul, you can add align-items: center;. Additionally, you can use margin-left: auto; to position it on the right side.

/* Reset */

* {
  margin: 0;
  padding: 0;
  border: 0;
  box-sizing: border-box;
  list-style: none;
  text-decoration: none;
}


/* General styles */

html {
  font-size: 100%;
  line-height: 1.5;
}

body {
  max-width: 1850px;
  font-family: "BenchNine", sans-serif;
}


/* Header */

.top-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  align-items: center;
}

.slogan {
  text-align: right;
  font-family: "Chela One", cursive;
  font-size: 4em;
  color: #527bea;
}


/* Navbar */

nav {
  background-color: #ae2123;
}

ul {
  display: flex;
  justify-content: left;
  align-items: center;
}

.form-container {
  margin-left: auto;
  margin-right: 1em;
}

a {
  display: block;
  padding: 15px 25px;
  text-align: center;
  color: #fff;
}

a:hover {
  color: #999;
}

input {
  padding: 5px 20px;
  border-radius: 20px;
}
<header>
  <div class="top-container">
    <div class="logo-box">
      <img class="logo" src="/img/logo.png" alt="logo" />
    </div>
    <div class="slogan-box">
      <h1 class="slogan">La passion des films</h1>
    </div>
  </div>
  <nav>
    <ul>
      <li>
        <a href="#">Programmes</a>
      </li>
      <li>
        <a href="#">Actualités</a>
      </li>
      <li>
        <a href="#">Jeune Public</a>
      </li>
      <li>
        <a href="#">Tarifs</a>
      </li>
      <li>
        <a href="#">Accés</a>
      </li>
      <li class="form-container">
        <form class="form" action="#">
          <input type="text" placeholder="Rechercher" />
        </form>
      </li>
    </ul>
  </nav>
</header>

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

Using routerLink for linking to multiple components

Below is the anchor tag provided: <a class="uppercase" routerLink="settings/pressure" routerLinkActive="text-success" (click)="closeModal()" > <div class="pad-btm"> PRESSURE </div> </a> I need to include another route ...

How can jQuery be used to determine if the number of checked checkboxes is a multiple of three?

Within the ul, I have li tags with checkboxes and I want to create a function that checks, when the submit button is pressed, if the number of checked checkboxes is not a multiple of 3. If it isn't, an alert should be displayed. How can I accomplish t ...

Why is the image cut in half on mobile devices but displaying correctly on computer screens? Could it be an issue with

There seems to be an issue on mobile screens that does not occur on computer screens. When the user clicks on the image, it disappears, and when they click another button, it reappears. However, there is a problem with how the image appears - it is cut off ...

What is the standard way elements are displayed within a box that is positioned absolutely?

My current setup involves setting <body> to be absolutely positioned in order to fill the entire viewport without needing to specify a height: body { width: 100%; margin: 0; padding: 0; position: absolute; top:0; right:0; bottom: ...

Using Javascript code to draw particles at the cursor's position and then directing those particles towards the bottom of

I found an interesting JavaScript code snippet that creates a bubble particles effect around the cursor. You can download it from https://github.com/tholman/90s-cursor-effects. However, I encountered a problem when adding certain elements inside a specifi ...

Create an HTML form that sends email notifications using a third-party form backend platform

I recently designed a form using Webflow and integrated it with Getform.io for the backend platform. Everything is running smoothly, including data collection and file uploads. However, I now want to enhance the form by enabling it to automatically send ...

Solving the issue of .css being blocked due to MIME type while building tailwind is a common problem faced by

https://i.stack.imgur.com/nrDgJ.png While working on my tailwind CSS project, I ran npm run build. However, upon opening the built index.html file, I noticed that the CSS file was not loading properly. How can I resolve this issue? I am unsure of what st ...

Complete the execution of the jQuery function

It may seem like a simple idea - to stop executing a function, just use return false, return, or call on a function like undefined. However, in this case, it's not that straightforward. I'm working on a website project that includes a snake game ...

When working with NodeJS and an HTML form, I encountered an issue where the 'Endpoint'

Having trouble sending input data from a form to my nodejs endpoint. When I try printing the req.body, it shows up as undefined and I can't figure out why. Here is the relevant API code snippet: var bodyParser = require('body-parser') var e ...

Ways to incorporate a dictionary into your website's content

I am in the process of developing a website for educational purposes while also honing my web programming skills. On this website, I have encountered some complicated terms that may be difficult for users to understand, so I want to implement a tooltip/mod ...

No feedback received from JSON

Hi, I'm having trouble receiving JSON response using JavaScript. My goal is to display the JSON data as a treeview. index.html: <!DOCTYPE html> <html> <head> <title>JSON VIEW</title> <link href="https:// ...

How can I replicate the functionality of a div mimicking a select element using javascript upon clicking away from the element?

My task was to design a pseudo-select element that showcases columns for each row within the select. Due to HTML's restriction on allowing the <option> tag to include HTML, I had to find an alternate solution. One issue I encountered was replic ...

Jquery animation in Wordpress without any need for scrolling

My Wordpress site features some animations that work flawlessly when the site is scrolled. The code looks like this: jQuery(document).ready(function($){ $(window).scroll( function(){ if(!isMobile) { $('.animate_1').each ...

Using Angular and ASP.NET for image uploading functionality

Trying to source the image from the PC and upload it into the database as "Images/aaa.jpg". I am relatively new to Angular and have attempted an example that did not work for me. I have been stuck on this issue for almost 3 days trying to find a solution. ...

What is the best way to use PHP to call an ACF variable and substitute a nested HTML element?

Utilizing the repeater field in Wordpress' advanced custom fields, I have made the content on my site dynamic. View an image of the static markup here The following is how I structured the content using plain HTML: <div class="container" ...

A guide on effectively selecting an element with the '@font-face' tag

I'm endeavoring to design a distinctive logo by utilizing a personalized font... and am keen on incorporating it into my CSS As an illustration: the identifier for my div element is "logo" Should I merely employ this code? #logo { font-family: ...

The grid layout is being disrupted by a concealed input

As I work on styling my admin panels with Twitter Bootstrap, I've encountered a strange issue. Upon testing in Chrome 28 and Firefox, adding a simple hidden input seems to disrupt the grid layout. If the hidden input is moved into div.span6 or remove ...

html table displaying incorrect data while using dynamic data in vue 3

example status 1 Hello there! I'm trying to create a table (check out example status 1 for guidance). Here's the code snippet I am using: <table> <tr> <th>Product</th> <th>Price</th> <th>Av ...

Ways to decrease the space between lines of text within a single mat-option element

::ng-deep .mat-select-panel mat-option.mat-option { height: unset; } ::ng-deep .mat-option-text.mat-option-text { white-space: normal; } Currently, I have implemented this code to ensure that text in options wraps to the next line when it's too ...

Ways to rejuvenate an Angular element

Last month, I was called in to rescue a website that was in chaos. After sorting out the major issues, I am now left with fixing some additional features. One of these tasks involves troubleshooting an angular code related to videos and quizzes on certain ...