Center 2 divs within block (fluid)

Posted on 2011-10-26
Last Modified: 2012-05-12
I am working on developing a site here: - I am working on making this in to a responsive website. My area I cant get is:

The main nav "Discover" and "Engage" - What is the best way to center those 2 elements with in the diagonal block?

I tried margin:0 auto and tried setting a width as well, and tried to inherit but that didnt work.

    LVL 30

    Expert Comment

    The main problem is that they are both different widths. The engage element is trying to center off of the discover width. You'll have to set a separate width for the Engage parent
    LVL 1

    Author Comment

    So even know I have this declaring both:

    .nav_header {
      background: url("../images/nav_header.png") no-repeat scroll -454px 0 transparent;
      float: left;
      height: 40px;
      line-height: 40px;
      margin: 0 2.96371% 31px 0;
      width: 42.8711%;

    The % render differently?

    LVL 30

    Accepted Solution

    No. It's rendering the same, however it's because the text inside are 2 different widths.
    Discover is 8 letters
    Engage is 6 letters

    That is going to make a huge difference in spacing, as you can see. I would class both of them and assign them widths as close as possible to their actual widths.
    LVL 12

    Expert Comment

    I'm not so sure about the different widths being a problem.

    You're trying to get the words "discover" and "engage" to be centered within their respective parent divs, right?  One thing to remember is that "inherit" is ignored by IE.

    Can you try this?
    1. Replace "width: inherit" with "text-align: center" for .nav_header_wrap in style.css (around line 137)
    2. Remove "float: left" for .nav_item in style.css (around line 150)

    See if that works.
    LVL 1

    Author Closing Comment

    Separating the 2 with their own class, worked perfect!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
    In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now