javascript - How to fix an element to the right of div? -
i have button want fix it's position right of div, button toggling visibility of it's left div, problem button loses it's position once resolution changing...
here example
and here i've done far:
$('.results_toggle').on('click', function() { $(this).toggleclass('left_hide'); $('.left').toggle(); });
.cont { width: 100vw; } .left { position: relative; width: 50vw; height: 100vh; background-color: grey; float: left; border-left: 2px solid white; } .right { height: 100vh; width: 50vw; float: left; } .results_toggle:before { content: "\f054"; font-family: fontawesome; font-style: normal; font-weight: normal; text-decoration: inherit; color: black; font-size: 24px; padding-right: 0.5em; position: absolute; top: 14px; left: 5px; } .results_toggle { background-color: grey; height: 60px; width: 30px; position: absolute; z-index: 106; top: 45vh; right: 223px; border-bottom-right-radius: 110px; border-top-right-radius: 110px; border-bottom: 0; } .left_hide { left: 0px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="cont"> <div class="left"> </div> <div class="results_toggle"> <!-- button --> </div> <div class="right"> </div> </div>
the simplest solution put toggle within .right
div, , position @ left: 0
adjacent .left
div, this:
<div class="cont"> <div class="left"></div> <div class="right"> <div class="results_toggle"></div> </div> </div>
.right { position: relative; /* add */ } .results_toggle { /* remove 'right' */ left: 0; /* add */ }
the advantage of method unaffected change in screen resolution.
Comments
Post a Comment