html - Toggle switch button - how to set responsive measurements? -
i've created this toggle button, , can't set it's size percentage - responsive. manage set it's text viewport width , height - , it's working well, don't want button in viewport measurements....
perhaps ::before , ::after cannot receive measurements in percentage?
html:
<div class="cont"> <div class="box"> <div class="material-switch"> <input id="someswitchoptiondefault" name="someswitchoption001" type="checkbox" /> <label for="someswitchoptiondefault" class="label-default"><span class="homme">homme</span><span class="femme">femme</span> </label> </div> </div> </div> css:
.cont { padding: 50px; background-color: #e9e9e9; width: 100vw; height: 100vh; } .box { width: 100px; height: 100px; } .material-switch > input[type="checkbox"] { display: none; } .material-switch > label { cursor: pointer; height: 0px; position: relative; width: 40px; } .material-switch > input[type="checkbox"] + label::before { content: "\f222"; font-family: fontawesome; font-style: normal; font-weight: normal; text-decoration: inherit; color: #333333; text-align: right; border: 1px solid #dcdcdc; padding-left: 10px; padding-right: 10px; } .material-switch > label::before { background-color: #f6f6f6; border-radius: 16px; height: 24px; margin-top: -12px; position: absolute; width: 100px; } .material-switch > label::after { /*--button---*/ content: ""; font-size: 18px; background-color: #fff; border-radius: 15px; height: 24px; left: -4px; margin-top: -8px; position: absolute; top: -4px; width: 73px; border: 1px solid #dcdcdc; } .material-switch > input[type="checkbox"]:checked + label::before { background-color: #f6f6f6; content: "\f221"; color: "blue"; font-family: fontawesome; text-align: left; } .material-switch > input[type="checkbox"]:checked + label::after { background-color: #fff; left: 30px; } .femme { display: none; } .material-switch > input[type="checkbox"]:checked + label>span.homme { display: none; } .material-switch > input[type="checkbox"]:checked + label>span.femme { display: block; } .homme { font-family: 'roboto light', sans-serif; font-style: normal; font-weight: normal; text-decoration: inherit; color: #5d5d5d; font-size: 1vw; position: absolute; top: -8px; left: 9px; z-index: 999; } .femme { font-family: 'roboto light', sans-serif; font-style: normal; font-weight: normal; text-decoration: inherit; color: #5d5d5d; font-size: 1vw; position: absolute; top: -8px; z-index: 999; } .material-switch > input[type="checkbox"]:checked + label .femme { left: 41px; } .homme::before { content: "\f222"; font-family: fontawesome; font-style: normal; font-weight: normal; text-decoration: inherit; color: #49c8c1; margin-right: 5px; } .femme::before { content: "\f221"; font-family: fontawesome; font-style: normal; font-weight: normal; text-decoration: inherit; color: #49c8c1; margin-right: 5px; }
i see in css have overridden lot of html dom properties, <input> component. suggest use simple , elegant toggle buttons available normal css. can check below toggle button examples:
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_switch https://codepen.io/mburnette/pen/lxnxng
Comments
Post a Comment