html - When I put my buttons on div CSS doesn't work -
i want buttons auto middle on page, can't bec of when put buttons on div, doesnt work. helping
*:focus{ outline:0px; } body{ width:100%; } .buttons{ width:200px; margin: 0 auto; } .tr,.eu{ width:65px;height:30px; border-radius: 5px; border-color:transparent; background-color:#00405d; color:white; font-weight:500; } .tr:active,.eu:active{ padding:3px; } .eu {display: none;} .eu:focus ~ .tr {display: none;} .tr:focus ~ .tr {display: block;} .tr:focus ~ .eu {display: none;} .eu:focus ~ .eu {display: block;} first 2 buttons <button type="button" class="eu" name="button">eu</button> working <button type="button" class="tr" name="button">tr</button> working first 2 buttons <br> <br> other 2 buttons in div <!--but doesnt work bec of in div --> <div> <button type="button" class="eu" name="button">eu</button>doesnt work on div <button type="button" class="tr" name="button">tr</button>doesnt work on div </div> <!--but doesnt work bec of in div --> other 2 buttons in div <br> <br> <br> result: <div class="tr"> tr </div> <div class="eu"> eu </div>
add following css rule codes
button.eu, button.tr { border: solid red; transform: translate(-50%, 0%); -webkit-transform: translate(-50%, 0%); -moz-transform: translate(-50%, 0%); -ms-transform: translate(-50%, 0%); -o-transform: translate(-50%, 0%); position: relative; left: 50%; } #btn_container { position: relative; } snippet below
var eu_btns = document.getelementsbyclassname("eu"); var tr_btns = document.getelementsbyclassname("tr"); var div1 = document.getelementsbyclassname("tr")[0]; var div2 = document.getelementsbyclassname("eu")[0]; (var x = 0; x < eu_btns.length; ++x) { eu_btns[x].addeventlistener("click", eu_click) } (var x = 0; x < tr_btns.length; ++x) { tr_btns[x].addeventlistener("click", tr_click) } function eu_click() { div2.style.display = "inline-block"; div1.style.display = "none"; } function tr_click() { div1.style.display = "inline-block"; div2.style.display = "none"; } *:focus { outline: 0px; } body { width: 100%; } .buttons { width: 200px; margin: 0 auto; } .tr, .eu { width: 65px; height: 30px; border-radius: 5px; border-color: transparent; background-color: #00405d; color: white; font-weight: 500; } .eu { display: none; } .eu:focus ~ .tr { display: none; } .tr:focus ~ .tr { display: block; } .tr:focus ~ .eu { display: none; } .eu:focus ~ .eu { display: block; } button.eu, button.tr { border: solid red; transform: translate(-50%, 0%); -webkit-transform: translate(-50%, 0%); -moz-transform: translate(-50%, 0%); -ms-transform: translate(-50%, 0%); -o-transform: translate(-50%, 0%); position: relative; left: 50%; } #btn_container { position: relative; } .tr, .eu { display: inline-block; } <button type="button" class="tr" name="button">tr</button> <!--working --> <!--but doesnt work bec of in div --> <div id="btn_container"> <button type="button" class="eu" name="button">eu</button> <button type="button" class="tr" name="button">tr</button> </div> <!--but doesnt work bec of in div --> <br> <br> <br> <div class="tr"> tr </div> <div class="eu"> eu </div>
Comments
Post a Comment