Guide to positioning a list to align right within a div

I'm having trouble getting the list to float to the right inside a div. Here is the HTML code:

<div class="topdiv">
    <header>MakeItWork</header>
      <ul class="navigation">
        <li>Home</li>
        <li>Shop</li>
        <li>Contact</li>
      </ul>
  </div>

Below is the CSS I am using:

.topdiv{
  width: 100%;
  overflow: hidden;
  background-color: black;
  color: white;
  display: flex;
}

.topdiv header{
  margin-top: auto;
  margin-bottom: auto;
  font-size: xxx-large;
  margin-left: 5%;
}


.navigation{
  text-decoration: none;
  margin: none;
  padding: none;
  float: right;
}


.navigation li{
  padding: 10px;
}

Edit: My goal is to have the header text (MakeItWork) on the left side of the page and the list (with items like Home, Shop, and Contact) on the right side of the page. You can see an example in this picture.

Answer №1

To align the title and list at different ends, add float:right to .navigation li and justify-content:space-between to .topdiv.

It looks like you're creating a navigation menu. I also included the extra rule list-style: none for .navigation.

.topdiv{
  width: 100%;
  overflow: hidden;
  background-color: black;
  color: white;
  display: flex;
  justify-content: space-between;
}

.topdiv header{
  margin-top: auto;
  margin-bottom: auto;
  font-size: xxx-large;
  margin-left: 5%;
}


.navigation{
  text-decoration: none;
  margin: none;
  padding: none;
  float: right;
  list-style: none;
}


.navigation li{
  padding: 10px;
  float: right;
}
<div class="topdiv">
    <header>MakeItWork</header>
      <ul class="navigation">
        <li>Home</li>
        <li>Shop</li>
        <li>Contact</li>
      </ul>
  </div>

Answer №2

To achieve spacing between elements, you can apply justify-content:space-between. It's important to note that using float won't function as expected when working with flex.

.topdiv{
  width: 100%;
  overflow: hidden;
  background-color: black;
  color: white;
  display: flex;
  justify-content:space-between
}

.topdiv header{
  margin-top: auto;
  margin-bottom: auto;
  font-size: xxx-large;
  margin-left: 5%;
}


.navigation{
  text-decoration: none;
  margin: none;
  padding: none;
}


.navigation li{
  padding: 10px;
}
<div class="topdiv">
    <header>MakeItWork</header>
      <ul class="navigation">
        <li>Home</li>
        <li>Shop</li>
        <li>Contact</li>
      </ul>
  </div>

Answer №3

.topdiv {
  width: 100%;
  background-color: black;
  color: white;
  display: flex;
  justify-content: space-between;
}

.topdiv header {
  font-size: xxx-large;
}

.navigation {
  float: right;
  list-style: none;
}

.navigation li {
  padding: 10px;
  float: right;
}
<div class="topdiv">
  <header>CustomizeIt</header>
  <ul class="navigation">
    <li>Home</li>
    <li>Products</li>
    <li>About Us</li>
  </ul>
</div>

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

Format the image to fit within a div container

I'm currently utilizing Bootstrap and am looking to insert some images into my div while ensuring they are all the same size (standardized). If the images are too large (as they typically are), I want to resize them to fit within my div and crop them ...

Execute AJAX function when loading a form populated from a MySQL/PHP database

I am currently working on a drop-down menu that is being populated from a MySQL table using PHP. The goal is to have a second drop-down menu triggered based on the selection made in the first form. This functionality works perfectly when a selection is mad ...

Tips for modifying and refreshing data in a live table with JQuery

One challenge I'm facing is figuring out how to transfer the data from a dynamic table back into input fields when clicking on the edit button of a specific row. Additionally, I need to update that particular row based on any changes made to the value ...

Remove elements generated by the .after method with Jquery

In my HTML file, I have a table with hard-coded column headers: <table id="debugger-table"> <tr> <th>Attribute</th> <th>Computed</th> <th>Correct</th> </tr> </table&g ...

The function .val() is not a recognized method

hello everyone here is the section of my HTML code: <div class="radio"> <input type="radio" name="certain" id="oui" value="oui"/> <label for="oui"> oui </label> <br /> <input type="radio" name="certain" id=" ...

Using TypeScript with Angular, you can easily include parameters to HTML tags

I have an HTML element that looks like this: eventRender(info){ console.log(info.el); } This is the output I'm seeing: https://i.stack.imgur.com/G0hmw.png Now, I want to include these attributes: tooltip="Vivamus sagittis lacus vel augue ...

Sending selected checkbox values to another JSP page with the help of JavaScript

I have some JSP code that I need help with. How can I pass checked checkbox values from a.jsp to b.jsp using JavaScript? Any assistance would be greatly appreciated. <html> <head> <meta http-equiv="Content-Type" content="text/ ...

Automated logout feature will be enabled if no user interaction is detected, prompting a notification dialog box

Here is my working script that I found on this site. After a period of idle time, an alert message will pop up and direct the user to a specific page. However, instead of just the alert message, I would like to implement a dialog box where the user can ch ...

Elements on the page are being truncated beyond the visible viewport

Encountering an issue with a web page I'm currently developing that is proving challenging to explain. The problem occurs when the page is viewed in a small browser window and cuts off when scrolling horizontally to content outside of the viewport. Wh ...

The jQuery dropdown menu smoothly expands to reveal all hidden submenu options

I'm currently encountering an issue with jQuery. I am trying to create a responsive drop-down menu with sub-menus. The behavior I want is that if the window width is less than 700px, the submenus will trigger onClick. And if the window is wider than 7 ...

The div stops scrolling after the Matrix3d transformation is applied, causing the scrolling functionality to cease

The issue arises when attempting to scroll the #content div, as it seems unresponsive. Oddly enough, scrolling with the scrollbar does work: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> ...

Showing a picture in Angular from a stored image on a node.js server

I'm curious about security measures. Let's say I've uploaded an image of an animal to the server, such as 1545419953137bear.jpg, which is stored in my backend uploads folder along with other images. On the frontend, I use an img element wit ...

jQuery's click event on dynamically generated AJAX elements sometimes fails to trigger randomly

When I use the getData() function to retrieve ajax content, it dynamically adds elements based on the JSON response from the server. The code snippet below shows how the elements are added: $("#list").append('<div class="ui card fluid" id="' ...

User interface for creating a platform resembling Product Hunt or Reddit

I am currently developing a web application similar to Product Hunt. The back-end API is up and running smoothly, and I have successfully implemented AngularJS for the front-end. However, I lack experience in designing the look and feel of the site. Shou ...

In the HTML body, create some breathing room on the side

While working on a virtual restaurant menu with bootstrap, I encountered an issue where there was a persistent little space at the right side of my page that remained unfilled. Despite trying various solutions and inspecting elements, I couldn't ident ...

What's the best way to target an input that's appearing as it slides in from the edge of the screen?

My webpage has an element called #cols that is three times wider than the <body>. This element contains three columns, each exactly as wide as the <body>. When a button is clicked, the #cols element slides over by the width of one column while ...

I possess a primary menu with several submenus, yet I am encountering difficulty accessing the submenus. My goal is to efficiently navigate and access the appropriate submenu within the main menu

I am facing an issue with my CSS where the sub menu is currently showing from the left side, but I would like it to slide up and down instead. .outer { width: 100%; text-align: center; background-color: Gray; padding-top: 20px; bord ...

Managing selected ticket IDs in a table with AngularJS

I have a table that includes options for navigating to the next and previous pages using corresponding buttons. When I trigger actions for moving to the previous or next page (via controller methods), I store the IDs of checked tickets in an array $scope. ...

Guide to adding a Scrollable Navbar

Is the term "scroll bar" really accurate? I want to create a scrollable feature where users can easily select a city using their mouse wheel (or swipe on a smartphone) and then choose from possible cities within that country in a second window. Something s ...

Automatically adjust height directive to fill up the remaining space

Is there a way to dynamically adjust the height of an element to fill the remaining space within its container? In my current layout, I have a fixed-height header (or menu) in pixels, a content area that may overflow the window height and require scroll b ...