Search code examples
htmlcsscenteralignment

HTML relative centre align


I'm trying to centre align an image using a div and a CSS class (the tag is wrapped in a div class="center" tag). What I'm using at the moment is working in Dreamweaver (when I go to design view) but not when I load the page up in Safari. Here is my code:

.center {
  display:inline; 
  text-align:center; 
  -webkit-inline; 
  -webkit-center; 
  background-color:transparent;
}

Sorry for asking such a simple question, I'm completely new to HTML, my experience is in Objective-C.


Solution

  • Give text-align:center; to it's .center parent DIV. Write like this:

    HTML

    <div class="parent">
     <div class="center"></div>
    </div>
    

    CSS

    .parent{
     text-align:center;
    }
    
    .center {
     display:inline;
     background-color:transparent;
    }