The issue with the floating of the Div element on the right side appears to be tied to the current CSS present in the code

Struggling to create a clean header using HTML and CSS, I'm facing an issue where my button list refuses to float to the right, resulting in an awkward layout.

I attempted various methods like floating the list, floating the ul, and even floating the div to no avail.

Oddly enough, when I isolated the list on a separate page, it did float correctly to the right. But as soon as I integrated my CSS, the problem resurfaced without any clear cause.

@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap');

header {
  display: inline-flex;
  background-color: grey;
  width: 110%;
  margin-left: -10px;
  margin-right: -10px;
  margin-top: -10px;
  height: 100px;
  align-items: center;
}

.logo {
  height: 100px;
  margin-top: -4px;
  font-family: "Montserrat", sans-serif;
}

ul li {
  font-family: "Montserrat", sans-serif;
  font-size: 18px;
  width: max-content;
  list-style-type: none;
  display: inline;
  padding: 10px;
}

.headerButton {
  transition: 0.1s ease-in;
  color: black;
  text-decoration: none;
  font-weight: 500;
  width: 10px;
}
<header>
  <a href="https://codepen.io/ThatCanadianKid_/full/qBwgVpJ">
    <img src="https://www.kadencewp.com/wp-content/uploads/2020/10/alogo-4.png" class="logo">
  </a>
  <div style="float:right;">
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About Us</a></li>
      <li><a href="#">Contact Us</a></li>
    </ul>
  </div>
</header>

If you require further details, feel free to ask. I'm relatively new to web development, so please be gentle with your critique of my code.

Answer №1

The issue arises from the container being set as an inline-flex element, causing the "floated" div to act as a flex-item where float properties do not apply.

To resolve this, you can include margin-left: auto; in the div to shift it to the right, a common technique when working within a flex container:

@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap');

header {
  display: inline-flex;
  background-color: grey;
  width: 110%;
  margin-left: -10px;
  margin-right: -10px;
  margin-top: -10px;
  height: 100px;
  align-items: center;
}

.logo {
  height: 100px;
  margin-top: -4px;
  font-family: "Montserrat", sans-serif;
}

ul li {
  font-family: "Montserrat", sans-serif;
  font-size: 18px;
  width: max-content;
  list-style-type: none;
  display: inline;
  padding: 10px;
}

.headerButton {
  transition: 0.1s ease-in;
  color: black;
  text-decoration: none;
  font-weight: 500;
  width: 10px;
}
<header>
  <a href="https://codepen.io/ThatCanadianKid_/full/qBwgVpJ">
    <img src="https://www.kadencewp.com/wp-content/uploads/2020/10/alogo-4.png" class="logo">
  </a>
  <div style="margin-left: auto;">
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About Us</a></li>
      <li><a href="#">Contact Us</a></li>
    </ul>
  </div>
</header>

Answer №2

Realized that the problem stemmed from my use of inline-flex, which is incompatible with float.

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 process for creating a see-through background?

I'm not sure if this question has been asked before, so please forgive me and provide a link if it has. However, I haven't come across it on here yet. My aim is to create a transparent background that displays the wallpaper of the laptop's ...

How can Selenium in Python be used to click a JavaScript button?

I need help automating the click of a button on a webpage using selenium Here is the HTML for the button: <div class="wdpv_vote_up "> <input value="7787" type="hidden"> <input class="wdpv_blog_id" value="1" type="hidden"> </div& ...

Can inline styling be overridden with CSS?

<td class="subrubr" nowrap="nowrap" valign="bottom"> <a name=""></a> Some lengthy text to be shown here. </td> This snippet of code is automatically created by a PHP script. However, ...

Next.js in combination with Tailwind CSS

While attempting to customize the styling for my Next.js 13 app, I encountered an error message that states: Syntax error: C:\Users\User\Documents\webdev\TicketingApp\ticketing-app\app\globals.css The text-default- ...

Creating a PHP and MySQL powered drop-down menu that features multiple columns

I am looking to create a dropdown menu with multiple columns. The options data is retrieved from MySQL using PHP. Below is the code I have: $query = mysql_query("SELECT * FROM accounts"); <select class="form-dropdown validate[required]" style="widt ...

Exploring Material UI: Step-by-step guide to customizing component styles

After reviewing the documentation, I have discovered two ways to style the component: import * as React from 'react'; import { makeStyles } from '@mui/styles'; import Button from '@mui/material/Button'; const useStyles = make ...

How can you hide specific elements in HTML/CSS based on window size without relying on media queries?

How can I create an HTML/CSS toolbar where specific elements disappear completely when the browser size is decreased, similar to how the favorites bar functions in most browsers? The toolbar should be able to display a varying number of items. In this cas ...

What is the best method for storing "game progress" in local storage?

I am currently working on coding a simple Risk game where players can click on countries to change their color from red to green, yellow, purple, and back to white. The game starts with an "all-white" map. I am looking to create different save slots so th ...

Is there a way to obtain background color values in decimal form?

I want to extract the background color in decimals that I have set, for example rgb(44.9, 19.373737, 255), using this jQuery code $("p").css("background-color") However, whenever I use it, the value gets rounded to rgb(45, 19, 255) All I need is to ret ...

Utilizing JavaScript Files Instead of NPM as a Library for Open Layers: A Step-by-Step Guide

I've been attempting to get Open Layers to function in my Eclipse web development environment, but I've encountered some challenges along the way. The setup instructions provided on the Open Layers website focus mainly on using npm. Nevertheless, ...

The layout option is not specified within the ejs-mate package

error boilerplate I am baffled as to why the layout is not being defined. I have installed ejs-mate and ejs, yet it still gives this error. <% layout('layouts/boilerplate') %> <h1>All campgrounds </h1> <div> <a ...

Aligning text in the center of a header, positioned beside an image

I am facing an issue with centering text within a banner. The banner is divided into 12 columns, with a cross icon placed in the left-most column for closing the window. However, the text is not centering within the whole banner width but only within the s ...

I need to position the CSS vertical scrollbar on the right side of the page

I can't figure out how to move the vertical scrollbar to sit on the right side of my site's work page. Any help would be greatly appreciated. Below is the provided HTML code: <div class="heading"> <h1>PRINT</h1> &l ...

Tips for updating information when a button is chosen

Hello everyone, I need some help with a form that has three select buttons. The button labeled "Distribute" is already selected when the page loads, and it contains information about full name, password, and location. How can I use JavaScript to create a c ...

What is causing jQuery toggleClass to fail in removing a class?

I have successfully implemented a Skills accordion feature, but I am now trying to add a button that toggles all the skill sections at once. However, I am facing issues with jQuery not correctly adding or removing classes on the .accordion-trigger-all elem ...

Alignment of images in a grid layout using Bootstrap 4

I am currently working on constructing an image grid with Bootstrap 4. The grid is contained within the class "showcase." In the first row, there are two landscape photos, and in the second row, there are three portrait photos. My challenge is to align the ...

Customize default values in LESS CSS

I've been attempting to create a LESS mixin that uses a default value if a variable is not set, but no matter what I try my code always defaults to the backup value. Here's what I have: @color : red; .mixin (@color : blue) { color: @color; ...

Tips for validating form data in JavaScript before invoking a PHP file

When working with a form that has an action attribute to call another PHP page, I want to ensure that one text field is not empty by validating it with JavaScript before submission. How can I accomplish this using the <input type"submit"> tag? ...

Is it possible to store values in LocalStorage by clicking?

Is there a way to store this value in localstorage whenever the user clicks either up or down??? <script> var Clicks = 800; function UpClick() { Clicks = Clicks + 25; document.getElementById('CountedClicks').innerHTML = C ...

CSS positioning with absolute value + determine the number of elements positioned above

Is it feasible to adjust the position of an absolutely positioned element based on the height of the element above it? The objective is to align elements with the class "pgafu-post-categories" one line above an H2 heading, even when the lengths v ...