Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

center element inside fixed element

Tags:

html

css

I'm having trouble centering an element inside another element that's fixed:

bottombanner is inside html body:

<div id="bottombanner">
<div>
    <ul>
        <li><a href="contact.html">ContactUs</a></li>
        <li><a href="about.html">AboutUs</a></li>
        <li><a href="help.html">Help</a></li>
        <li><a href="bugs.html">BugReportBox</a></li>
        <li><a href="suggestions.html">SuggestionBox</a></li>
    </ul>
</div>
</div>

css is linked properly:

    #bottombanner{
    position:fixed;
    width:100%;
    bottom:0;
    }

    #bottombanner > div {
    position:absolute;
    width:100%;
    }

    #bottombanner > div > ul {
    position:relative;
    margin-left:auto;
    margin-right:auto;
    -webkit-margin-start: auto;
    -webkit-margin-end: auto;
    -webkit-padding-start: 0;
    }
like image 735
Justin McDonald Avatar asked Oct 19 '12 20:10

Justin McDonald


2 Answers

Add height to #bottombanner (at least, it was necessary for my fiddle) and add text-align: center to #bottombanner > div:

#bottombanner{
    position:fixed;
    width:100%;
    bottom:0;
    height: 130px;
}

#bottombanner > div {
    position:absolute;
    width:100%;
    text-align:center;
}

#bottombanner > div > ul {
    position:relative;
    margin-left:auto;
    margin-right:auto;
    -webkit-margin-start: auto;
    -webkit-margin-end: auto;
    -webkit-padding-start: 0;
}

Fiddle: http://jsfiddle.net/kboucher/cFgNx/

like image 111
Kevin Boucher Avatar answered Sep 30 '22 05:09

Kevin Boucher


You have to set the display attribute of the centered element to block and set the width of the element.

#bottombanner > div > ul {
 position:relative;
 margin-left:auto;
 margin-right:auto;
 -webkit-margin-start: auto;
 -webkit-margin-end: auto;
 -webkit-padding-start: 0;
 display:block;
 width:200px;
}
like image 31
b_m Avatar answered Sep 30 '22 05:09

b_m