This content originally appeared on DEV Community and was authored by Labby
Introduction
In this lab, we will be exploring the fundamentals of CSS programming. The purpose of this lab is to help you gain a solid understanding of CSS syntax, selectors, properties, and values. By completing this lab, you will be able to style HTML elements and create visually appealing web pages.
Hamburger Button
index.html
and style.css
have already been provided in the VM.
To create a hamburger menu that transitions to a cross button on hover, follow these steps:
- Use a
.hamburger-menu
containerdiv
which contains the top, bottom, and middle bars. - Set the container to
display: flex
withflex-flow: column wrap
. - Add distance between the bars using
justify-content: space-between
. - Use
transform: rotate()
to rotate the top and bottom bars by 45 degrees andopacity: 0
to fade the middle bar on hover. - Use
transform-origin: left
so that the bars rotate around the left point.
Here's the corresponding HTML code:
<div class="hamburger-menu">
<div class="bar top"></div>
<div class="bar middle"></div>
<div class="bar bottom"></div>
</div>
And here's the CSS code:
.hamburger-menu {
display: flex;
flex-flow: column wrap;
justify-content: space-between;
height: 2.5rem;
width: 2.5rem;
cursor: pointer;
}
.hamburger-menu .bar {
height: 5px;
background: black;
border-radius: 5px;
margin: 3px 0px;
transform-origin: left;
transition: all 0.5s;
}
.hamburger-menu:hover .top {
transform: rotate(45deg);
}
.hamburger-menu:hover .middle {
opacity: 0;
}
.hamburger-menu:hover .bottom {
transform: rotate(-45deg);
}
Please click on 'Go Live' in the bottom right corner to run the web service on port 8080. Then, you can refresh the Web 8080 Tab to preview the web page.
Summary
Congratulations! You have completed the Hamburger Button lab. You can practice more labs in LabEx to improve your skills.
🚀 Practice Now: CSS Fundamentals for Web Styling
Want to Learn More?
- 🌳 Learn the latest CSS Skill Trees
- 📖 Read More CSS Tutorials
- 💬 Join our Discord or tweet us @WeAreLabEx
This content originally appeared on DEV Community and was authored by Labby
Labby | Sciencx (2024-07-31T03:23:56+00:00) CSS Programming Fundamentals | Web Development. Retrieved from https://www.scien.cx/2024/07/31/css-programming-fundamentals-web-development/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.