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

What is the best way to enlarge an element when scrolling downwards within the element?

I am looking to create a div that dynamically adjusts its height based on the user's scrolling behavior. The goal is for the div to expand to the very top as the user scrolls downward, and stop when it reaches 70% of the container/parent element. Is t ...

Guide on setting the value of a select element in Vue Core UI

Apologies for the newbie question, as I am just starting out with Vue.js. I have recently started using CoreUI, but I am having trouble finding detailed documentation or tutorials on CoreUI+Vue integration. Specifically, I am working with the <CForm> ...

Upload the PDF file along with other form data in a React application

I'm currently facing an issue with using formData for submitting a pdf file const [file,setFile] = useState() const [isFilePicked, setIsFilePicked] = useState(false); I have an input of type file <input accept=".pdf" type="file&quo ...

What is the best way to implement the nth:child selector in conjunction with the each function for handling JSON data in

Here is the HTML code I have written: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Flickr Feed</title> <link href="../_css/site.css" rel="stylesheet"> <link rel="stylesheet" type= ...

Typescript Angular2 filtering tutorial

In Angular 2 using TypeScript, the goal is to search for matching values from an array within an object array. The intention is to filter out any objects where the 'extraService' property contains any of the values from the 'array_values&apo ...

Is it possible to place an open div panel between two tweets?

I'm in the process of developing a UI with Twitter feeds. I want to create a feature where a panel can be opened between two tweets, causing the tweet below to shift downwards. This function is commonly seen in tweet clients like TweetBot; as each new ...

Tips for handling numerous buttons in ionic?

I'm currently working on an app that includes surveys. In this app, users are required to answer by selecting either the Yes or No button. The desired behavior is for the chosen button to turn blue once clicked, while the other button should maintain ...

How can I define the boundaries for the scrolling of a static background image?

Is there a way to limit how far a fixed background image can scroll down a page? Essentially, is it possible to change the background attachment to static when the bottom of the background image is 10px away from the bottom edge of its div container? In t ...

Ways to disable the caching feature in Google Chrome

When I am working on CSS and JS around a page, I need to disable the cache mechanism in Google Chrome browser. A trick is to open Chrome DevTools, which automatically disables the cache mechanism (you can configure this in the settings section). Are ther ...

How can I retrieve the content from an iframe whenever its state is altered using jQuery?

I am currently working on a project where I need to extract the content from a hidden iframe and display it as HTML in a div every time the iframe changes its loading state. The goal is for it to appear as if the page is being redirected and downloading it ...

Grabbing the mouse in Firefox

Are there any alternatives to the .setCapture(); and .releaseCapture() functions in Firefox that do not involve using jQuery? (The client prefers not to use it) ...

Display user's name in navigation bar using asp.net mvc

When working on an ASP.NET MVC project, I wanted to include a short message for the user, such as 'Hello, username!' In the navigation bar, specifically when the user is signed in, I encountered some display issues with the standard bootstrap la ...

Sample Source Code for Jssor Slider

Is there a way to replicate the slider effect shown in this example using Jssor Slider without any available sample code or source? I would greatly appreciate any assistance with achieving this. Thank you ...

Adapting padding based on the height of the browser to ensure optimal layout

I'm interested in adjusting the padding value of a button element based on the height of the browser window, not its width. I want to make sure that the padding adjusts proportionally to the browser window's height. Is this achievable using CSS? ...

Encountering a problem where updating the selected option in a dropdown does not properly refresh the HTML

I am currently working with a dropdown menu containing countries. Initially, the selected item is set to Ukraine. <select id="country" name="country"> <option value="US">USA</option> <option value="UG">Uganda</option> ...

Align an image in the middle with a heading

I am currently working on aligning a picture and heading in a header section. My goal is to center both elements, with the picture being twice as tall as the heading. So far, I have them stacked one above the other: .body { font: 15px/1.5 Arial, Helveti ...

Jquery deactivates the CSS hover effect

Having a dilemma with linked photos on my website. I have set their opacity to 0.45 by default, but want them to change to full opacity (1) when hovered over or clicked. I've implemented a JQuery function that resets the rest of the photos back to 0.4 ...

Discover the steps to download web page data using Objective-C while ensuring that JavaScript has finished executing

I attempted something similar: NSString *url = @"http://www.example.com"; NSURL *urlRequest = [NSURL URLWithString:url]; NSError *error = nil; NSString *htmlContent = [NSString stringWithContentsOfURL:urlrequest encoding:NSUTF8StringEncoding error:&e ...

The ZK Component fails to display within the HTML tag

In my dilemma, I am attempting to showcase a hyperlink component under an HTML tag along with some instructions for click functionality: <zk> <html> <a label="show me" onClick="@command('showMe')" /> </html> </zk ...

Refreshing an iframe located on disparate domains

There is a webpage called "main.jsp" within the domain "domain1". This page contains an iframe that loads content from another domain known as "domain2". Essentially, "main.jsp" serves as a common content platform, with the iframe displaying content from v ...