For the explanation It seems more intuitive. I tried to draw the following sketch to describe it. I hope it can be expressed clearly. Front-end UI sharing
3: CSS code
In order to make the tutorial look more concise, I have omitted some CSS code for visual effects. (For example, the CSS for drawing the arrow part) - You can view the full version of the code in the attachment. For the same reason I've also omitted prefixes that can be specific to different browsers.
css of radio-container:
.code
radio-container {
position: relative;
height: 4em; /* 3em (being the max-height of the inner container) 1em ("margin") */
}
.radio-container:hover {
z-index: 9999; }
CSS of elements contained in radio-container: Front-end UI sharing
.code
.radio-options {
position: absolute;
max -height: 3em;
width: 100%;
overflow: hidden;
transition: 0.7s;
}
.radio-options:hover {
max-height: 100em;
}
then
.code
.radio-options .toggle {
position: relative;
cursor: pointer;
padding: 0.75em;
background: darkgreen;
border-radius: 10px;
z-index: 1; }
* li are stacked at the same position as .toggle, only .toggle is visible */
.radio-options li {
position: absolute;
top: 0 ;
left: 0;
width: 100%;
height: 100%;
}
.radio-options label {
display: block;
opacity: 0;
transition: 0s; }
In order to hide the input, we can use display: none to achieve the goal, but this method will not focus on the relevant input when clicking the label in some browsers (such as some mobile browsers). Front-end UI sharing
.code
.radio-options input {
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 3em;
opacity: 0;
z-index:1;
cursor: pointer;
}
Four: Move the mouse up css code
According to the above code, let’s take a closer look at what happens when the hover goes up. The z-index of .radio-container is a very large value, and at the same time, the z-index of .radio-options The max-height attribute has also become larger (to 100em), we continue:
. Code
/* li elements have a normal flow within the .radio-options container */
.radio-options:hover li {
position: relative; }
.radio-options:hover label {
opacity: 1;
transition: 0.5s; }
五:选中状态
To style the checked option we will use the general sibling selector. It uses a tilde character combinator (E ~ F) and matches elements that are siblings of a given element. The first element (E) has to occur before the second (F) one and they have to share the same parent (li items in our case).前端UI分享
If one of the radio is checked, we’ll see its label instead of the toggle :
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn