html - css Horizontally center div in a div -


i'm trying horizontally center block element on page.

here example of want:

enter image description here

i cannot use div hard sizing because layout should responsive.

http://fiddle.jshell.net/rdy9nmp0/

here code:

 <div class = "container">     <div class="sub">         <h1> 01</h1>         <div class = "icon"><img src="img/settings.png" alt="">             <h2> power inside</h2>             <p>cum sociis natoque penatibus et magnis dis parturient montesmus. pro vel nibh et elit mollis commodo et nec augueique</p>             <a class="iconlink" href="/">read more</a>         </div>     </div>  <div> 

css

.container {      width: 1160px;     overflow: hidden;     display: inline-flex;     margin: 0 auto;     }  .sub{     padding-top: 30px;     padding-bottom: 30px;     padding-right: 30px;     padding-left: 30px;     display: inline-block;     vertical-align: top;  }  .sub h1{     font-size: 90px;     color: #efeff0;     font-family: 'ubuntu', sans-serif;     padding: 0px;     float:left; }  .sub img {     padding: 10px 0px 10px 0px; }  .sub h2  {     color: #2a2b2e;     font-size: 20px;     font-family: 'ubuntu', sans-serif; }  .sub p {     color: #8a8a8a;     font-size: 13px;     font-family: 'arial', sans-serif; } .sub .icon{     overflow: hidden;     padding-left:20px; } .sub .iconlink{     font-size: 13px;     color: #2a2b2e;     height: 28px;     -moz-border-radius: 50px;      -webkit-border-radius: 50px;     border-radius: 50px;     text-decoration: none;     vertical-align:baseline;     font-weight: bold;     font-family: 'ubuntu', sans-serif;     background: url(../img/shape_blue.png) no-repeat scroll right center #fff;     padding: 0 20px 0 0;     background-position: right; }  .container .iconlink:hover, .iconlink:hover {     color: #248cec;     background: url(../img/shape_grey.png) no-repeat scroll right center #fff;      text-decoration: none;     vertical-align:baseline;     background-position: right; } .container .iconlink a:active {     color: #248cec; }  img {     display:inline-block; } 

this should want.

.container {     display: flex; /*rather inline-flex*/ } 

if need inline-flex make parent element text-align:center;


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -