How to use pure CSS to achieve the effect of a coffee machine
This article mainly introduces how to use pure CSS to achieve the effect of a coffee machine. It has certain reference value. Now I share it with you. Friends in need can refer to it

Source code download
Please download all the source code of the daily front-end practical series from github:
https://github.com/comehope/front-end-daily- challenges
Code Interpretation
Define dom, the container contains the body, water outlet, coffee cup, button and coffee:
<p> <span></span> <span></span> <span></span> <span></span> <span></span> </p>
Centered display:
body {
margin: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(to right bottom, sandybrown, darkred);
}
Define the container size:
.coffee-machine {
width: 15em;
height: 15em;
background-color: white;
font-size: 20px;
border-radius: 50%;
border: 2em solid white;
}
Draw the outer frame of the body:
.coffee-machine {
position: relative;
display: flex;
justify-content: center;
}
.body {
position: absolute;
width: 8em;
height: 12em;
background-color: sandybrown;
border-radius: 1.2em;
top: 1.5em;
border-right: 0.6em solid peru;
}
Use pseudo elements to draw the middle part of the body:
.body::after {
content: '';
position: absolute;
width: 8em;
height: 8em;
background-color: darkslategray;
top: 2em;
border-right: 0.6em solid black;
}
Draw the water outlet:
.spout {
position: absolute;
width: 3em;
height: 1em;
background-color: white;
top: 3.5em;
border-radius: 0.5em;
border-right: 0.5em solid silver;
}
Draw the body of the coffee cup:
.cup {
position: absolute;
width: 3em;
height: 2em;
background-color: white;
bottom: 3.5em;
border-radius: 0 0 1.4em 1.4em;
border-right: 0.5em solid silver;
}
Use pseudo elements to draw the handle of the coffee cup:
.cup::after {
content: '';
position: absolute;
width: 0.6em;
height: 0.6em;
border: 0.3em solid silver;
border-radius: 50%;
right: -1.2em;
top: 0.2em;
}
Draw the button:
.button {
position: absolute;
width: 1.2em;
height: 1.2em;
background-color: tomato;
border-radius: 50%;
bottom: 2em;
right: 4.5em;
}
Draw the coffee :
.coffee::before,
.coffee::after {
content: '';
position: absolute;
width: 0.7em;
height: 5em;
background-color: chocolate;
top: 4.5em;
left: calc((15em - 0.7em) / 2);
}
Next, polish it up.
Add light and shadow to the coffee machine:
.coffee-machine {
z-index: 1;
}
.coffee-machine::before,
.coffee-machine::after {
content: '';
position: absolute;
width: 2em;
height: 2em;
border: 0.3em solid transparent;
z-index: 2;
border-radius: 50%;
border-left-color: white;
left: 3.8em;
}
.coffee-machine::before {
top: 1.8em;
transform: rotate(40deg);
}
.coffee-machine::after {
bottom: 1.8em;
transform: rotate(-40deg);
}
Define the first half of the coffee flow animation, that is, the coffee flows from the outlet to the cup:
.coffee::before {
animation: 2s linear infinite;
animation-name: pouring-before;
transform-origin: top;
}
@keyframes pouring-before {
0%, 20% {
transform: scaleY(0);
}
30%, 100% {
transform: scaleY(1);
}
70%, 100% {
visibility: hidden;
}
}
Define the second half of the coffee flow Animation, that is, the coffee outlet stops flowing out, and the remaining coffee flows into the cup:
.coffee::after {
animation: 2s linear infinite;
animation-name: pouring-after;
transform-origin: bottom;
}
@keyframes pouring-after {
0%, 70% {
visibility: hidden;
transform: scaleY(1);
}
80%, 100% {
transform: scaleY(0);
}
}
Done!
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to use pure CSS to achieve the effect of a color card
The above is the detailed content of How to use pure CSS to achieve the effect of a coffee machine. For more information, please follow other related articles on the PHP Chinese website!
A Little Reminder That Pseudo Elements are Children, Kinda.Apr 19, 2025 am 11:39 AMHere's a container with some child elements:
Menus with 'Dynamic Hit Areas'Apr 19, 2025 am 11:37 AMFlyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should
Improving Video Accessibility with WebVTTApr 19, 2025 am 11:27 AM"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee
Weekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteApr 19, 2025 am 11:25 AMIn this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.
Making width and flexible items play nice togetherApr 19, 2025 am 11:23 AMThe short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.
Weekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryApr 19, 2025 am 11:18 AMIn this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties
IndieWeb and WebmentionsApr 19, 2025 am 11:16 AMThe IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:


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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool








