Home  >  Article  >  Web Front-end  >  The principle and implementation of writing pure CSS pop-up menu By shawl.qiu_Experience exchange

The principle and implementation of writing pure CSS pop-up menu By shawl.qiu_Experience exchange

WBOY
WBOYOriginal
2016-05-16 12:08:465156browse

The principle and implementation of writing pure CSS pop-up menu By shawl.qiu


Abstract:
This article introduces the use of CSS to write multi-style pop-up menus suitable for Opera, Firefox, and IE
## #Description:
The key point of writing a CSS pop-up menu is to display the hidden label when the mouse moves over the target.
The label to be hidden is hidden using the display:none; attribute.
Trigger display Hidden tags mainly use the :hover attribute, and use display:block; to display hidden tags.

But because browsers do not support CSS consistently.
For Opera or Firefox, we can write a pure CSS menu , they support the :hover attribute of any tag.
For IE browser, :hover only works on the a tag, but we can use the script's onmouseover, onmouseout to simulate the :hover attribute of other tags.
Therefore Writing a CSS pop-up menu suitable for IE requires the use of a few scripts.

Directory:
1. Writing a CSS pop-up menu on the right side of the vertical row.
1.1 Really based on Opera, Firefox pure CSS Pop-up menu
1.2 Compatible with IE, Opera, Firefox CSS pop-up menu (script implementation)

2. Write a horizontal bottom pop-up CSS menu.
2.1 Real pure CSS pop-up based on Opera, Firefox Menu
2.2 Compatible with IE, Opera, Firefox CSS pop-up menu (script implementation)

3. Conclusion

4. Preview

shawl.qiu
2006 -10-01

http://blog.csdn.net/btbtd
1. Write a CSS menu that pops up on the right side of the vertical row.

1.1 True Based on Opera, Firefox pure CSS popup menu

    linenum "
  1. http://www.w3.org/TR/html4/loose.dtd">
  2. Untitled Document
  3.     
  4.         level
  •         
  •             level_ title
  •             level_ title 1
  •             level_ title 2
  •             level_ title 3
  •             level_ title 4
  •             level_ title 5
  •         
  •     
  •     
  •         level 1
  •         
  •             level_ title
  •             level_ title 1
  •             level_ title 2
  •             level_ title 3
  •             level_ title 4
  •             level_ title 5
  •         
  •     
  •     
  •         level 2
  •         
  •             level_ title
  •             level_ title 1
  •             level_ title 2
  •             level_ title 3
  •             level_ title 4
  •             level_ title 5
  •         
  •     
  •     
  •         level 3
  •         
  •             level_ title
  •             level_ title 1
  •             level_ title 2
  •             level_ title 3
  •             level_ title 4
  •             level_ title 5
  •         
  •     
  •     
  •         level 4
  •         
  •             level_ title
  •             level_ title 1
  •             level_ title 2
  •             level_ title 3
  •             level_ title 4
  •             level_ title 5
  •         
  •     

  • 1.2 兼容 IE, Opera, Firefox 的 CSS 弹出菜单(脚本实现)
      linenum
    1. " http://www.w3.org/TR/html4/loose.dtd">
    2. Untitled Document
    3.     
    4.         level
    5.         
    6.             level_ title
    7.             level_ title 1
    8.             level_ title 2
    9.             level_ title 3
    10.             level_ title 4
    11.             level_ title 5
    12.         
    13.     
    14.     
    15.         level 1
    16.         
    17.             level_ title
    18.             level_ title 1
    19.             level_ title 2
    20.             level_ title 3
    21.             level_ title 4
    22.             level_ title 5
    23.         
    24.     
    25.     
    26.         level 2
    27.         
    28.             level_ title
    29.             level_ title 1
    30.             level_ title 2
    31.             level_ title 3
    32.             level_ title 4
    33.             level_ title 5
    34.         
    35.     
    36.     
    37.         level 3
    38.         
    39.             level_ title
    40.             level_ title 1
    41.             level_ title 2
    42.             level_ title 3
    43.             level_ title 4
    44.             level_ title 5
    45.         
    46.     
    47.     
    48.         level 4
    49.         
    50.             level_ title
    51.             level_ title 1
    52.             level_ title 2
    53.             level_ title 3
    54.             level_ title 4
    55.             level_ title 5
    56.         
    57.     

    2. 编写横排底部弹出的 CSS 菜单. 

    2.1 真正的基于 Opera, Firefox 纯 CSS 弹出菜单
      linenum
    1. http://www.w3.org/TR/html4/loose.dtd">
    2. Untitled Document
    3. /*    body{ margin:0px auto; width:768px; /* 定义页面居中显示,*/}
    4.     *{text-decoration:none!important; /* 定义所有链接不显示下划线 */}
    5.     .pmHorizontalBottomOut{background-color:#fff!important; /* 定义主菜单域背景色 */} 
    6.     .pmHorizontalBottomOut .level{  /* 定义一级类别属性 */
    7.         width:120px; /* 宽度 */
    8.         height:17; /* 高度 */
    9.         position:relative; /* 显示位置为相对位置 */
    10.         display:block; /* 以块模式显示 */
    11.         background-color:#D8D8D8; /* 背景色 */
    12.         padding:0px 2px; /* 文字内补丁间隔 */
    13.         margin:0px 1px 0px 0px; /* 菜单外补丁间隔 */
    14.         float:left;
    15.     }
    16. .pmHorizontalBottomOut .level:hover { /* When the mouse moves over the first-level menu */
    17. background-color:#6633FF; /* background color */
    18. color:#FFFFFF; /* text color */
    19. }
    20. .pmHorizontalBottomOut .level_{display:none; /* Second-level categories are hidden by default */}
    21. .pmHorizontalBottomOut .level:hover .level_ { /* Trigger the display of the secondary category when the mouse moves over it */
    22.        display:block; /* Display in blocks */
    23. width:124px; /* Width */
    24. height:auto; /* height */
    25. margin:0px -2px 0px -2px; /* External patch */
    26. background-color:#EFEFEF; /* Define background color */
    27. Position:absolute; /* Position is absolute position */
    28. }
    29. .pmHorizontalBottomOut .level:hover .level_ .level_title {
    30. /* Define the secondary category title style */
    31. font-weight:bold; /* Font bold */
    32. background-color:#A7ADFE; /* background color */
    33. color:white; /* text color */
    34. }
    35. .pmHorizontalBottomOut .level:hover .level_ a:hover {
    36. /* Define the display style of secondary category links */
    37. background-color:#F83658; /* background color */
    38. color:white; /* text color */
    39. }
    40. .pmHorizontalBottomOut .level_ * {
    41.                                                                                                /* Define the common attributes of all second-level categories */
    42.        display:block; /* Display in blocks */
    43. color:black; /* text color */
    44. padding:0px 2px; /* inner patch interval */
    45. }
    46. /*]]>*/
    47.     
    48.         
      level
    49.         
    50.             
      level_ title
    51.             level_ title 1
    52.             level_ title 2
    53.             level_ title 3
    54.             level_ title 4
    55.             level_ title 5
    56.         
    57.     
    58.     
    59.         
      level 1
    60.         
    61.             
      level_ title
    62.             level_ title 1
    63.             level_ title 2
    64.             level_ title 3
    65.             level_ title 4
    66.             level_ title 5
    67.         
    68.     
    69.     
    70.         
      level 2
    71.         
    72.             level_ title
    73.             level_ title 1
    74.             level_ title 2
    75.             level_ title 3
    76.             level_ title 4
    77.             level_ title 5
    78.         
    79.     
    80.     
    81.         level 3
    82.         
    83.             level_ title
    84.             level_ title 1
    85.             level_ title 2
    86.             level_ title 3
    87.             level_ title 4
    88.             level_ title 5
    89.         
    90.     
    91.     
    92.         level 4
    93.         
    94.             level_ title
    95.             level_ title 1
    96.             level_ title 2
    97.             level_ title 3
    98.             level_ title 4
    99.             level_ title 5
    100.         
    101.     

    2.2 兼容 IE, Opera, Firefox 的 CSS 弹出菜单(脚本实现)
      linenum
    1. " http://www.w3.org/TR/html4/loose.dtd">
    2. Untitled Document
    3. /*    body{ margin:0px auto; width:768px; /* 定义页面居中显示,*/}
    4.     *{text-decoration:none!important; /* 定义所有链接不显示下划线 */}
    5.     /* ------------------- start 针对 Opera, Firefox 的 CSS 弹出菜单 -------------------*/
    6.     .pmHorizontalBottomOut{background-color:#fff!important; /* 定义主菜单域背景色 */} 
    7.     .pmHorizontalBottomOut .level{  /* 定义一级类别属性 */
    8.         width:120px; /* 宽度 */
    9.         height:17; /* 高度 */
    10.         position:relative; /* 显示位置为相对位置 */
    11.         display:block; /* 以块模式显示 */
    12.         background-color:#D8D8D8; /* 背景色 */
    13.         padding:0px 2px; /* 文字内补丁间隔 */
    14.         margin:0px 1px 0px 0px; /* 菜单外补丁间隔 */
    15.         float:left;
    16.     }
    17. .pmHorizontalBottomOut .level:hover { /* When the mouse moves over the first-level menu */
    18. background-color:#6633FF; /* background color */
    19. color:#FFFFFF; /* text color */
    20. }
    21. .pmHorizontalBottomOut .level_{display:none; /* Second-level categories are hidden by default */}
    22. .pmHorizontalBottomOut .level:hover .level_ { /* Trigger the display of the secondary category when the mouse moves over it */
    23.        display:block; /* Display in blocks */
    24. width:124px; /* Width */
    25. height:auto; /* height */
    26. margin:0px -2px 0px -2px; /* External patch */
    27. background-color:#EFEFEF; /* Define background color */
    28. Position:absolute; /* Position is absolute position */
    29. }
    30. .pmHorizontalBottomOut .level:hover .level_ .level_title {
    31. /* Define the secondary category title style */
    32. font-weight:bold; /* Font bold */
    33. background-color:#A7ADFE; /* background color */
    34. color:white; /* text color */
    35. }
    36. .pmHorizontalBottomOut .level:hover .level_ a:hover {
    37. /* Define the display style of secondary category links */
    38. background-color:#F83658; /* background color */
    39. color:white; /* text color */
    40. }
    41. .pmHorizontalBottomOut .level_ * {
    42.                                                                                                /* Define the common attributes of all second-level categories */
    43.        display:block; /* Display in blocks */
    44. color:black; /* text color */
    45. padding:0px 2px; /* inner patch interval */
    46. }
    47. /* ------------------- end CSS pop-up menu for Opera, Firefox ------------------ --*/
    48. /* ------------------- start CSS pop-up menu for IE ------------------- */
    49. .levelIe{ /* Define first-level category attributes */
    50. width:120px; /* Width */
    51. Height:17; /* Height */
    52. Position:relative; /* Display position is relative position */
    53.        display:block; /* Display in block mode */
    54. background-color:#D8D8D8; /* background color */
    55. padding:0px 2px; /* patch interval within text */
    56. margin:0px 1px 0px 0px; /* Patch interval outside menu */
    57. float:left;
    58. }
    59. .levelIe { /* When the mouse moves over the first-level menu */
    60. background-color:#6633FF; /* background color */
    61. color:#FFFFFF; /* text color */
    62. }
    63. .levelIe .level_ { /* Trigger the display of secondary categories when the mouse moves over */
    64.        display:block; /* Display in blocks */
    65. width:124px; /* Width */
    66. height:auto; /* height */
    67. margin:0px -2px 0px -2px; /* External patch */
    68. background-color:#EFEFEF; /* Define background color */
    69. Position:absolute; /* Position is absolute position */
    70. }
    71. .levelIe .level_ .level_title {
    72. /* Define the secondary category title style */
    73. font-weight:bold; /* Font bold */
    74. background-color:#A7ADFE; /* background color */
    75. color:white; /* text color */
    76. }
    77. .levelIe .level_ a:hover {
    78. /* Define the display style of secondary category links */
    79. background-color:#F83658; /* background color */
    80. color:white; /* text color */
    81. }
    82. .levelIe .level_ * {
    83.                                                                                                /* Define the common attributes of all second-level categories */
    84.        display:block; /* Display in blocks */
    85. color:black; /* text color */
    86. padding:0px 2px; /* inner patch interval */
    87. }
    88. /* ------------------- end CSS pop-up menu for IE ------------------- */
    89. /*]]>*/
    90.     
    91.         level
    92.         
    93.             level_ title
    94.             level_ title 1
    95.             level_ title 2
    96.             level_ title 3
    97.             level_ title 4
    98.             level_ title 5
    99.         
    100.     
    101.     
    102.         level 1
    103.         
    104.             level_ title
    105.             level_ title 1
    106.             level_ title 2
    107.             level_ title 3
    108.             level_ title 4
    109.             level_ title 5
    110.         
    111.     
    112.     
    113.         level 2
    114.         
    115.             level_ title
    116.             level_ title 1
    117.             level_ title 2
    118.             level_ title 3
    119.             level_ title 4
    120.             level_ title 5
    121.         
    122.     
    123.     
    124.         level 3
    125.         
    126.             level_ title
    127.             level_ title 1
    128.             level_ title 2
    129.             level_ title 3
    130.             level_ title 4
    131.             level_ title 5
    132.         
    133.     
    134.     
    135.         level 4
    136.         
    137.             level_ title
    138.             level_ title 1
    139.             level_ title 2
    140.               level_ title 3
    141. level_ title 4
    142. level_ title 5


    3. Conclusion
    As can be seen from the above example, if a usable CSS pop-up menu example has been written, then the pop-up position must be written in other If you have local CSS pop-up menu, you only need to modify it slightly.

    4. Preview

    4.1 1.2 Preview of CSS pop-up menu (script implementation) compatible with IE, Opera, and Firefox# ##
    /**/
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Previous article:Lesson02_05 Header Element_Basic TutorialNext article:Lesson02_05 Header Element_Basic Tutorial

    Related articles

    See more