Centering the embedded div

Does anyone know how to center the DIV alignment that has a display set for the built-in unit?

I can’t set the display of the block because I have a background image that needs to be repeated and it needs to expand based on the content. It is inside the parent div, which is larger when it comes to width.

So that's all. Does anyone have a fix to center the alignment of the div with the display mounted on the inline unit?

And no, text-align: center; does not work, as well as margin: 0 auto;

jsFiddle: http://jsfiddle.net/HkvzM/

Thank!

+5
source share
4 answers

Try using this:

margin: 0 auto;

text-align: center; <div>...

+13

, , ,

Css

div{
    text-align: center;

}

.dl{
    color: #fff;
    margin: 0 auto;
    background: #000;
    text-transform: uppercase;
    font-size: 14px;
    font-weight: bold;  
    line-height:35px;  
    display:inline-block;    
}

HTML

<div>
<a class="dl">DOWNLOAD NOW DOWNLOAD NOW DOWNLOAD NOW</a>    
</div>

- http://jsfiddle.net/rohitazad/HkvzM/15/

+2

You cannot center an element with

display:inline

You may need to find work using jQuery or JavaScript. You can do approximate centering with CSS, which will work if the text doesn't change so much. Something Like This Demo

<div id="out">
    <a class="dl">DOWNLOAD NOW DOWNLOAD NOW DOWNLOAD NOW</a>
</div>​​​

#out{
 padding:0 50px;   
}
+1
source

text-align: center in the parent div will just do the trick.
source: inline CSS center renderer?

0
source

All Articles