I am looking to arrange two div elements and one navigation bar into the header, positioning them at the top-left, top-center, and top-right using CSS. How

I'm attempting to arrange three divs within the <header>: div1 (logo) at the top left of the page, nav2 (menu bar) at the top center of the page, and div3 (social networks) at the top right of the page. However, I am unsure of how to achieve this layout. Here is the HTML code that I have tried:

<header>
    <div id="logo"></div>
    <nav>
        <ul>
            <li><a></a></li>
        </ul>
    </nav>
    <div id="links">
        <a></a>
    </div>
</header>

And here is the corresponding CSS code:

nav{
    background-color: #215177;
    border: 1px solid #215177;
    color: white;
    display: block;
    margin: 0;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

#logo{
    height: 120px;
    width: 50px;
    float: left;
}

nav ul{
    margin: 0;
    padding: 0;
    list-style: none;
    text-align: center;
}

nav ul li {
    margin: 0;
    display: inline-block;
    list-style-type: none;
    transition: all 0.2s;
}

nav > ul > li > a {
    color: white;
    display: block;
    line-height: 2em;
    padding: 0.5em 2em;
    text-decoration: none;
}

#links{
    float: right;
    position: absolute;
    top:0;
}

Answer №1

Your code seems to be missing some crucial elements, especially if you plan on optimizing it for mobile devices.

Remember to properly enclose all DIVs and content within your layout to ensure a polished final product.

Check out this example that closely resembles what you're aiming for. It utilizes similar classes and IDs:

<header> 
<div id='logo'>Logo</div> 
<nav> 
    <ul> 
        <li> 
            <a href='#0'>Home</a>
        </li>

        <li>
            <a href='#0'>About</a>
        </li>
        <li>
            <a href='#0'>Blog</a>
        </li>
        <li>
            <a href='#0'>Contact</a>
        </li>
    </ul>
</nav>    
<div id='links'>Links go here</div>
<div class='clear'></div>              
</header>

I've also included some basic CSS in the example to help you get started on the right track.

Answer №2

Give this a try:

<div id="top">
    <header> 
        <div id="logo"></div> 
        <nav> 
            <ul> 
                <li> 
                    <a></a> 
                </li> 
            </ul> 
        </nav> 
        <div id="links">
            <a></a>
        </div> 
    </header>
</div>

Now for the CSS:

#top{
    width:100%;
}
#logo{
    width:9%;
    float:left;
}
nav{
    width:78%;
    float:left;
}
#links{
    width:9%;
    float:right;
}

Please Note: If you notice that the total width of nav + link + logo does not equal 100%, it may be due to padding applied in your CSS.

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

"Creating multiple circles on an HTML5 canvas using an iPad: A step-by-step guide

My current code is only drawing one circle at a time on an iPad view, but I want to be able to draw multiple circles simultaneously. How can I achieve this? // Setting up touch events for drawing circles var canvas = document.getElementById('pain ...

Utilizing JavaScript to enable a Bootstrap 5 dropdown menu to open on hover for desktop users and be clickable for mobile users

I am currently using Bootstrap 5 to design a website and I'm facing an issue with creating a navbar dropdown. On desktop, I want the dropdown to open on hover and redirect the user to a new page when clicked. However, on mobile devices, I only want th ...

Page design ruined as a result of oversized fonts in IE9 for <h2> elements

Everything looks great on various browsers, except for the notorious IE9. We've implemented a block-style layout with a width of 660px, centered on the page. Despite setting the h2 width to 660px to match the layout, IE9 displays the font size much ...

What is the best way to align my content alongside my sidebar?

I am facing some challenges with my website layout because I used Bootstrap to integrate a sidebar. The sidebar has caused issues with the positioning of my content, and I'm struggling to align it properly next to the sidebar on the left side. Please ...

Issues with displaying PNG background images in older versions of IE while using HTML5?

Below is the HTML code that I am working with: <section class="first-content-top"> <img src="images/img-diner.png" /> <h1>Menu</h1> </section> <section class="first-content-middle"> <article class="m ...

Adapt the stylesheet for mobile devices using CSS

I am struggling with updating file paths in CSS depending on whether the end user is accessing my site from a PC or mobile device. Below is my CSS code, where I attempted to redirect users if they are on a handheld device: <link rel="stylesheet" type=" ...

Modifying the label focus does not alter the CSS style

I'm struggling with a simple form where I want to highlight the focused labels by changing their background colors. However, the jquery code doesn't seem to be working as expected. Despite no errors showing up in the console, the functionality is ...

Utilizing C# ASP.NET to Extract Data from a Web Page Post JavaScript Execution

Looking to extract all links from a web page in order to review where cookies are being set for compliance with UK legislation. In an effort to streamline the process, I am exploring automation options to save time. However, a challenge I am facing is tha ...

Is it possible for me to develop a mobile application using JavaScript, HTML, and CSS and distribute it for sale on the App Store, Google Play Store, and Microsoft Mobile App Store at

I have a keen interest in web standards such as Javascript, HTML, and CSS. My goal is to utilize these languages to develop applications for mobile devices like phones and tablets. I am also considering selling these applications on various platforms inclu ...

Deleting a division with the help of media queries

As a challenge, I am attempting to eliminate the .navbar-brand>img element once the screen size exceeds 768px by using media queries. Unfortunately, my efforts have not been successful so far. Although the styling applied to the img is successfully remo ...

What is the ideal JavaScript framework for implementing drag-and-drop, resize, and rotation features?

I am planning to create a web application that involves images and text with user handle functionalities such as drag-and-drop, resizing, and rotating. Although I have tried using JQuery UI js to implement drag-and-drop, rotate, and resize, I have encount ...

Dynamic JavaScript animation to retrieve the position of an element on-the-fly

I am currently exploring the world of animation in JavaScript and I have a few practical questions. In my script, I am attempting to "launch" a "rocket" upon clicking a "button". What I've observed is that although my function calculates values as int ...

Pictures acting erratic following the implementation of two setTimeout functions

I encountered an issue while developing a pong game using html/css/javascript. Everything was going smoothly until I introduced a second setTimeout() function. Here is the snippet of my html code: <!DOCTYPE html> <html> <head> <scrip ...

How can you achieve the effect of "hovering over an image to automatically start playing a muted video within the image itself"?

[![enter image description here][1]][1]I am working with WordPress and Elementor, and I want to create a hover effect where an image triggers a muted video to play within the image area on mouseover. The video should stop playing when the mouse is not hove ...

Creating a Date Computation Tool that Adds Additional Days to a Given Date

I have a challenge where Date 0 represents the start date, Date 1 is the result date after adding a certain number of days (NDays). I am looking for help in JavaScript to calculate Date0 + NDays = Date1. Please assist me as my coding knowledge is quite l ...

Getting the values of several labels using a class name - a comprehensive guide

Is there a way to retrieve the values of labels with the "timeAuction" class? I'm currently working on a JavaScript function that will target each label with the class name timeAuction and adjust its value. The number of labels with this class can va ...

What is the process for extracting the background color from a typescript file in Angular and connecting it to my HTML document?

My typescript array population is not changing the background color of my div based on the values in the array. I've attempted to set the background using [style.backgroundColor]="statusColor[i]", where statusColor is an array declared in my typescrip ...

What is the method to store and retrieve data attributes linked to elements such as select options within the React framework?

Despite my efforts, I'm currently unable to retrieve the data attribute from an option using React as it keeps returning null. <select onChange={(e) => this.onIndustryChangeOption(e)} value={this.props.selectedIndustry}> <opti ...

Troubleshooting a CSS problem within mat-autocomplete component in Angular 7

While using mat-autocomplete, I noticed that when I select an option from the dropdown and then scroll through the main bar, the dropdown menu does not move along with the autocomplete input field. view image here Here is the code snippet: <td width ...

I am looking to adjust the width of an element within an Iframe

In my single post, I have a social sidebar on the left side. Currently, the buttons in the sidebar are appearing in different sizes, but I want them all to be the same size as the "Twitter" button. To see the issue, please visit this link. I've tried ...