CSS Card: making cards with pure css
Html code for making poker
The first step is to make the html of poker. My principle is to use the least concise code without referencing any image. Maybe you think it is impossible, but you can still see how I work.
Create a div and assign two class attributes: cardand suitdiamonds.
. Code
-
-
Add the card content to this div. You only need A paragraph mark containing the letter.
You can.
. Code
-
-
A
-
Now remember in your mind that our goal is not only to make a playing card, but also to use the simplest code, you only need so much html code (concise enough ).
Well-developed 5-year UI front-end framework!
Css code
The first step of css is to define basic page attributes, which will becard
Inheritance.
. Code
- * {Margin: 0; padding: 0 ;}
-
- Body {
- Background: #00a651;
- }
-
- . Card {
- Position: relative;
- Float: left;
- Margin-right: 10px;
- Width: 150px;
- Height: 220px;
- Border-radius: 10px;
- Background: # fff;
- -Webkit-box-shadow: 3px 3px 7px rgba (0,0, 0, 0.3 );
- Box-shadow: 3px 3px 7px rgba (0, 0, 0, 0.3 );
- }
As shown in the code above, the card style is very simple, with a white background, rounded corner, and border shadow,position
There is nothing special except relative.
Now let's polish the letter.
. Code
- . Card p {
- Text-align: center;
- Font: 100px/220px Georgia, Times New Roman, serif;
- }
First look at the effect:
Now it seems that there is no card effect, but there is always something missing-plum blossom, square, red peach, and black peach. If we want to display these images without introducing them, things will become complicated, but we still have the problem-solving skills. Well-developed 5-year UI front-end framework!
Considering that we no longer want to add more code to the html part, we introduce the pseudo elements before and after to add the plum blossom blocks to the card. Fortunately, the vast majority of browsers can recognize various types of special symbols.
. Code
- . Suitdiamonds: before,. suitdiamonds: after {
- Content :"? ";
- Color: # ff0000;
- }
I use before and after at the same time, so that I can get the upper and lower squares, and the other figures are based on the gourd painting.
. Code
- . Suitdiamonds: before,. suitdiamonds: after {
- Content :"? ";
- Color: # ff0000;
- }
-
- . Suithearts: before,. suithearts: after {
- Content :"? ";
- Color: # ff0000;
- }
-
- . Suitclubs: before,. suitclubs: after {
- Content :"? ";
- Color: #000;
- }
-
- . Suitspades: before,. suitspades: after {
- Content :"? ";
- Color: #000;
- }
If you are a careful person, you should have discovered that the direction of these squares seems to be reversed. In fact, it is easy to Implement css inversion, but it is not necessary to consider that no one will reverse the screen to watch this playing card.
We have drawn the symbols of poker, and we should also modify the size and proper positioning. The font size and position of square, plum blossom, and peach are consistent, so we 'd better write it only once.div[class*=
'suit'
]
You can select the four selector at the same time. (In the comments in the original article, someone suggested using a class to define it separately, because the efficiency of the method described by the author is lower.) carefully developed the UI front-end framework for five years!
. Code
- Div [class * = 'suit']: before {
- Position: absolute;
- Font-size: 35px;
- Left: 5px;
- Top: 5px;
- }
-
- Div [class * = 'suit']: after {
- Position: absolute;
- Font-size: 35px;
- Right: 5px;
- Bottom: 5px;
- }
Next let's take a look at the effect
We just made an image above. Now I want to make a group of images:
. Code
-
-
-
-
A
-
-
-
-
A
-
-
-
-
A
-
-
-
-
A
-
-
-
A 5-year UI front-end framework developed by css!
. Code
- . Hand {
- Margin: 50px;
- }
-
- /* For modern browsers */
- . Hand: before,
- . Hand: after {
- Content :"";
- Display: table;
- }
-
- . Hand: after {
- Clear: both;
- }
-
- /* For IE 6/7 (trigger hasLayout )*/
- . Hand {
- Zoom: 1;
- }
-
- . Card: hover {
- Cursor: pointer;
- }
Next, I want to use css to make some interesting animated effects: At the beginning, only one poker player is displayed. When the mouse moves up, poker will show up, it's like holding a card in your hand when you play a card.
Html
The difference is that I added the spread class attribute.
. Code
-
-
-
-
A
-
-
-
-
A
-
-
-
-
A
-
-
-
-
A
-
-
- Well-developed 5-year UI front-end framework!
Css
. Code
- . Spread {
- Width: 350px;
- Height: 250px;
- Position: relative;
- }
-
- . Spread>. card {
- Position: absolute;
- Top: 0;
- Left: 0;
- -Webkit-transition: top 0.3 s records, left 0.3 s records;
- -Moz-transition: top 0.3 s records, left 0.3 s records;
- -O-transition: top 0.3 s records, left 0.3 s records;
- -Ms-transition: top 0.3 s records, left 0.3 s records;
- Transition: top 0.3 s records, left 0.3 s records;
- }
The effect of moving the mouse up:
. Code
- . Spread: hover. suitdiamonds {
- -Webkit-transform: rotate (-10deg );
- -Moz-transform: rotate (-10deg );
- -O-transform: rotate (-10deg );
- -Ms-transform: rotate (-10deg );
- Transform: rotate (-10deg );
- }
-
- . Spread: hover. suithearts {
- Left: 30px;
- Top: 0px;
- -Webkit-transform: rotate (0deg );
- -Moz-transform: rotate (0deg );
- -O-transform: rotate (0deg );
- -Ms-transform: rotate (0deg );
- Transform: rotate (0deg );
- }
-
- . Spread: hover. suitclubs {
- Left: 60px;
- Top: 5px;
- -Webkit-transform: rotate (10deg );
- -Moz-transform: rotate (10deg );
- -O-transform: rotate (10deg );
- -Ms-transform: rotate (10deg );
- Transform: rotate (10deg );
- }
-
- . Spread: hover. suitspades {
- Left: 80px;
- Top: 10px;
- -Webkit-transform: rotate (20deg );
- -Moz-transform: rotate (20deg );
- -O-transform: rotate (20deg );
- -Ms-transform: rotate (20deg );
- Transform: rotate (20deg );
- }
In addition, a five-year UI front-end framework has been developed with a shadow effect!
. Code
- . Spread>. card: hover {
- -Webkit-box-shadow: 1px 1px 7px rgba (0.4, 0 );
- Box-shadow: 1px 1px 7px rgba (0, 0, 0, 0.4 );
- }