I want to make something really simple.
When I click a div I want to display some text centered on any resolution.
Here is my approach:
<button>Click</button>
<div id="fade"><a class="close" href="#">×</a>
<p>Lorem ipsum sit dolor amet</p>
</div>
and this css:
#fade {background:red; width:100%; height:150px;}
.close {
color:white;
font:bold 40px Arial,Sans-Serif;
text-decoration:none;
}
Here is a jsfiddle
Now what I want to do is to center that #fade div on every screen resolution.
How can I accomplish this ?
divthat is always centered vertically and horizontallyFirst, you need to set an actual width for the
div. 100% won’t do.Next, set its
positiontoabsolute;Then here’s the updated jQuery:
DEMO