Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center floating divs inside of absolute positioned div

Tags:

html

css

I have this set of html and css. What I want is to have to have the small gadgets blocks float left but to centered inside of the absolute positioned gadget-wrapper.

So, the gadget wrapper is absolute positioned to the bottom of a page. It holds x number of gadgets that floats left inside of the wrapper.

All these gadget should be centered inside the wrapper - is this possible and how ...? This is really killing me ....

HTML

<div id="gadget-wrapper">
    <div class="gadget">
        <h2>1</h2>
        <div class="value-holder critical">not set</div>
        <div class="value-holder non-critical">not set</div>
    </div>
    <div class="gadget">
        <h2>2</h2>
        <div class="value-holder critical">not set</div>
        <div class="value-holder non-critical">not set</div>
    </div>
    <div class="gadget">
        <h2>3</h2>
        <div class="value-holder critical">not set</div>
        <div class="value-holder non-critical">not set</div>
    </div>
</div>

CSS

#gadget-wrapper {
    width: 900px;
    font-family: "Century Gothic";
    color: #FFF;
    position: absolute;
    bottom: 10px;
    outline: 1px solid green;
}

.gadget h2 {
    margin: 0px;
    font-weight: normal;
    font-size: 16px;
}

.gadget {
    min-width: 120px;
    margin-right: 10px;
    padding: 5px;
    -webkit-border-radius: 10px;
    background-color: #383838;
    opacity: 0.75;
    float: left;
    border: 4px solid #000;
}

.value-holder.critical.active {
    color: #FF0000;
}

.value-holder.non-critical.active {
    color: #FFFF00;
}

.value-holder {
    font-size: 28px;
    float: left;
    width: 50%;
    text-align: center;
}
like image 545
Riri Avatar asked Jan 12 '10 10:01

Riri


1 Answers

Have you tried making the gadget elements inline and aligning them to the center with text-align?

#gadget-wrapper {
    ...
    text-align: center;
}

.gadget {
    display: inline;
    float: none;
}

This might work, I'm just not sure how the block level elements inside will behave (I'm unable to test this right now). You can also try inline-block instead of inline.

like image 121
Tatu Ulmanen Avatar answered Sep 20 '22 01:09

Tatu Ulmanen