-1

I am trying to center text and images on a "content" div. I tried (margin: 0 auto;) and couple more and still not getting it. Also trying to center the div on the screen.

CSS:

#content {
    width: 100%;
}

#content img {
    width: 50%;
    opacity: 0.75;
}

#content img:hover {
    opacity: 1;
}

HTML:

<div id="content">
    <img src="images/intro_7.jpg">
</div>

1 Answers1

3

In #content, add text-align:center;:

#content {
    width: 100%;
    text-align:center;
}

UPDATE

Use table and table-cell to center is horizontally and vertically.

Surround your HTML with three div as follows:

<div class="outter">
<div class="center">
<div class="inner">

CSS:

.outter {
    display: table;
    position: absolute;
    height: 100%;
    width: 100%;
}
.center {
    display: table-cell;
    vertical-align: middle;
}

.inner {
    margin-left: auto;
    margin-right: auto;
}

JSFiddle Demo

More info here for vertical alignment.

Note: IE7 and below do not support display:table; or display: table-cell;

imbondbaby
  • 6,351
  • 3
  • 21
  • 54