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

Revamped styling for responsive web design

I am relatively new to experimenting with Responsive Web Design for my website. I am struggling to align the class="label" correctly after checking it on various devices. Initially, I attempted this: Initially, everything seemed fine. However, upon viewin ...

Trigger the phone to vibrate once the animation has completed. This feature will only activate upon clicking the button

After the image completes its animation by sliding in from the left, I would like it to vibrate for 2 seconds using the HTML 5 vibrate API: navigator.vibrate(2000); An on-click event successfully triggers the vibration when a button is clicked: <butt ...

Semantic HTML and unambiguous: both

We are making an effort to enhance the semantics of our HTML, and one element that stands out in our code related to presentation is <div class="clear"></div> For instance, if we consider the following semantic HTML structure: <div class= ...

Declaration of Character Encoding in CSS3

Do I need to include a character encoding declaration in CSS3? When I add the @charset "utf-8"; declaration, Visual Studio's CSS3 validation displays a warning. Can anyone offer some guidance on this issue? ...

Arrange the div and ensure that the external JavaScript file functions properly when the page loads

I am encountering an issue with my JavaScript and CSS code. It works perfectly fine within the fiddle environment but fails to function properly outside of it. Here is the link to the fiddle When I embed the code into an HTML document directly, it does n ...

The ultimate guide to disabling iframe scrolling on Internet Explorer 8

After extensively searching for a solution, I realized that most answers focused on removing scrollbars rather than completely preventing the page from scrolling. My issue involves embedding an index.php file in an iframe on my website. Within the index.ph ...

Navigating external pages with Vue Router

Could really use some assistance. I've got a JSON file filled with various URL links, some internal and some external. This is what the JSON structure looks like: [ {stuff..., "Url":"https://www.google.com/", stuff..}, {stuff... ...

What steps can you take to ensure that a pre-loaded swf file occupies the entire browser

Allow me to elaborate on my query. I am currently designing a flash website and utilizing a small external preloader swf to load the main swf. I have successfully configured the preloader swf to occupy the entire browser window, however, once it loads in ...

Items positioned to the left will not overlap

Having trouble with floating elements? Need to ensure that box 3 aligns under box 1 when resizing the browser window? Use this HTML template: <div class="box"> <p>box 1</p> <p>box 1</p> <p>box 1</p> & ...

Is it possible to utilize the <hgroup> element with various <h> heading levels?

<hgroup> <h4>Role</h4> <h3>Graphic Designer</h3> <h5>Company: Godigital</h5> </hgroup> Should I keep this structure, or should I use the <h3><h4><h5> order instead? ...

Is AngularJS causing issues with Foundation modals? Any solutions to this problem?

Wondering how to manage Foundation4 modals with AngularJS? I've noticed that when I navigate from a modal to a new view, the old modal disappears but the page stays darkened as if it's still there in the background. I tried adding a class attribu ...

Restrict User File Uploads in PHP

I have a system set up that enables users to upload files under 200 MB. Once the file is downloaded once, it will be automatically deleted. Additionally, all files are deleted from the server after 24 hours. I am looking for a way to limit the number of up ...

Which HTML element does each script correspond to?

Are there any methods to identify the script used in certain HTML elements? For instance, if I wish to determine the script responsible for creating a drop-down menu, I can locate the HTML and CSS for the menu but not the JavaScript (or other scripts). I ...

Title with lower border shorter than width

Looking to achieve an underline effect with a bottom border that is narrower than the width of the h2 title. Though I typically avoid uploading images, here is one to provide further clarification of my question: ...

Angular renders HTML elements

Greetings! I am currently experimenting with using AngularJS for the frontend and Wordpress as the backend of my project. To load content from Wordpress into Angular, I am utilizing a JSON wordpress plugin along with making $http requests. The content th ...

Dealing with a div height problem in HTML/CSS

I'm experiencing an issue where my footer is overlapping with the bottom of my div. I've attached an image for reference but I can't seem to figure out what's causing the problem. I've tried adjusting the height values without succ ...

What steps can be taken to avoid an input with a width of 100% from overflowing?

I'm facing an issue that needs to be resolved. Currently, I have a group of div elements arranged in a table-like structure with a row and three columns. When these divs reach a maximum width of 768px, the first column is hidden, leaving only the se ...

Prevent iPhone from automatically changing phone numbers to grey text color

For some reason, the iPhone keeps changing the phone numbers on my site to grey, despite using Drupal 7. I've heard that this is because the iPhone wants to make them stand out for users to interact with. I tried adding the following code to the head ...

Should we make it a routine to include shared sass variables in each vue component for better practice?

Within my Vue application, there are numerous components that rely on shared variables like colors. I'm considering having each component import a global "variables.scss" file. Would this approach have any adverse effects? ...

Trigger the click event on a specific class selector to extract the corresponding ID

I have an HTML Table with each row: <table> <tr><td><a href='#' id='1' class='delete'>delete</a></td></tr> <tr><td><a href='#' id='2' class='de ...