Some practical examples of CSS

Source: Internet
Author: User

// The position where the dynamic control element appears on the page combined with the script language.

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> css11.html </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  6. <Style type = "text/CSS">
  7. <! --
  8. Div. Show {
  9. Position: absolute;
  10. Top: 10;
  11. Left: 200;
  12. Visibility: visible;
  13. }
  14. Div. Hide {
  15. Position: absolute;
  16. Top: 120;
  17. Left: 200;
  18. Visibility: hidden;
  19. }
  20. -->
  21. </Style>
  22. </Head>
  23. <Body>
  24. <Div class = "hide"> // No
  25. </Div>
  26. <Div class = "show">
  27. </Div>
  28. </Body>
  29. </Html>

[Note] the DIV block tag can take the image and text inside it as a whole and control it in layers. This tag can often achieve partial changes to the page effect.

# The cursor attribute in CSS changes the shape of the mouse pointer.

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> css12.html </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  6. <Style type = "text/CSS">
  7. <! --
  8. . Hand {cursor: hand;}/* hand shape * // = "Class Attribute Value
  9. . Crosshair {cursor: crosshair;}/* precisely locate the word "+ */
  10. . Move {cursor: move;}/* move */
  11. . E-resize {cursor: E-resize;}/* the arrow toward the right */
  12. . Ne-resize {cursor: NE-resize;}/* arrow toward top right */
  13. . NW-resize {cursor: NW-resize;}/* the arrow toward the top left */
  14. . N-resize {cursor: N-resize;}/* the arrow toward the top */
  15. . Se-resize {cursor: Se-resize;}/* arrow toward bottom right */
  16. . S-resize {cursor: S-resize;}/* the arrow toward the bottom */
  17. . W-resize {cursor: W-resize;}/* arrow toward left */
  18. . Text {cursor: text;}/* "I" type */
  19. . Wait {cursor: Wait;}/* wait */
  20. . Help {cursor: help;}/* help */
  21. -->
  22. </Style>
  23. </Head>
  24. <Body>
  25. <P class = "hand">
  26. Give me a hand! (Hand)
  27. </P>
  28. <P class = "crosshair">
  29. Give me a crosshair (precise positioning )!
  30. </P>
  31. <P class = "move">
  32. Give me a move (MOVE )!
  33. </P>
  34. <P class = "e-resize">
  35. Give me a e-resize (arrow to the right )!
  36. </P>
  37. <P class = "Ne-resize">
  38. Give me a ne-resize (arrow toward top right )!
  39. </P>
  40. <P class = "NW-resize">
  41. Give me a NW-resize (the arrow is directed to the top left )!
  42. </P>
  43. <P class = "N-resize">
  44. Give me a n-resize (on )!
  45. </P>
  46. <P class = "Se-resize">
  47. Give me a se-resize (lower left )!
  48. </P>
  49. <P class = "s-resize">
  50. Give me a s-resize (lower )!
  51. </P>
  52. <P class = "w-resize">
  53. Give me a W-resize (left )!
  54. </P>
  55. <P class = "text">
  56. Give me a text )!
  57. </P>
  58. <P class = "wait">
  59. Give me a wait (wait )!
  60. </P>
  61. <P class = "help">
  62. Give me a help )!
  63. </P>
  64. </Body>
  65. </Html>

// ------- Dynamic interaction effect achieved by CSS + JavaScript scripts (set the homepage )-----

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> sethome.html </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  6. <Script language = "JavaScript" type = "text/JavaScript">
  7. Function set ()
  8. {
  9. Sethome. style. Behavior = "URL (# default # homepage )";
  10. Sethome. setHomePage (http://www.google.com );
  11. }
  12. </SCRIPT>
  13. </Head>
  14. <Body>
  15. <Span id = "sethome" onclick = "set ()" style = "cursor: Hand"> <br> set this site as the homepage </span>
  16. </Body>
  17. </Html>

// ----------- Further enrich the mouse effect ------------

Code:
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
  2. <HTML>
  3. <Head>
  4. <Title> movpic.html </title>
  5. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
  6. <Style type = "text/CSS">
  7. <! --
  8. # Topdown {
  9. Position: absolute;
  10. Left: 12;
  11. Top: 222;
  12. }
  13. -->
  14. </Style>
  15. <Script language = "JavaScript" type = "text/JavaScript">
  16. Function move (x, y)
  17. {
  18. Topdown. style. Left = X;
  19. Topdown. style. Top = y;
  20. }
  21. </SCRIPT>
  22. </Head>
  23. <Body onmousemove = "move (event. X, event. Y)">/× event-driven ×/
  24. <Div id = "topdown">/× ID style modifier ×/
  25. /* layer tag Div X/
  26. </Div>
  27. </Body>
  28. </Html>

Explanation: The layer-tagged div is used to separate the image into a layer, and the CSS stacked style sheet is used to define the position of the image. Then, the image is combined with the onmouseover event to track the mouse position (event. X and event. y), and use the mouse position to modify the corresponding image position at any time.

Effect: a smiling face that always moves with the mouse pointer is displayed on the page.

 

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.