Organizing components within a division

It's maddening...

I'm working on a website and trying to create a header div that includes the site name, search bar, and sign in/log in buttons. I want the logo on the left, search bar in the center, and sign in/log in buttons on the right, stacked vertically. The logo and search should be centered vertically.

Here's the code I currently have:

#home {
  position: absolute;
}
#search {
  position: absolute;
  left: 30%;
}
#search_box {
  width: 500px;
}
#header {
  position: relative;
  height: 90px;
  line-height: 90px;
  background-color: burlywood;
  color: beige;
  padding: 10px;
  float: top;
  margin: auto;
  border-style: groove;
}
#log_in {
  float: right;
}
#sign_in {
  float: right;
}
<div id="header">
  <div id="home">
    <h1>HatSpace</h1>
  </div>
  <div id="search">
    <form>
      <input id="search_box" type="text" placeholder="Search the Website">
    </form>
  </div>
  <div id="log_in">
    <p>Log in</p>
  </div>
  <div id="sign_in">
    <p>Sign in</p>
  </div>
</div>

After implementing Chheda's suggestions:

#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: burlywood;
    color: beige;
    border-style: groove;
    }
#register {
    display: flex;
    flex-direction: column;
    }
<div id="header">
            <div>
                <h1><a href="index.html"</a>HatSpace</h1>
            </div>
            <div id="register">
                <form>
                    <input style = "width: 500px;" type="text" placeholder="Search the Website">
                </form>
            </div>
            <div>
                <div>
                    <p>Log in</p>
                </div>
                <div>
                    <p>Sign in</p>
                </div>
            </div>
        </div>

If I remove the href from the HatSpace element, it displays as desired. However, I need the href there. What am I missing?

Answer №1

Do you require a solution similar to this?

#nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
#menu {
  display: flex;
  flex-direction: row;
}
<div id="nav">
  <div id="home">
    <h1>HomeSpace</h1>
  </div>
  <div id="menu">
    <div id="login">
      <p>Login</p>
    </div>
    <div id="register">
      <p>Register</p>
    </div>
  </div>
  <div id="search-bar">
    <form>
      <input id="search-input" type="text" placeholder="Search the Page">
    </form>
  </div>
</div>

Answer №2

To streamline the user experience, consolidate the "Log in" and "Sign in" texts within a single container (for example,

<div id="log_in"> </div>
). Eliminate the line-height:90px property from the styling of #header (which was likely added to reposition the search box). Instead, introduce margin-top:30px to adjust the positioning of the search bar within #search. If the line-height adjustment is required for #home as well, ensure it is also implemented there.

I trust this solution aligns with your requirements :)

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

Ways to display a box following the submission of a value within a form

There's a pop-up window where the user has to enter their name. After clicking the submit button, this window closes. You can try it out here: (Click the 21 button, enter any value, and see what happens) The function used for the pop-up box is: fu ...

Obtain the full HTML code for a Facebook album

I am attempting to extract the HTML code from a Facebook album in order to retrieve the photo links. However, since not all photos load at once, cURL only retrieves the links of photos that are initially loaded. Is there a way to fetch the entire loaded H ...

Solving the mystery of background color in CSS for heading/title div

I am facing an issue with the title div setup where the red background is not applied when only the leftmost div has content. Despite the 'title' div having content, the background remains white. Can anyone suggest why this might be happening? H ...

Displaying PHP output within a JavaScript expression

Let's dive into a scenario involving a basic HTML document and some JavaScript that's loaded within it: <!-- doc.html --> <!doctype html> <html lang="en"> <head> <script type="text/javascript" src=" ...

How to wrap a narrower column around a shorter column using Bootstrap 4

Incorporating Bootstrap 4 into my website design, I have created a simple two column layout. The right column houses a table of contents while the left column is filled with various markup elements such as paragraphs, lists, and images. My goal is to have ...

Step-by-step guide for serving static JavaScript files using NextJS

I am currently exploring the process of hosting static js and css files using NextJS. My journey began with creating a react app through create-react-app, where I developed an App component before executing the npm run build command. This resulted in the ...

Bone structure template - optimizing list spacing with CSS

Currently, I am attempting to float my navigation bar further towards the left by at least 200px, closer to the end of the line visible below. However, every time I add a margin or padding, it causes the elements within the navigation bar to stack on top o ...

The JavaScript function does not function properly when it is called from another function

I tried my hand at creating a simple website for personal use, where I could input and edit text in an organized manner. A key feature I wanted was the ability to add new text fields dynamically by clicking a button, but it turned out to be more challengin ...

Styling with CSS: How to Show an Absolutely Positioned Element in Google Chrome

I'm currently working on a CSS design that involves positioning an image within a span tag. Here's the CSS code I have: .dc-mega-icon { background-image: url(...); display: inline-block; position: absolute; top: 18px; width: ...

Ways to achieve a darker background with rgba(0,0,0,0.5)

Hey there, if this isn't the right place to post my query, could someone guide me on where to do so? TL;DR = I need to darken the background of my showcase image! I'm working on a website as part of an online course project to practice new skil ...

Position a div relative to another div with a static position

I am attempting to create a site that is fullscreen and responsive, but I am having issues with elements in the container overflowing on smaller screens, causing it to not be 100% as desired. I have tried using: top:100%; position:relative; width:100%; he ...

Using Selenium with Java to interact with elements on a webpage, I encountered an issue where I was unable to click

I utilize Selenium for purposes other than web testing; my main goal is to extract and modify text from a website. Specifically, I use it within an additional editor to manipulate content on Confluence. The text I extract often contains various formatting ...

What is the proper way to place a newly added element using absolute positioning?

Currently, I am in the process of developing a tooltip feature. This function involves adding a div with tooltip text inside it to the element that is clicked. However, I am facing a challenge in positioning this element above the clicked element every tim ...

Text in React Native exceeding one line is causing it to extend beyond the screen boundaries

I am having trouble displaying the last messages in my simple contact list as the text is getting cut off the screen. Below is the code I am using: (the readableTimestamp should be positioned behind the text.) View style={{ fontSize: 16, backgro ...

CSS sidebars are failing to display on the website

Working on a supposedly simple template turned out to be more challenging than expected. The template lacked sidebars, so I attempted to add them myself. However, my test text isn't displaying as intended. Could someone please help me identify the mi ...

Enhancing the functionality of localStorage

I am attempting to append a value to a key within the HTML5 localStorage. Take a look at my code below: var splice_string = []; splice_string += "Test value"; var original = JSON.parse(localStorage.getItem('product_1')); origina ...

Double-up with Bootstrap's dual-column tabs

Looking to customize the layout of a nav-tabs ul to display its contents in 2 columns instead of horizontally, as per the default Bootstrap style for nav-tabs. Attempted to use the CSS property column-count: 2 but it didn't yield the desired result. ...

Showing error messages in Angular when a form is submitted and found to be invalid

My form currently displays an error message under each field if left empty or invalid. However, I want to customize the behavior of the submit button when the form is invalid. <form #projectForm="ngForm" (ngSubmit)="onSubmit()"> ...

What is the reason behind the vanishing of the input field while adjusting the

Why is the input field getting cut off when I resize my browser window, even though I'm using percentages? Here is a screenshot for reference: https://i.sstatic.net/4JrWd.png Shouldn't it resize automatically with percentages? Thank you! Below i ...

Building an Ionic Angular application that converts milliseconds to DateTime values retrieved from local storage

I have a mobile app built using Ionic framework where I retrieve data from local storage. My goal is to convert the milliseconds into a readable date format. I have tried the code below but it's not giving me the desired output. Can you please point ...