我正在開發一個 Web 應用程序(使用 AngularJS),我需要創建一個切換開關。網上的指南看起來并不難,我遵循的是 W3C 的指南:https://www.w3schools.com/howto/howto_css_switch.asp在本指南中,一切正常:我可以在切換開關區域內單擊任何我想要的位置,并且它的行為符合預期。顯然,其背后必須有一個checkbox類型輸入。不幸的是,這在我的應用程序中沒有發生。這是我的代碼(我使用它是因為標簽已經有了正確的<div>樣式):<label><style>.switch { position: relative; display: inline-block; width: 60px; height: 34px;}.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: .4s; transition: .4s;}.slider:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; -webkit-transition: .4s; transition: .4s;}input:checked + .slider { background-color: #2196F3;}input:focus + .slider { box-shadow: 0 0 1px #2196F3;}input:checked + .slider:before { -webkit-transform: translateX(26px); -ms-transform: translateX(26px); transform: translateX(26px);}.slider.round { border-radius: 34px;}.slider.round:before { border-radius: 50%;}</style> <div class="switch"> <input type="checkbox"> <span class="slider round"></span></div>正如您所看到的,這是完全相同的 W3C 代碼(除了我沒有隱藏輸入,否則在我的情況下什么都不會發生?。?。不幸的是發生了以下事情:input checkbox風格是完美的,但只有通過單擊左小角(這將是故意不被遮擋的?。袨椴攀钦_的。如果我按照 W3C 的建議使復選框輸入不可見,我將無法再單擊該角落,并且什么也不會發生!我不明白如何使input checkbox隱形,但仍然將其行為擴展到整個切換開關!我哪里錯了?
CSS:切換開關的問題。如何呈現整個切換的輸入復選框的行為?
開心每一天1111
2023-08-18 17:47:39