html - How can I centre an object whose height I do not know in a list? -
it seems no matter can't text black background centre vertically. problem text on 1 line , on 2 or three. i'm trying automatically adjust can't.
i have tried numerous approaches such listed on here.
here code trying centre:
.infogrid { display: inline-block; position: relative; bottom: 45px; right: 0; margin: 0px 1% -100% 1%; width: 98%; background-color: #f6f6f6; } .infogrid ul { margin: 0; padding: 0; text-align: center; } .infogrid li { display: inline-block; position: relative; background-color: white; width: 320px; margin: 1vw; height: 320px; transition: transform 0.4s; box-shadow: 0.2vh 0vh 0.8vh #888888; } .infogrid li:hover { transform: scale(1.05, 1.05); } .tilewrappertext { display: inline-block; color: white; visibility: hidden; z-index: 1; width: 100%; text-align: center; font-family: "century gothic", "arial", "sans-serif"; background-color: black; opacity: 0.75; font-size: 2.2em; } #tilewrapper:hover .tilewrappertext { visibility: visible; } <div class="infogrid"> <ul> <li> <div id="tilewrapper"> <img id="automargins" src="content/tile1.png" width="96%"> <h3 class="tilewrappertext">half price facials</h3> </div> </li> <li> <div id="tilewrapper"> <img id="automargins" src="content/tile2.png" width="96%"> <h3 class="tilewrappertext">1/4 off massages</h3> </div> </li> <li> <div id="tilewrapper"> <img id="automargins" src="content/tile3.png" width="96%"> <h3 class="tilewrappertext">20/3 off hot rocks</h3> </div> </li> <li> <div id="tilewrapper"> <img id="automargins" src="content/tile4.png" width="96%"> <h3 class="tilewrappertext">20/3 off nails</h3> </div> </li> <li> <div id="tilewrapper"> <img id="automargins" src="content/tile5.png" width="96%"> <h3 class="tilewrappertext">free use of sauna treatment</h3> </div> </li> <li> <div id="tilewrapper"> <img id="automargins" src="content/tile6.png" width="96%"> <h3 class="tilewrappertext">free use of jacuzzi treatment</h3> </div> </li> <li> <div id="tilewrapper"> <img id="automargins" src="content/tile7.png" width="96%"> <h3 class="tilewrappertext">1/20 off eyes</h3> </div> </li> <li> <div id="tilewrapper"> <img id="automargins" src="content/tile8.png" width="96%"> <h3 class="tilewrappertext">1/20 off hair</h3> </div> </li> </ul> </div> the text appears when image hovered over.
since li position relative, can add following css rules h3 center vertically within li.:
position: absolute; top: 50%; transform: translatey(-50%); margin: 0; example here: http://codepen.io/nicerhugs/details/dmgmev/
the top move top of h3 halfway down li, , transform correct height of li itself. getting rid of margin take away weird mystery space makes appear lower is.
Comments
Post a Comment