html - itHow do I make div/ div images not move when resizing, while also allowing them to have a % from the top -
i want able resize window while divs keep position on page , resize % of width , height declare.
html:
<body> <div class="view"> <div class="tree"> <img id="tree" src="img/tree.png"> </div> <div class="ground"> <div class="g"></div> </div> </div> </body>
css:
.tree { position: absolute; } .tree #tree { position: relative; height: 75%; width: 75%; left: 30%; } .ground { z-index: 2; width: 100%; height: 100%; } .ground .g { background-color: green; opacity: .5; position: relative; height: 50%; width: 100%; }
the tree stays pretty constant, when window largest can on macbook, slides on left little. ground element vertically takes half page, instead want placed 50% top. when try apply 'top' style either of them nothing happens. know because #tree relative .tree , don't declare height/ width. don't declare h/w because makes #tree image's w/h off.
thank help!
edit, added clarification:
i want divs resize according window width. don't want them change left position. , want able set 'top' % because can't.
fiddle: https://jsfiddle.net/sqdgzbp6/
notice on website: anniwang.com if resize entire window drawings seem resize don't loose position on page. want recreate effect similar hers.
as .tree
absolute positioned element, need height/width set explicit or else no child percent have calculate percent from, in sample gave height , top
work.
.tree { position: absolute; height: 100%; width: 100%; } #tree { position: relative; height: auto; width: 60%; left: 30%; top: 20%; } .ground { z-index: 2; width: 100%; height: 100%; } .ground .g { background-color: green; opacity: .5; position: relative; height: 50%; width: 100%; }
<div class="view"> <div class="tree"> <img id="tree" src="http://www.placehold.it/200/100"> </div> <div class="ground"> <div class="g"></div> </div> </div>
Comments
Post a Comment