Issues with positioning divs in the header and main sections

I'm struggling with positioning the divs inside the header div on my page that has 3 parent divs. Here is a snippet of my code:

Divs layout:

<div id="layout">
    <div id="header" class="body">
        header
        <div id="logo">logo</div>
        <div id="menu">menu</div>
    </div>
    <div id="main">
        <div id="left">left</div>
        <div id="right">right</div>
        <div id="body">body</div>
        <div id="clear"></div>
    </div>
    <div id="footer">footer</div>
</div>

The CSS looks something like this:

.body {
 background-color: #ffffff;
 margin: 0px;
 background-repeat: repeat-x;
 background-image: url(imgs/back.png);
}

#layout {
 margin:auto;
 width: 1024px;
 background-color:  #ffffff;
}

#main {
   background-color:  #ffffff; 
}

#header {
 background-color:#0F0;
 height: 300px;
}

#body {
 margin-left: 180px;
 margin-right: 180px;
 padding: 5px;
 background-color:  #ffffff;
}

#footer {
 margin-left: 180px;
 margin-right: 180px;
 padding: 0px;
 background-color:  #ffffff;
}

#right {
 float: right;
 width: 180px;
 padding: 0px;
 margin: 0px;
 right: 0px;
    background-color:  #ffffff;
}

#left {
 float: left;
 width: 180px;
 padding: 0px;
 margin: 0px;
 left: 0px;
 background-color:  #ffffff;
}

#clear {
   clear:both; 
}

I am trying to position the elements within the header div, such as vertically centering one element and placing another between the center and the right side horizontally. I would really appreciate any help or suggestions.

Thank you in advance!

Answer №1

If you could provide more details, I would be able to offer better assistance.

I am uncertain about the specifics of your query regarding the header's positioning.

One suggestion is to shift the menu between the center and right columns by enclosing it along with the right-hand column in a div aligned to the right. In this example, I've named it right-container.

This is how the HTML structure looks:

<div id="layout">
    <div id="header" class="body">
        header
        <div id="logo">logo</div>
    </div>
    <div id="main">
        <div id="left">left</div>
        <div id="right-container">
           <div id="menu">menu</div>
           <div id="right">right</div>
        </div>
        <div id="body">body</div>
        <div id="clear"></div>
    </div>
    <div id="footer">footer</div>
</div>​

Additionally, here are the CSS styles I included:

#right-container {
 float: right;
 width: 360px;
 padding: 0px;
 margin: 0px;
 right: 0px;
    background-color: #ffffff;
}

#menu {
 float: left;
 width: 180px;
 padding: 0px;
 margin: 0px;
 left: 0px;
 background-color: #ffffff;
}

You can view the demonstration on this fiddle link:

http://jsfiddle.net/AbCdE/

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

Picking specific <button> items

Presented here are a series of buttons to choose from: <button id="hdfs-test" type="button" class="btn btn-default btn-lg">HDFS</button> <button id="hive-test" type="button" class="btn btn-default btn-lg">HIVE</button> <button id ...

Is there a way to improve or simplify this jQuery validation code?

I am implementing client side validation using jQuery to ensure all fields are filled in before proceeding. var passedValidation = new Boolean(true); // Validate Required Fields if ($('#fbsignup input.firstName').val().trim() == '') { ...

Creating a personalized grid display

https://i.sstatic.net/tLd7X.png I've been trying to achieve the following output with my code, but so far nothing has worked. Can someone help me identify what I may be doing wrong? I'm new to this, so any guidance would be greatly appreciated. ( ...

Animating the navbar with CSS transitions

https://i.sstatic.net/cV3X6.png Seeking advice on adding a transition effect to my navbar. Specifically, I'd like to have a colored background appear below each link when hovered over. For example, when hovering over "HOME," a yellow color should dis ...

Displaying a CSS span element as the topmost layer

I am struggling to get a tooltip to properly display on top of its parent element. Despite trying various combinations of z-index and overflow properties, I have not been able to achieve the desired outcome. The issue arises when hovering over the red box ...

Experience a glint in the React Suspense with React Router - Struggling with CSS properties post utilizing Suspense and Lazy

I'm experiencing an issue with my code where the CSS properties are not working properly when I wrap the code in suspense. The page loads and the suspense functions as expected, but the styling is not being applied. However, if I remove the suspense, ...

What is the process for triggering an unordered list when I click on a table data cell within the Hospitals category?

Hi there! I need help with writing a JavaScript function for Hospitals in the code below. When I click on Hospitals, I want to display the values in the unordered list. Expected output: Hospitals--->onclick Bangalore| salem |Goa| Mangalore| Visakhapat ...

Session does not reflect the correct quantity

I have encountered some issues with my account, so I am currently using my brother's account to access the e-commerce website I am working on. My main concern is regarding the handling of quantities on different pages of the website. The website con ...

Bootstrap image with simplistic arrow indicators

I'm facing a minor issue that I need help solving. I want to have two simple arrows (one pointing left and one right) vertically aligned in the center of an image. Additionally, these arrows should resize proportionally when the screen size changes. ...

Transform your dictionary into an interactive HTML table that allows users to search through the results with ease

I have a university project where I need to exchange data via JSON using a Python script and a server, and then display it in a browser with an add and search function. The information being added includes student names, surnames, and ages. I must apologiz ...

JSX is a powerful tool that revolutionizes the way we structure our front-end components. One of the most

I'm currently facing an issue while attempting to create a custom component that utilizes a looping array to conditionally render different elements. In this component, I have special classNames that help generate a grid with 3 elements per row, regar ...

Exploring the theme color options in Angular Material

Despite extensive searching on SO and GitHub, I am seeking clarification: Is it impossible to access a theme color (or any other theme feature) in order to set a mat-card color? There is no way to retrieve a variable in scss. You cannot assign a class to ...

Querying data via AJAX from a specific Laravel route to retrieve a JSON encoded array filled with dates to populate ChartJS labels

My Laravel 5.7 project includes ajax and ChartJS functionality. Upon page load, an ajax call is made to "action_route", which retrieves the labels for the ChartJS. The PHP function json encodes an array of labels, which are then decoded by the ajax call. ...

Is there a way to adjust the dimensions of the <audio> tag using CSS?

//I am trying to adjust the size of the audio player based on the 'height' and 'width' properties, but it doesn't seem to be working as expected. <audio autoplay controls height="100px" width="100px"> ...

Arrange list items in alignment without the need for additional CSS (bootstrap) styling

<div class="card-body p-0"> <ul class="list-group list-group-flush"> <li class="list-group-item d-flex justify-content-between" th:each="extraConfig : ${extraConfigsPage.content}"> ...

Exploring the search capabilities of input fields that are disabled

Lately, I've been struggling with a search function on my table of information. The trouble started when I made the text in the table editable - now the search function refuses to cooperate. I've tried troubleshooting it from different angles, b ...

Utilize CSS to conceal the direct ancestor of a specified element

Is it achievable using just CSS to conceal a parent element when a child element lacks a particular class? <!-- hide this --> <div class="parent"> <p class="badChild" /> </div> <!-- do not hide this --> <div class="pare ...

I am experiencing an issue with using double quotation marks in VS Code

Whenever I press the double quote symbol like this "", the cursor automatically moves to the end. While this may be natural, I would prefer the cursor to move inside the double quotes automatically when pressing them. Additionally, it's a bi ...

Issue with loading contentsCss in CKEDITOR with VUEJS2

Currently in the process of developing a website using Vue.js 2, we incorporated the ckeditor4-vue plugin some time ago. An issue has recently come up regarding the font not matching the rest of the application. The preference is to default to 'Lato& ...

Do you require assistance with creating an image slideshow?

My first day working with HTML was a success as I successfully built a navigation bar that looks pretty cool. Take a look at it here. Next on my list is to incorporate a slideshow into my site, possibly using JavaScript or jQuery plugins. I'm aiming ...