在本文中,我們將討論使用HTML和CSS建立按鈕測試顯示效果的方法。
Buttons are the most important user interface component for any website. It is very important to design the buttons in a creatively unique way. The text-reveal effect for a button is used when unique way。 for enhancing the user experience.
The approach is to cover the button with a strip of the same dimension as of button and then moving it in any one direction on mouse-hover.
To move forward with the approach mentioned we need to know about two selectors before and hover which will be used for the text reveal effect for the button approach with the css properties.
::before選擇器是CSS偽元素,用於在其他元素的內容之前多次添加相同的內容。這個選擇器與::after選擇器相同。它幫助創建表示所選元素的第一個子元素的偽元素,並通常用於使用content屬性向元素添加裝飾性內容。它的預設值是inline。
文法
以下是before選擇器的語法 -
element ::before{ content: }
:hover選擇器是用於在滑鼠懸停在元素上時對其進行樣式設定的CSS偽類。它可以應用於任何元素,在滑鼠懸停在元素上時選擇該元素。
文法
以下是before選擇器的語法 -
element :hover{ // CSS declarations; }
The following HTML code snippet implements the creation of a simple button using the button tag.
Index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content= "width=device-width, initial-scale=1.0" /> <title>Create Text Reveal Effect for Buttons using HTML and CSS</title> </head> <body> <button>Text Reveal</button> </body> </html>
CSS Code −
#The following are the steps for implementing the CSS code −
Step 1 − Apply some basic styling to the button like adding padding and border-radius to have rounded corners.
Step 2 − Now use the before selector to create a strip of the same dimension to cover the whole button.
Step 3 − Now use the hover selector to move the strip to any one direction as it is moved to the left in the example.
Note − You can move the strip to any direction according to your need. Also, you can use some other properties to tweak the effect according to you.
Index.css
<style> button { position: absolute; top: 50%; left: 50%; font-size: 20px; padding: 15px; } button::before { content: ""; position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background: blue; transition: 0.5s ease-in-out; } button:hover::before { left: -100%; } </style>
Example
的中文翻譯為:範例
完整程式碼 − 它是上述兩個程式碼部分的組合。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Text Reveal Effect for Buttons</title> <style> button { position: absolute; top: 50%; left: 50%; font-size: 20px; padding: 15px; } button::before { content: ""; position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background: blue; transition: 0.5s ease-in-out; } button:hover::before { left: -100%; } </style> </head> <body> <button>Text Reveal</button> </body> </html>#
Supported Browsers − The browsers supported by pointer-events Property are listed below −
- Google Chrome 1.0
- Edge 12.0
- Internet Explorer 11.0
- Firefox 1.5
- Opera 9.0
- Safari 4.0
Note − Opera 4-6 supports with single-colon.(::before).
本文重點介紹如何使用HTML和CSS透過before和CSS選擇器來建立一個文字揭示效果的按鈕。
以上是如何使用 HTML 和 CSS 為按鈕建立文字顯示效果?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Wufoo一直在集成方面非常出色。他們與特定應用程序(例如廣告系列顯示器,MailChimp和Typekit)進行集成,但他們也


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Dreamweaver Mac版
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。