Position three divs in the center and at the top of my master page

My goal is to position 3 divs on top of each other efficiently without wasting space. The first div contains a logo image, the second is a search box, and the third, located at the right side, is a login/logout control.

I have attempted to use CSS to float the first div left, the last div right, and keep the search bar centered, but the layout doesn't look correct. Here is my HTML code:

<div id="main">
        <div id="maia-header-logo" class="float-left;">
        </div>
        <div id="searchbox">
                <input runat="server" id="search" type="text" placeholder="Type here..." />
                <input runat="server" id="submit" type="submit" value="Search" />
        </div>
        <div class="float-right">
                <section id="login">
                    <asp:LoginView ID="LoginView1" runat="server" ViewStateMode="Disabled">
                        <LoggedInTemplate>
                            <p>
                                Hello, <a id="hlManageAccount" runat="server" class="username" href="#" title="Manage your account">
                                    <asp:LoginName ID="LoginName1" runat="server" CssClass="username" /></a> | <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" />
                            </p>
                        </LoggedInTemplate>
                    </asp:LoginView>
                </section>
         </div>
    </div>    

The current display:

Answer №1

To ensure your elements align properly, it is essential to define their widths.

If you opt not to specify individual widths, you can instead create a fixed width container and utilize position: relative; to position your top bar accordingly.

#header-container {
    position:relative;
    width: 1000px;
    margin: auto; }
#maia-header-logo {
    position: relative;
    top: 0;
    left: 0; }
#searchbox { 
    width: 500px; /* exact width of element */
    position: relative;
    top: 0;
    left: 250px; /* (containerWidth - elementWidth) / 2 */ }
#login {
    width: 250px;
    text-align: right;
    left: 750px; }

As I do not have the specific measurements for your layout, I recommend performing the calculations based on the formula provided in the code snippet above.

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

In React Router v6, the homepage is continuously rendered as "/"

I am having issues implementing a router in my react-create-app. It always renders "/" and displays either the Home or SignIn page. How can I resolve this problem? function AppRouter({ isLoggedIn, user }) { return( <Router> <Routes&g ...

Is it better to have a heading titled "Navigation" above a <nav> element, or should it be included inside the navigation element itself?

Which is the better way to structure navigation: <h1>Navigation</h1> <nav> <ul> <li>...</li> </ul> </nav> Or: <nav> <h1>Navigation</h1> <ul> <li>...</li> ...

How to Center a Bootstrap List on Tablets and Mobile Devices

I've run into a bit of a snag and despite my efforts to research online, I'm unable to find a solution. Currently, I am utilizing bootstrap to develop my website. However, when I resize the page to a mobile or tablet size, my navbar list shifts ...

Webpack is failing to load the logo PNG image file

Is there a way to make the logo png file visible on the webpage? I have been encountering issues with loading the image while other elements like HTML, css, and fonts are loading properly when the web pack is started. List of Error Messages: Refused to a ...

Utilize images stored locally in ReactJS

My path to the image is: ../src/assets/images/img_name.jpg" And my path to the file.js is: src/file_name.js If I include the following code in file.js: Import img_name from "../src/assets/images/img_name.jpg" Then reference the image pa ...

Ways to center card components (rmwc) horizontally within a React application

Within my parent component: { this.state.projectList.map(data => <Item details = {data}/>) } Inside the child component Item render() { return ( <div style={{'width':'100%', 'tex ...

Position the AdMob banner at the bottom of the page

I am attempting to place an AdMob banner at the bottom of my page, but the Ad is not appearing. There seems to be space allocated for it, but the AdMob banner is not displaying. Include and reference the Google Play services library. - CONFIRMED Add a me ...

Conceal specific pages within the DataTable without deleting them

Currently, I am facing an issue where the dataTable paginates and removes the DOM pages along with the data. My goal is to extract all the data from the dataTable and convert it to JSON without losing access to the DOM when pagination occurs. I want to m ...

With Bootstrap 4 navigation bar, once a container is added, the elements will automatically align to the right

Greetings! I am a newcomer to the world of bootstrap, so please bear with me if my question seems too basic. My current challenge involves creating a navbar using bootstrap. However, I have encountered an issue where the logo remains on the left side whi ...

Unable to submit /api/sentiment

I'm currently troubleshooting the /api/sentiment endpoint in postman and encountering a "cannot POST" error. I have confirmed that the routes are correct and the server is actively listening on port 8080. Interestingly, all other endpoints function wi ...

The use of JavaScript within the code results in the <header> and <nav> elements failing to display on the browser

Currently, I am tackling a webpage project that involves using scripts in both the head and section elements to generate a table where clicking on the cells changes their color randomly. However, a glitch seems to be hindering the display of the header and ...

What is the best method in Selenium IDE for tracking an element based on its value?

While testing a website with Selenium IDE, I encountered an issue with the way elements are identified. The site utilizes something called "wickets" that change the ID of elements randomly, making it difficult for Selenium to record actions on certain elem ...

I'm attempting to arrange the movieCards in a horizontal row, but they keep stacking up vertically instead

I have created a movie list component with different attributes in the div section to display the cards in a row. However, all the cards are currently aligned in a column. Should I use flex or grid to achieve the desired layout? If so, how can I implement ...

How can jQuery help me load a lengthy webpage with various backgrounds that change according to the vertical scroll value?

I have been given a design that is 960px wide and approximately 7000px tall, divided into five segments stacked vertically at random points. There is a fixed sidebar that scrolls to each segment when a navigation link is clicked. The layout includes slider ...

An error in typescript involving a "const" assertion and a string array

Currently, I am diving into the world of Typescript along with React. However, an error has emerged in my path that I can't seem to figure out. It's puzzling why this issue is occurring in the first place. Allow me to elaborate below. const color ...

Limiting input to specific characters is effective on Chrome, but unfortunately does not function on Firefox

This code snippet is designed to restrict user input to lowercase letters from a-z, numbers from 0-9, and the dash character "-". While it functions correctly in Chrome, it does not allow any input in Firefox. What could be causing this issue? $('#sl ...

``It has come to our attention that ALT texts are not displaying properly on popular email clients such as Outlook,

Despite following all the email standards and attempting to style the ALT tag, most major email clients do not display the ALT text when images fail to load. Is there a workaround for this issue or does it primarily depend on the specific email engine bein ...

Uncovering the Mystery of AJAX and JSON in jQuery and NodeJS

Currently, I'm facing a challenge with an ajax function that sends a json to a nodejs route. I need to extract the selected values from 4 button-groups named quality, costeffectiveness, deliveryscope, and rating. Each button-group consists of 5 radio- ...

Searching through a JSON object on a Laravel web page using JavaScript or AJAX for live filtering purposes

After diving into AJAX and JavaScript, I find myself needing to replace some outdated Angular functionality on our Laravel site. The specific task at hand is creating a live search filter for a page with a static header search bar. The main requirement is ...

The cache feature seems to be malfunctioning, resulting in images having to be reloaded every time

I am working on a simple webpage at . The issue I'm encountering seems to be specific to Google Chrome - every time I reload the page, the images are reloaded as if there is no cache. I noticed that when checking the example on stackoverflow.com, the ...