Comments: Recently I have re-designed my blog site and decided to display the time with a calendar icon. In the past, the solution generally used background images. Thanks to css3. Now we can use css3 to implement this function. Next we will introduce you in detail how to redesign my blog site, determines the display time of an icon in a calendar style. In the past, the solution generally used background images. Thanks to css3. Now we can use css3 to implement this function. I will use some linear-gradients, border radius and box shadow attributes to replace the previous photoshop design.
Photoshop concept Diagram
Many designers adopt a direct design method on the browser, but I prefer the concept map method of photoshop first. Although many effects can be directly implemented using css, it is much easier to design effects using photoshop than to constantly try to modify css to achieve the desired effect.
First, create a rounded rectangle and set the radius of the rounded corner to 10px. Then, use the border-radius attribute of css.
Add a vertical gradient to the rectangle. The gradient color ranges from # dad8d8 to # fcfcfc.
Set the stroke of 1 pixel. The color is # e3e3e3
Add the shadow effect to the bottom. The transparency is 20%, the distance from 0 pixels and the size of 15 pixels. These effects will be implemented using the box-shadow attribute in css.
Copy the rectangle and remove the above part. Modify the gradient. The color ranges from #790909 to # d40000. Fill in the newly created rectangle. This part will contain the month information.
Set an inner shadow to indicate the upper border. The color is # a13838, 100% transparency, 3px distance, and 0px size.
Use photoshop's font tool to set the font effect of the last part of the calendar icon. The font is Helvetica and the color is # 9e9e9e.
Enter the month information in the red section below. The font is set to width and the color is white.
The photoshop model is complete. In the past, we would extract the image as the background and write html numbers on it, but now all these can be implemented using css.
HTML Structure
<Div class = "date">
<P> 25 <span> May </span> </p>
</Div>
The html of the ICON demo at this time is very simple. We use the div with the class 'date' as the container, and then use a p label to represent the date number. The day and month are represented by characters of different sizes in our design, so we treat different elements differently using the <span> label.
Css style
The Code is as follows:
. Date {
Width: 130px; height: 160px;
Background: # fcfcfc;
Background: linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
Background:-moz-linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
Background:-webkit-linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
}
Css style first sets the height and width of the entire container. gradient of css can easily achieve the gradient effect.
The Code is as follows:
. Date {
Width: 130px; height: 160px;
Background: # fcfcfc;
Background: linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
Background:-moz-linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
Background:-webkit-linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
Border: 1px solid # d2d2d2;
Border-radius: 10px;
-Moz-border-radius: 10px;
-Webkit-border-radius: 10px;
}
You can use the border attribute to achieve the effect of a 1px border in photoshop, and then use the border-radius to achieve the effect of rounded corners. Do not forget to add the-moz-and-webkit-prefixes to achieve compatibility with older browsers.
The Code is as follows:
. Date {
Width: 130px; height: 160px;
Background: # fcfcfc;
Background: linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
Background:-moz-linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
Background:-webkit-linear-gradient (top, # fcfcfc 0%, # dad8d8 100% );
Border: 1px solid # d2d2d2;
Border-radius: 10px;
-Moz-border-radius: 10px;
-Webkit-border-radius: 10px;
Box-shadow: 0px 0px 15px rgba (0.1, 0 );
-Moz-box-shadow: 0px 0px 15px rgba (0.1, 0 );
-Webkit-box-shadow: 0px 0px 15px rgba (0.1, 0 );
}
The last part of the code implements the shadow effect in photoshop design through box-shadow. Add the horizontal and vertical offset of 0px to increase the Blur degree of 15px. Use rgba to control transparency. In photoshop design, 105 is changed to 0.1.
The Code is as follows:
. Date p {
Font-family: Helvetica, sans-serif;
Font-size: 100px; text-align: center; color: # 9e9e9e;
}
We use the p label to define a style to define a text style for a date. The font, text size, and text color are all copied from photoshop, and the text-align is set to center. However, the style also affects the month text. Next we will define the span label style for it separately.
The Code is as follows:
. Date p span {
Background: # d10000;
Background: linear-gradient (top, # d10000 0%, #7a0909 100% );
Background:-moz-linear-gradient (top, # d10000 0%, #7a0909 100% );
Background:-webkit-linear-gradient (top, # d10000 0%, #7a0909 100% );
}
The red part is implemented by setting the linear-gradient attribute for the span background. The red value also comes from photoshop.
The Code is as follows:
. Date p span {
Background: # d10000;
Background: linear-gradient (top, # d10000 0%, #7a0909 100% );
Background:-moz-linear-gradient (top, # d10000 0%, #7a0909 100% );
Background:-webkit-linear-gradient (top, # d10000 0%, #7a0909 100% );
Font-size: 45px; font-weight: bold; color: # fff; text-transform: uppercase;
Display: block;
}
Modify the text style to match the design. Set the size to 45px, bold, and white. Use text-transform to convert the text in uppercase. Set the span label as a block element so that it matches the container size and sets the red background.
The Code is as follows:
. Date p span {
Background: # d10000;
Background: linear-gradient (top, # d10000 0%, #7a0909 100% );
Background:-moz-linear-gradient (top, # d10000 0%, #7a0909 100% );
Background:-webkit-linear-gradient (top, # d10000 0%, #7a0909 100% );
Font-size: 45px; font-weight: bold; color: # fff; text-transform: uppercase;
Display: block;
Border-top: 3px solid # a13838;
Border-radius: 0 0 10px 10px;
-Moz-border-radius: 0 0 10px 10px;
-Webkit-border-radius: 0 0 10px 10px;
Padding: 6px 0 6px 0;
}
The rest is to add the header border and implement it with the border-top style, and use the border-radius attribute to implement the lower two rounded corners. A little bit of padding can separate the text of a month from other elements.
Browser compatibility
Although css improved attributes can help us achieve gradient and shadow effects in photoshop, we still have to face the problems that web designers have to face before, browser compatibility.