What is the best way to position the div element to the right side of the webpage?

Looking at my HTML code below, I am trying to reposition the 'site-logo' and 'nav-search-wrapper' div elements to the left side of the parent div (top-nav) and have the 'list' div element appear on the right side. However, they are currently all stacked up together on the left side of the page.

<!DOCTYPE html>
<html>
<head>
    <title>AirBnB</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<!-- Top Nav -->
<div class="top-nav">
    <div class="site-logo">
            <a href="index.html"  class="logo">
                <img src="https://upload.wikimedia.org/wikipedia/commons/6/69/Airbnb_Logo_B%C3%A9lo.svg" alt="AirBnB">
            </a>
    </div>  
    <div id="nav-search-wrapper">
            <form action="#" method="GET">
                <input type="text" name="search" id="nav-search" placeholder="Search">
            </form>
    </div>
    <div class="list">
        <ul>
            <li><a href="">Become A Host</a></li>
            <li><a href="">Help</a></li>
            <li><a href="">Sign Up</a></li>
            <li><a href="">Log In</a></li>
        </ul>
    </div>
</div>
</body>
</html> 

Presenting my custom CSS:

/* Customized CSS */
body{
    padding: 0px;
    margin: 0px;
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
    color: #484848;
    line-height: 1.43;
}

p{
    font-size: 16px;
    margin: 0px;
    padding: 0px;
}

a: link{
    font-size: 16px;
    text-decoration: none;  
    margin: 0px;
    padding: 0px;
}

a: visited{
    text-decoration: none;
    padding: 0px;
    margin: 0px;
}

h1, h2, h3, h4, h5, h6, ol, ul, li{
    margin: 0px;
    padding: 0px;
}

ul, ol{
    list-style-type: none;
}

::selection{
    color: #fff;
    background-color: #333;
}

::-moz-selection{
    color: #fff;
    background-color: #333;
}

.clearfix::after{
    content: "";
    display: table;
    clear: both;
}

/* Top Nav Styling */

.top-nav{
    position: fixed;
    width: 100%;
    height: auto;
    border-bottom:  1px solid #ccc;
    display: flex;
}

.site-logo{
    float: left;
}

.logo:link{
    color: #484848;
    display: inline-block;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    -o-transition: all 0.3s ease;

}

.logo:hover {
    background-color: #f1f1f1;
}

.logo:visited{
    color: #484848;
}

.logo img{
    padding: 12px 18px;
    width: 100px;
    vertical-align: middle;
    border-right: 1px solid #ccc;
}

#nav-search-wrapper{
    float: left;
    display: inline-block;
    width: 490px;
    height: 100%;
}

#nav-search-wrapper form input{
    box-sizing: border-box;
    padding: 22px 10px 18px 52px;
    width: 100%;
    border: none;
}


#nav-search-wrapper form input::-webkit-input-placeholder{
    color: #666;
    font-size: 14px;
}

.top-nav .list{
    float: right;
    border: 1pt solid black;
}

.top-nav .list li{
    display: inline-block;
    line-height: 52.547px;
}

.top-nav .list ul{
    height: 100%;

}

Any suggestions on how to correctly adjust the positioning of the 'list' div element to the right side, while moving the other two div elements to the left within the top-nav parent element?

Current layout shown here. (The Airbnb Logo is a placeholder image in this learning project) https://i.stack.imgur.com/x0Dcg.png

Answer №1

The issue lies in this section:

.top-nav{
    display:flex;
}

If there is no specific reason for using flex in your case, simply removing it will resolve the problem (moving the list div to the right).

body{
    padding: 0px;
    margin: 0px;
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
    color: #484848;
    line-height: 1.43;
}

p{
    font-size: 16px;
    margin: 0px;
    padding: 0px;
}

a:link{
    font-size: 16px;
    text-decoration: none;  
    margin: 0px;
    padding: 0px;
}

a:visited{
    text-decoration: none;
    padding: 0px;
    margin: 0px;
}

h1, h2, h3, h4, h5, h6, ol, ul, li{
    margin: 0px;
    padding: 0px;
}

ul, ol{
    list-style-type: none;
}

::selection{
    color: #fff;
    background-color: #333;
}

::-moz-selection{
    color: #fff;
    background-color: #333;
}

.clearfix::after{
    content: "";
    display: table;
    clear: both;
}

/* Top Nav CSS */

.top-nav{
    position: fixed;
    width: 100%;
    height: auto;
    border-bottom:  1px solid #ccc;
}

.site-logo{
    float: left;
}

.logo:link{
    color: #484848;
    display: inline-block;
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    -o-transition: all 0.3s ease;

}

.logo:hover {
    background-color: #f1f1f1;
}

.logo:visited{
    color: #484848;
}

.logo img{
    padding: 12px 18px;
    width: 100px;
    vertical-align: middle;
    border-right: 1px solid #ccc;
}

#nav-search-wrapper{
    float: left;
    display: inline-block;
    width: 490px;
    height: 100%;
}

#nav-search-wrapper form input{
    box-sizing: border-box;
    padding: 22px 10px 18px 52px;
    width: 100%;
    border: none;
}


#nav-search-wrapper form input::-webkit-input-placeholder{
    color: #666;
    font-size: 14px;
}

.top-nav .list{
    float: right;
    border: 1pt solid black;
}

.top-nav .list li{
    display: inline-block;
    line-height: 52.547px;
}

.top-nav .list ul{
    height: 100%;

}
<html>
<head>
    <title>AirBnB</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<!-- Top Nav -->
<div class="top-nav">
    <div class="site-logo">
            <a href="index.html"  class="logo">
                <img src="https://upload.wikimedia.org/wikipedia/commons/6/69/Airbnb_Logo_B%C3%A9lo.svg" alt="AirBnB">
            </a>
    </div>  
    <div id="nav-search-wrapper">
            <form action="#" method="GET">
                <input type="text" name="search" id="nav-search" placeholder="Search">
            </form>
    </div>
    <div class="list">
        <ul>
            <li><a href="">Become A Host</a></li>
            <li><a href="">Help</a></li>
            <li><a href="">Sign Up</a></li>
            <li><a href="">Log In</a></li>
        </ul>
    </div>
</div>
</body>
</html> 

Answer №2

It's not possible to shift the div.list to the right side due to the flexbox layout of your top-nav. Simply remove the display:flex; property from the .top-nav class.

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

Modify the anchor text when a malfunction occurs upon clicking

Whenever I click on the link, I am able to retrieve the correct id, but the status changes for all posts instead of just the selected item. Below is the HTML code: <div th:each="p : ${posts}"> <div id="para"> <a style="float: right;" href= ...

jQuery Ajax Redirect Form

I am currently developing an HTML application with a form. Upon clicking the submit button, I initiate a server-side call using jquery.ajax(). However, when the server returns an exception, such as a Status Code 500, I need to display an error message on t ...

Design elements using CSS within the <th> tags

When working with HTML tables, the use of a <th> element allows for the implementation of a scope attribute. This attribute serves to indicate whether the header cell is associated with its subsequent column, row, or group. Is it feasible to leverage ...

Issue when attempting to animate an SVG point using translateX transformation

I am attempting to create a basic animation using the translate X property on a section of my svg when hovering over the element. Here is the code I have so far: <html> <style> .big-dot:hover { transform: translateX(20px); animat ...

Tips for highlighting a Material UI Button when pressing the Enter key

Once the user has completed the final input, they need to press the save button The 'Tab' key typically moves the focus to the next element (in this case a button), but I want to use the 'Enter' key for this action. Can anyone advise o ...

The FileReader.result is found to be null

Currently, I am in the process of setting up a page that allows users to upload a txt file (specifically a log file generated by another program) and then modify the text as needed. Initially, my goal is to simply console.log the text, but eventually, I pl ...

Converting XML to HTML with the help of XSLT transformation customization

I need assistance in adjusting the XSLT 1.0 transform within the provided xsl file to create an HTML version of the table coded in the attached XML file. The generated HTML output file should display the table from the XML file with alternating row backgro ...

Flexbox Resizing Notification(?)

Recently, I've been utilizing flexbox in my layout design and it has been a game-changer. However, I am facing an issue that might be linked to my heavy use of AngularJS, particularly the ng-include feature. The specific problem arises when I incorpo ...

Changing the animation associated with a hover action - tips and tricks!

My navigation header includes links to various websites, some of which are displayed as drop-down menus. I have implemented an animation and style change on hover to visually indicate the active link and display all available options in case of a dropdown ...

Element in list displaying a distinct alignment from the rest

I currently have a navigation bar based on a list, which looks something like this: https://i.stack.imgur.com/e1Dmb.png My concern is how to position the "Logout" item on the right side of the screen. I've tried adding clear list items but that seem ...

tilt and give motion to image within canvas

I am looking to incorporate skewing and animation effects on an image displayed on a canvas. While I have successfully drawn the image on the canvas using the code snippet below, I am unsure about how to apply skewing and animation to the image post-drawin ...

Is there a way to line up these two tables or divs using a shared parent header div?

In the process of developing this webpage, I encountered a layout that resembles the following: Here is an approximation of the HTML structure: <div class="title"> <table> <tr> <td width="35%">Table 1a Head ...

Tips for shuffling the sequence of EJS variables

I am currently working on creating a quiz that consists of multiple choice questions. In order to display the Question, Correct Answer, and 3 other wrong options, I am utilizing EJS variables. The format will be similar to the following example: Question: ...

Function that activates traffic lights

Currently, I'm encountering errors while working on this project in Notepad. Can you help me figure out what's wrong with my code? I'm attempting to create an onload traffic light using an object array. The requirement is to implement this f ...

Interacting with CSS buttons using Selenium

Currently, I am working on a test case in Java where I am using Selenium to record a series of events and then play them back on an application. Here is the code snippet I have: // *The app opens a new window* // Get handle of the main window Stri ...

What is the methodology behind stackoverflow's implementation of comments functionality?

I am looking to implement a feature comparable to the comment system on Stack Overflow for this website. The idea is to enable users to type in a text, click submit, and instantly see it displayed on the page without having to navigate away. It has to be ...

Angular2: Dynamically switch between selected checkboxes in a list

Is there a way to toggle a checked checkbox list in Angular2? I am trying to create a button that, when pressed while the full list is visible, will display only the checked items. Pressing the button again would show the entire list. Here's the Plu ...

How can I make my Grid items in React and Material-UI occupy the entire horizontal space without wrapping to the next row?

I am currently utilizing Material-UI within a React 16.10 project. My goal is to create a table where the left column consists of an icon, while the right column displays a label and address stacked on top of each other. I want the items in the right colum ...

Ensure consistency in CSS3 background color transitions

There are multiple elements on the webpage with background transitions that change from one color to another: @-moz-keyframes backgroundTransition /* Firefox */ { 0% {background-color:#ff7b7b;} 33% {background-color:#7fceff;} 66% {backgr ...

Deselect the DOM element

Here is a jQuery code snippet: $(document).ready(function () { $(".story-area > h1, .story-area > p, .story-area > div > p").text(function () { return convertString($(this).text()); }); }); Additionally, there is a function de ...