源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> <style> .button { background-color: #4CAF50; /* Green */ border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; } .button1 {width: 250px;} .button2 {width: 50%;} .button3 { padding-left: 0; padding-right: 0; width: 100%; } </style> </head> <body> <h2>按鈕寬度</h2> <p>默認情況下,按鈕的大小有按鈕上的文本內容決定( 根據文本內容匹配長度 )。 我們可以使用 width 屬性來設置按鈕的寬度:</p> <p><strong>提示:</strong> 如果要設置固定寬度可以使用像素 (px) 為單位,如果要設置響應式的按鈕可以設置為百分比。</p> <button class="button button1">250px</button><br> <button class="button button2">50%</button><br> <button class="button button3">100%</button> </body> </html>
運行結果