10 CSS skills you may not know

Source: Internet
Author: User
Tags border color

1. Simplified CSS font attributes V ~ Xwa &
D = 'lwxc
In general, CSS is used to set the font attributes as follows: 2j6wh? H? %
1 m {&~ Im
Font-weight: bold; 3tbb3l ['l
# NQA + J PP
Font-style: italic; '+ X '~ Oe7
32 24pql &
Font-varient: Small-caps; @ M .! \ N % m
F E9 "8n
Font-size: 1em; E (h) f * ^ LG
+ M; i8-X, 5 @
Line-Height: 1.5em; Se. Ko) L
Edhd' <}!
Font-family: verdana, sans-serif;) Clvrc }&
Z] xjxu {IU"
But you can also write all of them to one line: IV @ 2? (G * $
0g; \ (%
Font: bold italic small-caps 1em/1.5em verdana, sans-serif; : Rfz2d'
! ^ Xhccb
Really good! Only one note: this shorthand method takes effect only when both the font-size and font-family attributes are specified. Also, if you do not set font-weight, font-style, and font-varient, they will use the default value, which should be noted.] K'ohk
Tqs % = B4
2. Use two classes at the same time ZS ^ _ fr
Z = XX # XB],
Generally, only one class can be set for one element, but this does not mean that two classes cannot be used. In fact, you can: ZP {, B
~ 0) drep
<P class = "text side">... </P> QP! WL>
; 4 ^ MCS
At the same time, two classes are given to the P element, with an empty lattice in the middle. In this way, the attributes of all the text and side classes will be added to the P element. If the attributes of the two classes conflict, the subsequent settings take effect, that is, the attributes of the classes placed in the CSS file take effect. > 03 ^-7g
; \ V> .';:
Supplement: for an ID, neither <p id = "text side">... </P> can be written in this way. V0.} e:
-: PV <p '>
3. Default Value of CSS border Y qi3x: d
Y! E # XN
You can usually set the border color, width, and style, such: J7rkblo
EB % BW
Border: 3px solid #000 Kbaru @, c
^ B (Sj * fo
The border is displayed as 3 pixels wide, black, and solid. However, you only need to specify the style here. M $ & QX \
Lvrd: z | V
If only the style is specified, the default value is used for other attributes. Generally, the default width of border is medium, which is generally 3 to 4 pixels. The default color is the text color. If this value is correct, you don't need to set that much.Yulguy, V (
1. axijy
4. CSS for document printing \-V. TTF! -
Ma & | Z] 1 &
Many websites have a printing version, but this is not actually required, because you can use CSS to set the printing style. U1 V1 @
}) T! X; W8
That is to say, you can specify two CSS files for the page, one for screen display and the other for printing: /4zw1:
$ & 'Glq
<Link type = "text/CSS" rel = "stylesheet" href = "stylesheet.css" Media = "screen"/> <link type = "text/CSS" rel = "stylesheet" href = "printstyle.css" Media = "print"/> Ujqojp # I
-0ys $ AP |
1st rows are displayed, and 2nd rows are printed. Pay attention to the media attributes. Ezu? XN
Oby * SZ
But what should I write in printed CSS? You can set it by designing common CSS. At the same time of design, you can set this CSS to display CSS to check its effect. Maybe you will use the "display: none" command to turn off some decorative images and then turn off some navigation buttons. For more information, see "Print differences.X ^ Z! F $ y
7] W * HPT
5. Image replacement skills ^ _ Kt] OP
Qlt9s %? J
Generally, we recommend that you use standard HTML to display text instead of images. This is fast and readable. However, if you want to use some special fonts, you can only use images. O w_t7mi
Gr) LB>
For example, if you want to use the entire selling icon, you can use this image: Z7z) (d ^;
?>. K xfg
= Vtjls 'zf
This is certainly acceptable, but for search engines, they are less interested in replacing text in alt than normal text, because many designers put a lot of keywords here to cheat the search engine. The method should be as follows: ; D <8 ^; + T
26% I> * 07
<H1> buy widgets Gj *! [
GMZ | = '*
However, there is no special font. To achieve the same effect, you can design CSS as follows: ; O4v, Ol | SZ
U. N3] $
H1 {Background: url(widget-image.gif) No-Repeat; Height: Image Height text-indent:-2000px} _ S "V] HJP
, GK '? + D (I
Change the Image Height to the actual image height. Here, the image is displayed as a background, and the real text is Indented by setting-2000 pixels. They will appear at 2000 on the left of the screen and will not be seen. However, this may not be visible to anyone who closes the image. "> V [r_x W
I; V-F
6. Another adjustment technique for the CSS Box Model "N2 | D)
9> RH <> NV
The box model is adjusted mainly for IE browser before IE6. They calculate the boundary width and blank space on the element width. For example: <Qbp) 17
/67 hzli
# Box {width: 100px; Border: 5px; padding: 20px} } Z ~;} ]
> <Ikrc
Call it like this: D. '% 73 p
. DBY | C ^ C
<Div id = "box">... </div> % LLF IR
/HS % GB %
At this time, the full width of the box should be 150 points, which is correct in all browsers except IE6. However, in a browser like ie5, its full width is still 100 points. The box adjustment method invented by the predecessors can be used to deal with this difference. SV | n] 9tp *
ZM $> 4 h
However, CSS can achieve the same purpose to make them display the same effect. & "} Hwr'h
~ Kcstr
# Box {width: 150px} # Box Div {border: 5px; padding: 20px}*! V ;*
2amj $ n | NF
Call this method as follows: ? _ + S {
Yi = Ho
<Div id = "box"> <div>... </div> WY % J _ |
Mo] ahuz
In this way, no matter what browser, the width will be 150 points. H2c CW $ A 0
K_qrz? 9e
7. Align block elements in Center [A' 0 +
N = $ WB ^ 6'
If you want to build a fixed-width webpage and make the webpage horizontally centered, it is usually like this: ] P. SVF _
A_y rdo
# Content {width: 700px; margin: 0 auto} > G8sbl |
K1 &; V "6 * y
You will use <Div id = "content"> to enclose all elements. This is very simple, but it is not good enough. This effect will not be displayed in earlier versions of IE6. Change CSS as follows:BWE & 9y '+
X &: Y \ n
Body {text-align: center }# content {text-align: Left; width: 700px; margin: 0 auto} Po: nixy \ 8
8sep | 7A-
This will center the webpage content, so the content is added $ I7h #0
} Xw8v5od \
Text-align: left. | Edtd3lz |
Ug4: NN ??
8. Use CSS to process Vertical Alignment ,} | "\> K <t
DW $ I \ f/J
Vertical alignment can be easily implemented using tables. You can set the table unit vertical-align: Middle. But this is useless for CSS. This attribute is useless if you want to set a navigation bar to 2 em and center the navigation text vertically. $ G} GP9
| E] dwec %
What is the CSS method? By the way, set the Row Height of the text to 2em: Line-Height: 2em. (Y | dtc1 {r
M $ wa] ^
9. Position CSS in the container = B ^ ~ * A8 #9
; IC <fr0fz
One advantage of CSS is that one element can be located at any time in a container. For example, for this container: } [F # x '"
*} ($ "Mr
# Container {position: relative} '-WLPT | gg
Maci & Q
In this way, all elements in the container are relatively located, and can be used as follows: P * xmh QE
H5, 4th
<Div id = "Container"> <Div id = "navigation">... </div> S4sq0cp
PLMA} cw13
If you want to locate at 30 to the left and 5 to the top, you can do this: Riyk;
~ U; QM
# Navigation {position: absolute; left: 30px; top: 5px} J/RD (0 S $
~ # HJ ^ B PVN
Of course, you can also do this: 6p ^ mx1b"
GZ ^ he <& Q
Margin: 5px 0 0 30px <0qt. ^/BQ
E, O: l! +
Note that the order of the four numbers is: Top, right, bottom, left. Of course, sometimes the positioning method is better than the margin method. Eyr + IR>
E % zb' X "Z
10. Background Color directed to the bottom of the screen Wbkx 'u7
I = '> q) 9.
CSS cannot control the vertical direction. If you want to direct the navigation bar to the bottom of the page like the content bar, It is very convenient to use a table, but if you only use this CSS: ~ M) ox} VV _
K/# 4pu <
# Navigation {Background: Blue; width: 150px} E) mxb
F9z_9v_u
A shorter navigation bar will not go straight to the bottom, and it will end when the half-way content ends. What should I do? > {HM ** AV
X \ A/(2 * U2
Unfortunately, you can only use spoofing to add a background image to the shorter column. The width is the same as the column width, and the color is the same as the Set background color. @ Wdh &}
D10 [p [n4j
Body {Background: url(blue-image.gif) 0 0 repeat-y} 2/8nl
N @ $ Ko # + C + W
In this case, EM cannot be used as the unit, because in this case, once the reader changes the font size, this trick will reveal the filling, and only PX can be used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.