Search code examples
htmlcsscentermargin

Margin 0 auto to a span within div not working


I'd call a span within a div, its taking margins but margin:0 auto is not working. Any suggestion?

html

<div>
    <span>
         <h3>Paris Eurostar Breaks</h3>
         <p>Curabitur fringilla mauris interdum nec magna</p>
    </span>
</div>

css

div{
    width:465px;
    min-height:201px;
}
div span{
    display:inline-block;
    color:#FFF;
    border-bottom:1px #FFF solid;
    border-top:1px #FFF solid;
    margin:0 auto;  
}

Output Required

enter image description here


Solution

  • To center horizontal with margin the element must have a fixed width.

    Since you are using inline-block Try this:

    div {
      text-align:Center;
    }