


How to use pure CSS to implement an aircraft porthole style toggle control
The content of this article is about how to use pure CSS to implement the aircraft porthole style toggle control. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Effect preview
Source code download
https://github.com/comehope/front- end-daily-challenges
Code interpretation
Define dom, .windows
container represents the porthole, and its child element .curtain
represents the curtain:
<figure> <div></div> </figure>
Centered display:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: skyblue; }
Set the size of the portholes. Because the font size will be used later, the font size is defined with variables:
:root { --font-size: 10px; } .window { position: relative; box-sizing: border-box; width: 25em; height: 35em; font-size: var(--font-size); background-color: #d9d9d9; }
Use shadow to draw a thick window frame:
.window { border-radius: 5em; box-shadow: inset 0 0 8em rgba(0, 0, 0, 0.2), 0 0 0 0.4em #808080, 0 0 0 4em whitesmoke, 0 0 0 4.4em #808080, 0 2em 4em 4em rgba(0, 0, 0, 0.1); }
Set the curtain style to the same size as the window, but do not pull it all the way:
.window .curtain { position: absolute; width: inherit; height: inherit; border-radius: 5em; box-shadow: 0 0 0 0.5em #808080, 0 0 3em rgba(0, 0, 0, 0.4); background-color: whitesmoke; left: 0; top: -5%; }
Use pseudo elements to draw indicator lights on the curtains, which will light up red when the curtains are closed:
.window .curtain::before { content: ''; position: absolute; width: 40%; height: 0.8em; background-color: #808080; left: 30%; bottom: 1.6em; border-radius: 0.4em; } .window .curtain::after { content: ''; position: absolute; width: 1.6em; height: 0.8em; background-image: radial-gradient(orange, orangered); bottom: 1.6em; border-radius: 0.4em; left: calc((100% - 1.6em) / 2); }
The above is what the porthole looks like when it is closed. Next, draw the effect when the porthole window is open.
First add a checkbox
in the dom. When it is checked
, it means the porthole is opened:
<figure> <div></div> </figure>
Hidecheckbox
, Use opacity(0)
to make the element interactive even when it is invisible. Set its size to be as big as the porthole, and the layer is above the porthole. The effect will be the actual effect when clicking on the porthole. is clicked checkbox
:
.toggle { position: absolute; filter: opacity(0); width: 25em; height: 35em; font-size: var(--font-size); cursor: pointer; z-index: 2; }
When the porthole is open, .curtain
wants to move upward, and the indicator light lights green:
.window .curtain { transition: 0.5s ease-in-out; } .toggle:checked ~ .window .curtain { top: -90%; } .toggle:checked ~ .window .curtain::after { background-image: radial-gradient(lightgreen, limegreen); }
Hide beyond Part of the window:
.window { overflow: hidden; }
Next, draw the scenery outside the porthole.
Add the .clouds
element that represents clouds in the dom, and the five <span></span>
sub-elements represent one white cloud respectively:
<input> <figure> <div></div> <div> <span></span> <span></span> <span></span> <span></span> <span></span> </div> </figure>
Use The cloud container draws the blue sky outside the window:
.window .clouds { position: relative; width: 20em; height: 30em; background-color: deepskyblue; box-shadow: 0 0 0 0.4em #808080; left: calc((100% - 20em) / 2); top: calc((100% - 30em) / 2); border-radius: 7em; }
Each cloud is composed of 3 parts. Draw the largest part first:
.clouds span { position: absolute; width: 10em; height: 4em; background-color: white; top: 20%; border-radius: 4em; }
Then use pseudo elements to draw 2 protruding arcs:
.clouds span::before, .clouds span::after { content: ''; position: absolute; width: 4em; height: 4em; background-color: white; border-radius: 50%; } .clouds span::before { top: -2em; left: 2em; } .clouds span::after { top: -1em; right: 1em; }
Increase the animation effect of floating clouds:
.clouds span { animation: move 4s linear infinite; } @keyframes move { from { left: -150%; } to { left: 150%; } }
Make some changes in the size and position of each cloud:
.clouds span:nth-child(2) { top: 40%; animation-delay: -1s; } .clouds span:nth-child(3) { top: 60%; animation-delay: -0.5s; } .clouds span:nth-child(4) { top: 20%; transform: scale(2); animation-delay: -1.5s; } .clouds span:nth-child(5) { top: 70%; transform: scale(1.5); animation-delay: -3s; }
Finally, hide the content outside the container:
.window .clouds { overflow: hidden; }
Done!
The above is the detailed content of How to use pure CSS to implement an aircraft porthole style toggle control. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.
