CSS ???? ??
CSS ???? ??
CSS? ???? ???? ?? ??? ? ???? ??? ???? ??? ??????.
?? ???? ??
??? ?? ?? ???? ??? ???? ??? ?????.
Example
<!DOCTYPE html> <html> <head> <title> PHP中文網(wǎng)(php.cn)</title> <meta charset="utf-8"> <style> .dropdown { position: relative; display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgb(83, 251, 185); padding: 12px 16px; } .dropdown:hover .dropdown-content { display: block; } </style> </head> <body> <div class="dropdown"> <span>鼠標移動到我這!</span> <div class="dropdown-content"> <p> PHP中文網(wǎng)(php.cn)</p> <p>ipnx.cn</p> </div> </div> </body> </html>
????? ???? ??? ???
?? ??
HTML ??:
?? HTM ??? ???? ??? ?? ???? ??? ? ? ????. ??
???? ??(?: <div>)? ???? ???? ??? ???? ??? ??? ?? ?????.
<div> ??? ???? ??? ??? ???? CSS? ???? ???? ???? ???? ?????.
CSS ??:
.dropdown ???? position:relative? ???? ???? ??? ??? ???? ??? ??? ??? ????? ?????(position:absolute ??).
.dropdown-content ???? ?? ???? ?????. ????? ??? ??? ???? ??? ??? ??? ?? ?????. ?? ?? ?? 160px? ???? ????. ????? ??? ? ????. ??: ???? ???? ???? ??? ??? ????? ????? ??? 100%? ???? ???(overflow:auto ??? ?? ???? ???? ? ??).
box-shadow ??? ???? ???? ??? "??"?? ??? ????.
:?? ???? ???? ???? ?? ?? ???? ??? ? ???? ??? ???? ? ?????.
???? ??
???? ??? ??? ???? ???? ??? ??? ? ??? ????. ???? ??? ??? ???? ???? ??????.
<!DOCTYPE html> <html> <head> <title>PHP中文網(wǎng)(php.cn)</title> <meta charset="utf-8"> <style> .dropbtn { background-color: #4CAF50; color: white; padding: 16px; font-size: 16px; border: none; cursor: pointer; } .dropdown { position: relative; display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; } .dropdown-content a:hover {background-color: #f1f1f1} .dropdown:hover .dropdown-content { display: block; } .dropdown:hover .dropbtn { background-color: #3e8e41; } </style> </head> <body> <h2>下拉菜單</h2> <p>鼠標移動到按鈕上打開下拉菜單。</p> <div class="dropdown"> <button class="dropbtn">下拉菜單</button> <div class="dropdown-content"> <a href="http://ipnx.cn">PHP中文網(wǎng) 1</a> <a href="http://ipnx.cn">PHP中文網(wǎng) 2</a> <a href="http://ipnx.cn">PHP中文網(wǎng) </a> </div> </div> </body> </html>
????? ???? ??? ???
Drop- ?? ?? ??
Leftfloat:left;
rightfloat:right;
Example
<!DOCTYPE html> <html> <head> <title>PHP中文網(wǎng)(php.cn)</title> <meta charset="utf-8"> <style> .dropbtn { background-color: #4CAF50; color: white; padding: 16px; font-size: 16px; border: none; cursor: pointer; } .dropdown { position: relative; display: inline-block; } .dropdown-content { display: none; position: absolute; right: 0; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; } .dropdown-content a:hover {background-color: #f1f1f1} .dropdown:hover .dropdown-content { display: block; } .dropdown:hover .dropbtn { background-color: #3e8e41; } </style> </head> <body> <h2>下拉內(nèi)容的對齊方式</h2> <p>left 和 right 屬性指定了下拉內(nèi)容是從左到右或從右到左。</p> <div class="dropdown" style="float:left;"> <button class="dropbtn">左</button> <div class="dropdown-content" style="left:0;"> <a href="#">PHP中文網(wǎng) 1</a> <a href="#">PHP中文網(wǎng) 2</a> <a href="#">PHP中文網(wǎng) 3</a> </div> </div> <div class="dropdown" style="float:right;"> <button class="dropbtn">右</button> <div class="dropdown-content"> <a href="#">PHP中文網(wǎng) 1</a> <a href="#">PHP中文網(wǎng) 2</a> <a href="#">PHP中文網(wǎng) 3</a> </div> </div> </body> </html>
????? ???? ??? ???
? ?? ??
? ???? ?? ??? ???? ??? ???? ??? ?????.
<!DOCTYPE html> <html> <head> <title>PHP中文網(wǎng)(php.cn)</title> <meta charset="utf-8"> <style> ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333; } li { float: left; } li a, .dropbtn { display: inline-block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover, .dropdown:hover .dropbtn { background-color: #111; } .dropdown { display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; } .dropdown-content a:hover {background-color: #f1f1f1} .dropdown:hover .dropdown-content { display: block; } </style> </head> <body> <ul> <li><a class="active" href="">主頁</a></li> <li><a href="">新聞</a></li> <div class="dropdown"> <a href="#" class="dropbtn">下拉菜單</a> <div class="dropdown-content"> <a href="#">鏈接 1</a> <a href="#">鏈接 2</a> <a href="#">鏈接 3</a> </div> </div> </ul> <p>鼠標移動到 "下拉菜單" 鏈接先顯示下拉菜單。</p> </body> </html>
????? ???? ??? ???
?
???? ??? ??? ???? ??.
<!DOCTYPE html> <html> <head> <title>PHP中文網(wǎng)(php.cn)</title> <meta charset="utf-8"> <style> .dropdown { position: relative; display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); } .dropdown:hover .dropdown-content { display: block; } .desc { padding: 15px; text-align: center; } </style> </head> <body> <p>移動鼠標到圖片上顯示下拉內(nèi)容。</p> <div class="dropdown"> <img src="https://img.php.cn/upload/course/000/000/006/580837363b987802.jpg" alt="Trolltunga Norway" width="100" height="50"> <div class="dropdown-content"> <img src="https://img.php.cn/upload/course/000/000/006/580837363b987802.jpg" alt="Trolltunga Norway" width="400" height="200"> <div class="desc">PHP中文網(wǎng)(php.cn)</div> </div> </div> </body> </html>
????? ???? ??? ???