html - Horizontal and vertical center a fixed width/height element in svg -
i have following html code:
<div class="youtube-preview" style="background-color: #333; position: relative; width: 420px; height:316px"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="80" height="55" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);"> <rect width="100%" height="100%" rx="20" ry="0" fill="#fff"/> </svg> </div>
this produces div has smaller box inside centered both vertically , horizontally, exact effect want.
however, want convert svg. i've spent last 2 days looking a way center element (without scaling) in fluid dimensioned svg , couldn't find anything.
is possible? seems pretty basic...
notes:
- the "black box" can have width , height , ratio can change.
- the inner box has fixed dimensions , should not scale (up or down)
no. can't done - without using javascript resize , reposition inner box.
if want svg responsive, have accept inside scale also.
this may possible svg 2, not svg 1.1 , current browsers.
Comments
Post a Comment