Ways to position the div within the header at the right, left, and center

.header-cont
{
width: 100%;
position: fixed;
top: 0px;
}
.header
{
height: 50px;
background: #f0f0f0;
border: 1px solid #ccc;
width: 80%;
margin: 0px auto;
line-height: 0px;

}
.maindiv
{
box-shadow: 15px 0px 10px -11px rgba(0, 0, 0, 0.1), -15px 0px 10px -11px rgba(0, 0, 0, 0.1);
width: 960px;
background: #f0f0f0;
border: 1px solid #ccc;
height: 2000px;
margin: 70px auto;

}
label {
    float: left;
    width: 15%;
    margin-top: .5%;

}

form ul {
    list-style-type: none;
    margin: 0;
}

form ul li {
    clear: both;
    margin-top:2%;
    
}
<html>
<body>
<!-- Beginning of Top Title Bar -->
<div class="header-cont">
<div class="header">
<form>
    <ul>
      <li>
      <div>
Placing the logo in the left corner
        <label>
          <img src=""> <!-- Logo on the left side--> `enter code here`
        </label>  
      <div>
      <div >
Centering the profile picture
        <label> 
          <img src=""><!-- Profile Picture in center -->
        </label>
       </div>
Displaying the user name on the right side
        <label>
          <a href="" id="welcome">Welcome User!!</a><!-- Right Side-->
        </label>
Login and sign up options for the right corner
        <label>
          <a href="#">Login</a><!-- Right Side Corner-->
          <a href="#">Signup</a>
        </label>
      </li>
    </ul> 
</form>
</div>
</div>
<div class="maindiv">
<h1>This is Content Page</h1>
</div>

</body>
</html>

The output image can be modified by changing the header section.

Answer №1

Adjust the width to suit your requirements.

.container{
    width:100%;
}

.left {
float:left;
    width:33.33%;
text-align: left;

}
.center {
display: inline-block;
    margin:0 auto;
    width:33.33%;
    text-align: center;
}

.right {
float:right;
    width:33.33%;
text-align: right;
}
<div class="container">
<div class="left"><!-- insert left contents here --> </div>
<div class="center"><!-- insert center contents here --> </div>
<div class="right"><!-- insert right contents here --> </div>
</div>

Answer №2

Create 3 <div> elements with unique ids, setting their widths to 33.33% and floating them to the left.

In the first div, place your logo. In the second div, add the profile picture. Lastly, in the third div, insert 2 more <div> elements with widths of 50% each. Set text-align:left; for welcoming users and text-align:right; for login and sign up options.

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

Show that a CPU-intensive JavaScript function is executing (animated GIF spinners do not spin)

Displaying animated indicator or spinner gifs, then hiding them, is an effective way to communicate to the user that their action is being processed. This helps to assure the user that something is happening while they wait for the action to complete, espe ...

Tips for maintaining a website within a 960px width while stretching the background on the x-axis

I have enclosed the entire website within a div with the ID container. The CSS styling for the container is as follows: #container { width: 960px; background: #FFFFFF; margin: 0 auto; border: 1px solid #000000; text-align: left; } How ...

Picture not showing up when loading iPhone video

My website features a video that is displayed using the following code: <div class="gl-bot-left"> <video controls=""> <source src="https://www.sustainablewestonma.org/wp-content/uploads/2019/09/video.fixgasleaks.mp4" ...

Creating a persistent sticky element that remains at the forefront in Electron or JavaScript development

Currently, I have a remote desktop control application built on Electron that functions as a desktop app on Mac and Windows, and as a web app on Chrome and Firefox. My next goal is to create a sticky component that remains on top at all times, regardless ...

When choosing the child option, it starts acting abnormally if the parent option is already selected in Angular

I am encountering an issue while trying to select the parent and its children in the select option. The concept is to have one select option for the parent and another for the child. I have parent objects and nested objects as children, which are subCatego ...

Is it possible for me to execute index.html using React without relying on npm start and npx create-react-app?

As I dive into learning React on my own, I find myself tangled in confusion. My initial approach was to add React to my index.html using a script like this: //index.html <!DOCTYPE html> <html lang="en"> <head> <title> ...

Header that sticks to the top of a container as you scroll through it

Many questions arise regarding sticky elements in the DOM and the various libraries available to handle them, such as jquery.pin, sticky-kit, and more. However, the issue with most of these libraries is that they only function when the entire body is scro ...

animation for closing the hamburger menu

Having trouble creating a hamburger menu animation. I've set up two divs - one for the basic horizontal lines and one for the X icon. Using jQuery, I can hide and show them (clicking on the lines hides them and shows the X). But now I want to animate ...

Guide to activating the 'Next' button on WP Forms using JavaScript code when certain conditions are fulfilled

Is there a way to adjust the JavaScript code provided so that the visibility of the "Next" button is dependent on whether at least one item in the 'wpforms-icon-choices-item' class has the '.wpform-selected' class on the current page or ...

Bizarre discrepancies in text wrapping across various browsers

After encountering a larger issue, I found that I could reduce it to a simpler scenario: To see the problem in action, check out this jsFiddle link: http://jsfiddle.net/uUGp6/ Here is the simplified HTML code: <div class="box"> <img class=" ...

Tips for disabling the source of an external iframe

Is there a way to close an iframe src with a click event from within the iframe itself? Let's suppose I have this parent HTML: <body> <script> document.write("<iframe src='default.html' id="myFrame" width=' ...

Difficulties arise when dealing with card elements and scrolling on a

Currently working on an ecommerce simulation project for a course, I successfully implemented a featured section with cards. However, when it comes to scrolling, I am facing an issue where the cards overlap with my sticky navbar as I scroll down. If anyo ...

Gensim's Word2Vec is throwing an error: ValueError - Section header required before line #0

Hello everyone! I am diving into the world of Gensim Word2Vec and could use some guidance. My current task involves using Word2Vec to create word vectors for raw HTML files. To kick things off, I convert these HTML files into text files. Question Number O ...

Which method is more effective: utilizing AJAX to retrieve page elements, or just toggling their visibility?

When it comes to web development, particularly in jQuery, should I preload my page and use jQuery to manipulate the DOM, or should I do it the other way around? This debate involves: <div id="item1" ></div> <div id="item2"></div> ...

Trigger a click event on a dynamically loaded button

Here's a unique twist to the usual discussions on this topic. I have a dynamically loaded button in my HTML, and I've saved the selector for it. Later on in my code, I need to trigger a click event on this button programmatically. The typical $(& ...

Using jQuery, you can easily update the value of the nth-child(n) for a cloned element

Looking to duplicate an HTML element and assign new values to its child elements? Here's my current HTML structure: <div id="avator" class="avator" style="display:none"> <label><a href="/cdn-cgi/l/email-protection" class="__cf_email ...

Save the current state of the collapsible navigation menu

I developed a website for a friend, but I'm encountering an issue with my js/css vertical and collapsible menu. Every time I click a link, the new page loads and the entire menu collapses again. I've tried to figure out a way to "store" the infor ...

When an image is added, it will display against a backdrop of pure white

Hey there, I have a question regarding an image on my website. I removed the background using PowerPoint, but when I upload it, there is still a white background around it. Even changing the background color doesn't remove the white outline. Any tips ...

What is the best way to refine my selection of elements within a jQuery object?

function initializeItems($items, current, count) { $items.removeClass('z-item-current'); $items.each(function(index) { var $self = $(this); $self.data('z-item-index', index); if(index === current) { ...

Setting Image Widths for Various Screen Sizes in HTML for Android Tablets and Phones

My android app functions on both tablets and phones, loading content from HTML files in the assets folder. Currently, I am facing an issue where I need different image sizes for tablet and phone devices. Below is the code snippet for displaying the image ...