Is it possible to align the second "navbar" div inline with the first "navbar" div?

I am struggling to align the div "nav2" on the same line as "nav1", but it just won't move up. I've tried using float, but it's not working.

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}

body {
width: 100%;
height: 100vh;
}

#navbar {
position: fixed;
width: 100%;
display: 
}

#navbar ul {
list-style: none;
}

#navbar ul li {
display: inline-block;
padding: 10px 5px 0px 20px;
 }

 #nav2  {
 float: right;
 }
<div id="main">
    <div id="navbar">
        <div id="nav1">
            <ul>
                <li>How it works</li>
                <li>Why Company?</li>
                <li>Pricing</li>
                <li>About us</li>
                <li>Resource center</li>
            </ul>
        </div>
        <div id="nav2">
            <ul>
                <li>Get started</li>
                <li>Log in</li>
            </ul>
        </div>
    </div>
    <div id="head">
        <div>
            <h3>Company</h3>
        </div>
        <div>
            <h1>Invert Like an idiot</h1>
        </div>
        <div>
            <p>because money is lame</p>
        </div>
    </div>
</div>

I'm hoping to have both "nav1" and "nav2" on the same line like a normal navbar, but I want "nav2" to be aligned to the right side, which is why I made it a separate div with the class "nav2".

Answer №1

Here is a suggestion for what you may want to do:

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

body, html {
    width: 100%;
    height: 100vh;
}

#navbar {
    position: fixed;
    width: 100%;
    display: grid;
    grid-template-columns: auto auto;
    height: 50px;
}

#nav1 ul, #nav2 ul {
    display: grid;
    grid-gap: 20px;
    grid-auto-columns: minmax(min-contant, max-content);
    grid-auto-flow: column;
    height: 100%;
    align-items: center;

    list-style: none;
}

#nav1 ul {
    padding-left: 20px;
    justify-content: left;
}

#nav2 ul {
    padding-right: 20px;
    justify-content: right;
}



#head {
    padding: 50px 20px 0 20px;
}
<html>
<head></head>
<body>
    <div id="main">
        <div id="navbar">
            <div id="nav1">
                <ul>
                    <li>How it works</li>
                    <li>Why Company?</li>
                    <li>Pricing</li>
                    <li>About us</li>
                    <li>Resource center</li>
                </ul>
            </div>
            <div id="nav2">
                <ul>
                    <li>Get started</li>
                    <li>Log in</li>
                </ul>
            </div>
        </div>
    </div>
</body>
</html>

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 are some tactics for avoiding movement in the presence of a border setting?

I created a webpage that has the following structure: .topbar-container { width: 100%; position: fixed; top: 0; background-color: #2d3e50; z-index: 999; display: flex; transition: height 500ms; } @media (min-width: 992px) { .topbar-cont ...

Looking to implement a condition that prevents the echoing of HTML code when a certain template ID is selected?

Struggling with inherited PHP MVC code for a website, I encounter an issue on a specific page where unwanted code is echoed out. To prevent this, I aim to skip the echoing when a specific templateID (which I set as default) is selected. However, I'm u ...

Having trouble displaying API JSON data in a Vue.js table component

In my HTML file, I have implemented fetching data from an API and displaying it in a table successfully. Now, I am trying to convert the HTML file to use Vue.js, but encountering some issues. Despite being able to fetch data from the API with Vue, the tab ...

Creating an Innovative Grid Design with Varying Column Widths for Each Row

Seeking advice on achieving a specific layout using HTML. I have attempted to use HTML tables but struggled with creating rows with varying columns. Does anyone have recommendations for grid tools that may be more helpful? Thank you ...

Can you show me how to magnify multiple images when hovering over them without altering their dimensions?

I am working on a gallery that features multiple images and I want the images to zoom in when hovered over without resizing the container. My project is built using Bootstrap 4. <div class="row"> <div class="col-12"><img ...

What is the best way to add a specific class to another class in my CSS code?

Is it possible to apply a CSS class defined in css1.css to another HTML class defined in css2.css? In css1.css: div.classPredefined { border: solid 1px #000; } In css2.css: div.newClass { background: #CCC; /*apply-class: classPredefined;*/ } Although ...

Hover effect exclusively for specific child elements

Applying a hover effect to all divs inside a well can be done using the following code: .well:hover div { background-color:green } However, if you only want to apply the hover effect to specific divs inside the well, you can specify them in this way: ...

unable to choose an option if more than one radio button is being used

I am having trouble with two radio buttons that are supposed to select the gender of an applicant and the gender of the applicant's child. Both buttons are not functioning properly. Can someone assist me with this issue? Here is the code I am using: ...

Tips for adjusting the text color of input fields while scrolling down

I am currently working on my website which features a search box at the top of every page in white color. I am interested in changing the color of the search box to match the background color of each individual page. Each page has its own unique background ...

Pick Control - Utilize jQuery to display options that haven't been chosen before

Seeking assistance with a table view that includes a button for dynamically adding new rows. Each row contains a select control. Using Select2 for styling purposes. How can I ensure that when adding a new row, the select options only display those not prev ...

Encountering a problem when attempting to send an HTML email through PHP

Trying to use PHP to send email within an HTML code snippet. Here's the code I've written: <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { if ( mail ('<a href="/cdn-cgi/l/email-protection" class="_ ...

What is the best way to seamlessly transition from responsive design to mobile design?

While developing a single-page app, I encountered an issue with the layout when the screen width reaches a specific point. On narrow screens, I prefer to utilize the full width, but for wider screens, I want to limit the width for better readability. The l ...

Tips for displaying Japanese characters followed by numbers in a single line on a web browser using CSS

Combining Japanese characters with numbers without spacing can present formatting challenges. For example, with a string like "新しいフォルダ000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ...

Keep some table columns locked in place on your webpage while others are located off-screen, requiring a scroll to access

I have a question regarding an HTML table. There is a windows application that features a vertical scrollable table where some columns are fixed on the page while others remain outside the page. Here is an example: The black border represents the responsi ...

Experiencing issues with nested jQuery submit functions not triggering

I'm attempting to use AJAX to submit a form once a user has clicked on an image element. HTML <img class="remove_subscription" id="remove_mobile_id_<?php echo get_the_ID(); ?>" src="<?php echo get_bloginfo('template_director ...

Solve the issue of aligning two contents side by side using Bootstrap

I'm struggling to display two content items in one row. Here's my code snippet: <div class="row"> <div class="form-group"> <div class="col-lg-1"> <label>Insured First ...

Struggling to contain the image inside my div element

I'm having trouble with keeping the image inside my div element as it keeps stretching outside of it. I've tried researching for a solution but haven't been successful in finding one. Any help would be greatly appreciated! Here is the HTML/ ...

Creating visually stunning full-width sections with graphic backgrounds using Bootstrap

Trying to bring a unique design concept to life, courtesy of my talented graphic designer. However, this sleek look is proving to be quite the challenge as I navigate through bootstrap implementation. We are focusing on a call to action section that perfe ...

Tips for emphasizing the letters of the alphabet used in search functionality with Angular

Is there a way to highlight specific alphabets in the searched list instead of highlighting the entire word? Currently, when filtering the memberOffice and memberFacilities lists based on the alphabet entered in the search field, the entire text is highlig ...

The checkbox filter in Angular 6 has the ability to replace the previously selected

I've been working on creating a filter system using checkboxes. Below is a snippet of the code I'm currently using: filter.pipe.ts import { Pipe, PipeTransform, Injectable } from '@angular/core'; @Pipe({ name: 'filter2' }) ...