javascript - Best way to center div in responsive div -


i've been trying several hours both vertically , horizontally center div no specific width or height in parent div has max-width , max-height responsive. i've looked @ both css , js/jquery options nothing working properly.

as can see, it's thumbnail preview video. when in normal state, shows thumbnail play icon above it. in hover state, changes play button orange one, displays title, , has black transparent overlay above thumbnail.

now, easy css if site wasn't responsive. but, browser width decreases, thumbnail sizes decrease.

here's html i'm using:

<article class="movie"><a href="#">      <div class="movie-overlay">          <div class="movie-play"></div>          <h2 class="movie-title">title goes here</h2>      </div> <!-- end .movie-overlay -->      <div class="movie-thumb"><img src="thumbs/thumb.jpg"/></div>  </a></article> <!-- end #post- --> 

and here's css:

.movie-archive .movie {     width: 50%;     height: auto;     max-width: 480px;     position: relative;     overflow: hidden;     float: left; }  .movie-archive .movie .movie-overlay {     width: 100%;     height: 100%;     position: absolute;     text-align: center; }  .movie-archive .movie:hover .movie-overlay {background: rgba(0, 0, 0, 0.6);}  .movie-archive .movie .movie-play {     background: url("images/play-icon@2x.png") no-repeat center 0;     background-size: 94px 190px;     width: 100%;     height: 95px; }  .movie-archive .movie:hover .movie-play {background-position-y: -95px;}  .movie-archive .movie .movie-title {     font-size: 17px;     letter-spacing: -0.01em;     font-weight: 700;     color: #ffffff;     display: none;     padding: 10px 50px 0; }  .movie-archive #latest-top.movie:hover .movie-title, .movie:hover .movie-title {display: block;}  .movie-archive .movie .movie-thumb img {     width: 100%;     height: 100%;     display: block; } 

i've tried various things adding div , using display: table trick adding padding percentage, , using js. nothing seems work. have suggestions? appreciate it. thanks!

not matters, using wordpress site.

the container , elemented want centered should have properties this:

.movie-archive .movie {     width: 50%;     height: auto;     max-width: 480px;     position: relative;     overflow: hidden;     float: left; }  .movie-archive .movie .movie-overlay {     width: 100%;     height: 100%;     left: 50%;     margin-left: -50%; //half of width     top: 50%;     margin-top: -50%; //half of height     position: absolute;     text-align: center; //only if want text centered } 

source: http://designshack.net/articles/css/how-to-center-anything-with-css/


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -