What's the best way to design a header with a multi-colored center alignment?

I am looking to replicate this particular header design:

The issue I am facing is that the content is centered within the white section. The background of the body is grey and the header spans 100% of the screen.

Here is my current code:

CSS

.top_left {
  background:#3c4d74;
}

.top_right {
  background:#2f3a5a;
}

.top_center {
  background:#3c4d74 url(http://img85.imageshack.us/img85/2816/headerbgo.jpg) no-repeat right top;
  height:140px;
}

#page, 
.top_center {
  max-width:1000px;
  margin:0 auto;
}

#page {
  background:#FFF;
}

body {
  background:#DEDEDE;
}

HTML

<body>
    <div id="top-header">
        <div class="top_left"></div>
        <div class="top_center">
            <a href="#">LOGO</a>    
        </div>
        <div class="top_right"></div>
    </div>
    <div id="page" class="hfeed">
        MY content bla bla bla
    </div>    
</body>​​​​​​

You can view the working example on http://jsfiddle.net/gTnxX/ (I changed the max width to 600px for display purposes).

How can I make the left side a soft blue and the right side a hard blue regardless of resolution?

Answer №1

In order to achieve this effect, a solid understanding of how positioning functions is necessary.

The styling for #header-bg dictates that it should be positioned below #wrapper. This element spans 100% of the width, is 140px in height, and contains two divs, each taking up 50% of the space with different colors assigned for left and right sides.

#wrapper is relatively positioned to enable proper functioning of the z-index, ensuring it appears above #header-bg. Its width is specified as 600px, with a margin set to auto to center it on the page.

#header is a basic div with defined height and background styling.

Following the #header element, content flows in a typical manner.

A jsfiddle demonstrating the desired behavior can be found here.

http://jsfiddle.net/sg3s/cRZxN/

This design gracefully degrades, allowing horizontal scrolling if the content exceeds the screen size (an observation from the original jsfiddle).

Edit:

To ensure compatibility with IE7, adjustments were made to address two bugs. It was necessary to explicitly add left: 0; and top: 0; to #header-bg to resolve a positioning issue. The inner divs within #header-bg were adjusted to be 49% instead of 50% to prevent resizing problems in IE7 which caused the right div to shift downwards. To account for any gap created by this change, the right div was floated to the right using float: right;.

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

Using Jquery to retrieve the data-id attribute value from the <li> element

Seeking assistance on how to retrieve the value of (data-id=64) when clicking on a specific li-item within a tree structure. The tree consists of 5 list items, each with subchilds. Currently, I am able to obtain the (data-uid) of the first li, but I'm ...

The HTML for identifying Selenium objects in Java is lacking any identifiers such as ID, Xpath, class name, tag, link, CSS selector, or name

I am having trouble finding the object needed to identify an element on the webpage. Specifically, I am looking for the Column "Member Name" but cannot locate the appropriate object for identification. Below is the HTML code: <tbody> <tr class=" ...

The Ion-button seems to be malfunctioning

I am interested in using special buttons for my ionic 1 project, specifically the ion-button feature outlined on this page: Ionic Buttons. I attempted to create a Round Button and an Outline + Round Button: <h2 class="sub-header" style="color:#4 ...

Link the Sass variable to Vue props

When working on creating reusable components in Vue.js, I often utilize Sass variables for maintaining consistency in colors, sizes, and other styles. However, I recently encountered an issue with passing Sass variables using props in Vue.js. If I directly ...

JavaScript issue: Submitting form does not trigger the associated function

I am currently in the process of learning JavaScript as part of my university course, and I have encountered an issue where my function is not being called. I am seeking to gain a better understanding of why this problem is occurring. Summary The situati ...

Tips for closing the mobile navigation bar on your device after clicking

Currently developing a website and in need of assistance with the mobile device navbar functionality. Essentially, I am looking to close the navigation when a specific link, such as "Destaques", is clicked. All I require is to remove the class "opened" upo ...

Setting a timer within Vuex - step by step guide

I recently delved into learning Vue and Vuex. My current project involves setting up a countdown timer that initiates a countdown from 5 seconds upon being clicked. The implementation logic resides in the Vuex store for efficient state management, but unfo ...

I am unable to utilize sweetalert for creating a confirmation message in ASP with a linkbutton

I'm currently working on a school project and facing issues with implementing the delete confirmation using sweetalert. Below is the script I am struggling with: <script type="text/javascript> function myDelete { ...

Addressing a jquery.ajax relative path problem

I am a newcomer to this topic and I have been researching extensively online for more information. I would like some further insight into the following issue: I am attempting to retrieve a JSON file located one level down from the directory where `index.h ...

When the content within a dialog element exceeds the boundaries of the dialog, it will not be displayed

Issue Struggling with creating a dialog element that includes an x button for closing the <dialog> in the upper-right corner. My initial idea was to utilize absolute positioning and transforms to achieve this functionality, but encountered a setback ...

Is there a way to add the command "npm run development -- --watch" to my script as "watch"?

Is there a way for me to add "watch": "npm run development -- --watch" in my package.json script despite encountering the error ERR! missing script: watch? ...

Steps for inserting an array of strings in PHP into HTML input fields

I need help with extracting elements from a php array and displaying them as a list of text input fields on a webpage. The issue I'm facing is that the elements in the $list are strings, and when I run the code, only the portion of the string up to th ...

Instructions on how to hide a form tag once the submit button has been clicked

I am looking for a way to hide this form tag once the submit button is clicked. I attempted using "formaction" but it interfered with my ability to store data in the database. I am considering using JavaScript, but I am unsure how to go about making this ...

Show a row of pictures with overflow capabilities

I am looking to develop my own image viewer that surpasses the capabilities of Windows. My goal is to design an HTML page featuring all my images laid out horizontally to maximize screen space. I also want the images to adjust in size and alignment as I z ...

What is the best way to arrange multiple images on top of a single image?

I have a collection of six adorable kitten images in my portfolio. How can I arrange these images on top of a beautiful lake wallpaper without any white space? I want the word "Portfolio" and the six kittens displayed over the lake background, followed by ...

Integrating the Google Translate tool onto a website

My goal is to integrate a translation tool like Google Translator or other reliable options onto my website. I am not looking to translate the entire content of my pages into another language, but instead want to add a feature similar to the one found on t ...

Building a cascading dropdown menu in Angular 8 using ngFor

Currently, I am working on a code for creating a multi-level dropdown menu. However, the issue is that the output is not displaying as expected, resembling the image above. Here is my code: HTML <div *ngIf="options?.length >= 1" class=&qu ...

A guide on interacting with a link containing an SVG element using Selenium and Java

I'm having trouble clicking a specific button on a website using Selenium with Java. I can click and type in other fields, but this one button is causing issues. Here is the HTML code for the button that needs to be clicked: <div class="sc-dI ...

Error: OBJLoader is not defined in Three.js

I've been trying to learn Three.js by following various tutorials, but I keep encountering an error message that says Uncaught ReferenceError: OBJLoader is not defined when I attempt to use my own .obj file. I've tried different approaches to fix ...

Enhance Your Website with Jquery and Bootstrap 4: Imrpessive Navbar Effects for Resizing

Hello, I am facing a challenge that my novice mind is struggling to overcome. Utilizing Bootstrap 4 navbar and some jquery, I managed to create a transition where an initially invisible navbar transforms into a solid color when the user scrolls beyond a ce ...