Use CSS to draw a clear picture (●-●)_html/css_WEB-ITnose
This time we will use CSS to draw the avatar of Baymax from Super Marines.
What we do is to use CSS to dynamically change the position of the background image on an element, and add some linear effects.
See the Pen Baymax face - Hero Number 6 by Donovan Hutchinson (@donovanh) on CodePen. The part that shows the face
Style rendering
In order to make the effect cooler, we use radial-gradient on the body to add subtle color gradient changes to make it more like a head.
<div class="baymax"></div>
Next, we position the face. The mouth is just a black line, and we use border to achieve it.
body { background: radial-gradient(center, #fff, #fff 50%, #aaa); background-size: 100%; background-repeat: no-repeat; height: 100vh; }
The problem is that our element now starts at the midpoint of the container, but not out of the middle.
.baymax { border-bottom: 1.5em solid #000; position: absolute; top: 50%; left: 50%; width: 50%; transform: translate(-50%, -40%); }
In order to offset, we use transform to move the element to the left and up according to 50% of its own width and 40% of its height.
So the position of the mouth is like this
Add eyes
We use before and after pseudo-classes to implement the eyes, which does not require extra HTML , and using CSS entirely is enough.
Each pseudo-class has a black background, a 50% border-radius, and is positioned at the edge of the mouth. Finally, use skew transformation to move the eyes a little closer to the middle, and the result becomes like this.
.baymax::before { background: #000; border-radius: 50%; content: ""; position: absolute; width: 12em; height: 12em; left: -9em; top: -6em; transform: skewX(-4deg); }.baymax::after { background: #000; border-radius: 50%; content: ""; position: absolute; width: 12em; height: 12em; right: -9em; top: -6em; transform: skewX(4deg); }
Low battery
This is a very interesting scene in the movie. (●?●) The battery is out and its upper and lower eyelids are fighting. We can do this using color gradient backgrounds and animations.
First, we give the background two colors, black to show the state of open eyes, and white to represent squinting. The white part needs to be positioned outside the eyes initially, and then animation is used to make the eyes droop.
We added a linear gradient background, making it twice the height of the container and positioning the top half outside the container.
With the background, we can control the entire action through keyframes animation.
.baymax::before { background: linear-gradient(to bottom, #efefef, #efefef 50%, #000 50%, #000); background-position: 0 -100%; background-size: 200%; ... } .baymax::after { background: linear-gradient(to bottom, #efefef, #efefef 50%, #000 50%, #000); background-position: 0 -100%; background-size: 200%; ... }
The keyframes animation defines a series of frames through percentages. The percentages are related to the animation execution time, so 50% represents half of the animation time.
Here we do the blink animation 50% to 85% of the time.
@keyframes blink { 0%, 50% { background-position: 0 100%; } 85%, 95% { background-position: 0 75%; } 100% { background-position: 0 100%; }}
The next step is to tell the pseudo class to perform this animation. Add the animation attribute.
The above code sets the execution time to 6 seconds and will loop forever.
In addition, in order to make the effect more realistic, we added a 0.1s delay to the after pseudo-class, so it seems that the second eye will be a little slower and look more cute.
.baymax::before { animation: blink 6s infinite; ... } .baymax::after { animation: blink 6s 0.1s infinite; ... }
Browser Compatibility
In this example, I omitted the browser compatibility stuff, -webkit, -moz, etc. Animation needs to consider browser compatibility. Here I recommend you to use a tool like Autoprefixer.
Share the gif version
There is a gif version here, you can share it online as you like.
This article is translated by @cssanimation. The entire translation contains my own understanding and meaning. If there is anything that is not translated well or is wrong, please give me some advice. If you want to reprint this translation, please indicate the English source: https://cssanimation.rocks/baymax/

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



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

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.

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