How to Create Swinging Lamp With
HTML & CSS
Video Tutorial of Swinging Lamp
Swinging Lamp [Source Codes]
To Create Swinging Lamp with HTML and CSS, follow the given steps line by line:
Create a folder. You can name this folder whatever you want, and inside this folder, create the mentioned files.
Create an index.html file. The file name must be index and its extension .html
Create a style.css file. The file name must be style and its extension .css
Once you create these files, paste the given codes into the specified files. If you don’t want to do these then scroll down and download the source code by clicking download button.
First, paste the following codes into your index.html file
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>CSS Lamp</title>
- <link rel="stylesheet" href="style.css">
- </head>
- <body>
- <div class="container">
- <div class="lamp">
- <input type="checkbox">
- </div>
- </div>
- </body>
- </html>
Now paste the following codes into your style.css file
- body{
- padding: 0;
- margin: 0;
- background-color: #000000;
- }
- .container{
- height: 500px;
- width: 500px;
- position: absolute;
- transform: translate(-50%,-50%);
- left: 50%;
- top: 50%;
- }
-
- .lamp {
- height: 0;
- width: 170px;
- border-bottom: 150px solid #6EC7B0;
- border-right: 30px solid transparent;
- border-left: 30px solid transparent;
- border-top-left-radius: 50px;
- border-top-right-radius: 50px;
- position: absolute;
- margin: auto;
- left: 0;
- right: 0;
- top: 100px;
- background: linear-gradient(to bottom, #6EC7B0,#fff, #388E8E);
- }
-
- .lamp:before{
- content: "";
- position: absolute;
- height: 100px;
- width: 10px;
- background-color: #759493;
- margin: auto;
- left: 0;
- right: 0;
- top: 150px;
- }
-
- .lamp:after{
- content: "";
- position: absolute;
- height: 50px;
- width: 100px;
- background-color: #666666;
- top: 230px;
- margin: auto;
- left: 0;
- right: 0;
- border-radius: 50px 50px 0 0;
- }
-
- input[type="checkbox"]{
- -webkit-appearance: none;
- appearance: none;
- background-color: #e5e5e5;
- height: 25px;
- width: 5px;
- position: absolute;
- top: 147px;
- left: 170px;
- outline: none;
- cursor: pointer;
- transition: 0.5s;
- }
- input[type="checkbox"]:after{
- content: "";
- position: absolute;
- height: 15px;
- width: 15px;
- background-color: #ffffff;
- border-radius: 50%;
- left: -5px;
- bottom: -2px;
- }
- input[type="checkbox"]:before{
- content: "";
- position: absolute;
- height: 130px;
- width: 240px;
- left: -208px;
- z-index: -5;
- clip-path: polygon(10% 0, 90% 0, 100% 100%, 0 100%);
- transition: 0.5s;
- pointer-events: none;
- }
- input[type="checkbox"]:checked{
- height: 40px;
- }
- input[type="checkbox"]:checked:before {
- background: linear-gradient(
- rgba(255, 255, 255, 0.4),
- rgba(255, 255, 255, 0.1)
- );
- box-shadow: 10px 0 15px rgba(255, 255, 255, 0.3), -10px 0 15px rgba(255, 255, 255, 0.3);
- }
-
If you face any difficulties while creating your Swinging Lamp or your code is not working as expected, you can download the source code files by clicking on the download button.