Home > Article > Web Front-end > Create a cute frog expression using html
We generally use the float method for horizontal three-column layout, and display each floating block in the same line. This method will result in the element not having the original height attribute, and clearing the float is required to solve the space occupation problem. It is very inconvenient for those special layouts. For example, vertical centering is not easy to achieve.
In 2009, W3C proposed a new solution - Flex layout, which can realize various page layouts simply, completely and responsively. Currently, it is supported by almost all browsers, which means that it is safe to use this feature now. Check out the blog for basic syntax: Flex Layout Tutorial: Grammar
In addition, you must have a certain understanding of pseudo-elements in css: before, after
Finally, if you want to make the expression move, the most important thing is to use the animation attribute.
We first lay out the overall seat so that each expression can be displayed intuitively in each position, because each The emoticons almost occupy a square space, so we display each frog emoticon horizontally on the page, using flex layout here.
<div class="container"><!--所有表情的存放容器,flex布局,所有子项目水平显示,自动换行,水平居中显示,竖直方向从顶部开始--><div class="emoji-container"> <!--存放青蛙表情的大容器,控制大小间距之类的属性--><div class="icon"> <!--存放每一个青蛙表情的容器,控制每一个表情自己的位置和特征--><div class="frog" id="frog-n"></div></div></div></div> body {background-color: #F1FFE6;} .container {width: 950px;margin: 70px auto 0px auto;text-align: center;} .container .emoji-container { /*flex弹性布局,多用于左右并排布局,跟float的作用类似,不用清除浮动*/ display: -webkit-box; display: -ms-flexbox; display: flex; /*justify-content属性定义了项目在主轴上的对齐方式。center就是在x轴上居中显示*/ -ms-grid-column-align: center; justify-items: center; /*align-items属性定义项目在交叉轴上如何对齐。flex-start就是从y轴的最上端开始排列*/ -webkit-box-align: start; -ms-flex-align: start; align-items: flex-start; /*flex-wrap属性定义,如果一条轴线排不下,如何换行。wrap:换行,第一行在上方。*/ -ms-flex-wrap: wrap; flex-wrap: wrap; } .container .emoji-container .icon { margin-right: 40px; margin-bottom: 40px; } .container .emoji-container .icon:nth-child(6n) { margin-right: 0px; } .icon {width: 125px;height: 120px;position: relative;} .icon .frog {position: absolute; top: 0;left: 0;width: 100%;height: 100%;}
Observe the expressions of each frog. Although each expression has a different shape, their bodies , mouth, eyes, and the position and size of the small blush are almost the same. We can write these consistent styles as common styles, and then write a single style for each frog's characteristics according to each person's frog ID for redrawing or overwriting.
<div class="frog" id="frog-1"> <!-- 蛙蛙的身体部分 --> <div class="body"> <!-- 蛙蛙的嘴巴 --> <div class="mouth"></div> </div> <!-- 蛙蛙的眼睛 --> <div class="eyes"> <!-- 蛙蛙的左右眼睛 --> <div class="eye eye-left"> <!-- 蛙蛙的内眼圈儿 --> <div class="eye-inner"> <!-- 蛙蛙的眼珠 --> <div class="pupil"> <!-- 蛙蛙眼圈里的光晕 --> <div class="light"></div> </div> </div> </div> <div class="eye eye-right"> <div class="eye-inner"> <div class="pupil"> <div class="light"></div> </div> </div> </div> </div> </div>/*蛙蛙身体部分样式*/.icon .frog .body {width: 110px;height: 86px;background-color: #A3D768; border-radius: 50%;position: absolute;top: 25px;left: 0;right: 0;margin: auto;box-shadow: 4px 4px 0px 0px rgba(163, 215, 104, 0.3); }/*蛙蛙嘴巴部分样式,因为每个蛙蛙的嘴巴不一样,所以公共样式就只定义了位置*/.icon .frog .body .mouth {margin: auto;}.icon .frog .eyes {width: 86px;height: 35px;position: absolute; top: 8px;left: 0;right: 0;margin: auto; }/*蛙蛙眼睛部分样式*/.icon .frog .eyes .eye {width: 35px;height: 35px;}.icon .frog .eyes .eye:before {content: "";display: block;width: 100%;height: 100%; background-color: #A3D768;border-radius: 50%; }/*蛙蛙眼圈部分样式*/.icon .frog .eyes .eye .eye-inner {background-color: #fff;width: 80%;height: 80%; position: absolute;top: 10%;left: 10%;border-radius: 50%; }/*蛙蛙眼珠部分样式*/.icon .frog .eyes .eye .eye-inner .pupil {background-color: #3F6A34; width: 60%;height: 60%;position: absolute;top: 20%;left: 20%;border-radius: 50%; }/*蛙蛙眼珠里的亮光部分样式*/.icon .frog .eyes .eye .eye-inner .pupil .light {background-color: #fff; width: 50%;height: 50%;position: absolute;top: 10%;left: 10%;border-radius: 50%; }/*蛙蛙左右两边眼睛的位置*/.icon .frog .eyes .eye-left {position: absolute;top: 0px;left: 0;}.icon .frog .eyes .eye-right {position: absolute;top: 0px;right: 0;}
The first little frog has a dynamic effect with the corners of its mouth rising based on the basic style, so to complete the drawing of the first frog, just create it in the public Just add the animation of the mouth based on the style, and the dom structure is the same.
.frog#frog-1 .body .mouth {width: 18px;height: 22px;border-bottom: 3px solid #3F6A34;position: absolute;top: 6px;left: 0;right: 0;-webkit-animation: smile 3.8s linear 0s infinite;animation: smile 3.8s linear 0s infinite; } @-webkit-keyframes smile { 0% { border-radius: 0%; } 20% { border-radius: 50%; } 70% { border-radius: 50%; } } @keyframes smile { 0% { border-radius: 0%; } 20% { border-radius: 50%; } 70% { border-radius: 50%; } }
The mouth of the second little frog is a big mouth, and there are two small blushes on the cheeks. The eyes are filled with love, so a blush div must be added to the dom structure. The style of the mouth and eyes should also be modified accordingly. (Mainly the production of mouth, blush and red heart)
<div class="frog" id="frog-2"> <div class="body"> <!--存放蛙蛙的脸颊红晕--> <div class="blush"></div> <!--加上大嘴巴的class big-month--> <div class="mouth big-mouth"></div> </div> <div class="eyes"> <div class="eye eye-left"> <div class="eye-inner"> <div class="pupil"> <div class="light"></div> </div> </div> </div> <div class="eye eye-right"> <div class="eye-inner"> <div class="pupil"> <div class="light"></div> </div> </div> </div> </div> </div>/*第二只青蛙脸颊两边的红晕样式*/.icon .frog .body .blush {width: 75px;height: 9px;position: absolute;top: 20px;left: 0;right: 0;margin: auto; }.icon .frog .body .blush:before, .icon .frog .body .blush:after {content: "";display: block;width: 12px;height: 100%;background-color: #F7D2C9;border-radius: 50%; }.icon .frog .body .blush:before {position: absolute;top: 0;left: 0;}.icon .frog .body .blush:after {position: absolute;top: 0;right: 0;}/*第二只青蛙的嘴巴样式,用圆角和阴影的方式制作而成*/.icon .frog .body .big-mouth {width: 30px;height: 20px;border-radius: 0 0 50% 50%;box-shadow: 2px 2px 0px 0px rgba(63, 106, 52, 0.3); } .frog#frog-2 .mouth {background-color: #fff;position: absolute;top: 30px;left: 0;right: 0; }/*第二只青蛙的眼睛样式,将眼圈的背景设置为透明色,圆圈里面的亮光隐藏*/ .frog#frog-2 .eye-inner {top: 17%;background-color: transparent !important; -webkit-animation: hearts 0.6s linear 0s infinite alternate;animation: hearts 0.6s linear 0s infinite alternate; } @-webkit-keyframes hearts {0% { -webkit-transform: scale(0.7); transform: scale(0.7); }100% { -webkit-transform: scale(1); transform: scale(1); } } @keyframes hearts {0% { -webkit-transform: scale(0.7); transform: scale(0.7); }100% { -webkit-transform: scale(1); transform: scale(1); } }/*第二只青蛙的眼睛的爱心样式,左上角和右上角设置交圆角50%,然后左右对应的旋转45度合并成一个爱心的形状*/ .frog#frog-2 .eye-inner:before, .frog#frog-2 .eye-inner:after {content: "";display: block; height: 70%;width: 40%;background-color: #C71F1C;border-radius: 50% 50% 0 0; } .frog#frog-2 .eye-inner:before {position: absolute;top: 0;left: 5px; -webkit-transform: rotate(-45deg);transform: rotate(-45deg); } .frog#frog-2 .eye-inner:after {position: absolute;top: 0;right: 5px; -webkit-transform: rotate(45deg);transform: rotate(45deg); } .frog#frog-2 .eye-inner .pupil {display: none;}
The above is the detailed content of Create a cute frog expression using html. For more information, please follow other related articles on the PHP Chinese website!