Home > Article > Web Front-end > CSS Card: Making playing cards with pure css_html/css_WEB-ITnose
制作扑克的html代码
第一步是制作扑克的html,我的原则是用最少最简洁的代码,不引用任何图片,也许你认为不可能,但是你还是乖乖的看我是如何工作的吧。
建立一个div,赋予两个class属性:cardand suitdiamonds
.代码
往这个div中添加卡片的内容,只需要一个包含字母A的段落标记
就可以了。
.代码
A
Now always keep in mind that our purpose is not just to make a playing card, but to use it The most concise code, the html part of the code only needs so much (concise enough).
UI front-end framework carefully developed for 5 years!
css code
The first step in css is to specify the basic page properties, which will be inherited by the card.
.code
As shown in the above code, card The style is very simple, with a white background, rounded corners, and border shadow. There is nothing special except that the position attribute is relative.
Now let’s polish up the A letter
.code
.card p {
Let’s take a look at the effect first:
Now it looks like it has the effect of the card, but it always feels like there is still something missing - plum blossoms, Diamonds, hearts, spades. If we want to display these graphics without introducing pictures, things will become more complicated, but we still have tricks to solve the problem. UI front-end framework carefully developed for 5 years!
Considering that we no longer want to add more code to the html part, we introduce pseudo elements before and after to add graphics such as plum squares to the card. Fortunately, most browsers recognize various kinds of special symbols.
.code
.suitdiamonds:before, .suitdiamonds:after {
I use both before and after so that I can Get the upper and lower square shapes, and follow the same pattern as other shapes.
.code
.suitdiamonds:before, .suitdiamonds:after {
If you are a If you are careful, you will notice that the direction of these diamond clubs seems to be reversed. In fact, it is easy to achieve inversion with CSS, but considering that no one will turn the screen upside down to look at this playing card, this is unnecessary.
我们画好了扑克的符号,还应该修饰大小和合适的定位。方块、梅花、红桃黑桃的字体大小位置摆放以及position属性都是一致的,因此我们最好只写一次。div[class*='suit']选择器就可以同时选择这四个。(原文的评论里面有人建议单独用一个class来定义,因为作者的这个方法效率上讲要低一些) 精心开发5年的UI前端框架!
.代码
下面看看效果
上面我们只是制作了一张图片,现在我想制作一组图片的效果:
.代码
A
A
A
A
css 精心开发5年的UI前端框架!
.代码
接下来我想利用css做出一些有趣的动画效果来:开始的时候只显示一张扑克,当鼠标移上去,扑克会展开,就像你打牌的时候手里握牌的样子。
html
和之前不同的是我增加了spread class属性
.代码
A
A
A
A
css
.代码
鼠标移上去的效果:
.代码
再加上点阴影效果 精心开发5年的UI前端框架!
.代码