html - Center elements within an image -
i have tried solutions in here, here, here , many other sources can't seem want.
i'm using kickstart template , want have image , text/elements centered (horizontally , vertically) on it. have:
<div class="grid"> <div class="col_12" style="margin-top:50px;" > <div class="mainimage"> <h2>h2 text</h2> <h3>h3 text</h3> </div> </div>
and css:
.mainimage { height:400px; width:100%; background-image: url(img/customers.png); text-decoration:line-through; display: flex; justify-content: center; /* align horizontal */ align-items: center; /* align vertical */ }
i have tried
display: table-cell; vertical-align: middle;
but these don't work.
most solutions involve specifying width. not want specify width want page responsive. if use display:table makes background image smaller.
what want to: 1. have image in own size 2. have elements centered on it
any suggestions can try out?
thank you.
i came across issue while ago. came with:
html
<section id="abc"> <div class="table-cell"> <div class="table-center"> centered </div> </div> </section>
css
#abc { background: url(http://i.imgur.com/nvh8ni3.jpg) 50% 0 repeat; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; margin: 0; padding: 0; width: 100%; height: 500px; display: table; -moz-box-shadow: inset 0 0 20px #333; -webkit-box-shadow: inset 0 0 20px #333; box-shadow: inset 0 0 20px #333; } .table-cell { display: table-cell; text-align: center; vertical-align: middle; } .table-center { display: inline-block; width: 460px; background: rgba(45, 45, 45, 0.80); border-radius: 5px; padding: 30px 30px; -webkit-box-shadow: 0 0 7px 2px #0f1519; box-shadow: 0 0 7px 2px #0f1519; } .col-centered { float: none; margin: 0 auto; }
Comments
Post a Comment