搜尋
首頁web前端css教學如何使用 HTML 和 CSS 為按鈕建立文字顯示效果?

How to Create Text Reveal Effect for Buttons using HTML and CSS?

在本文中,我們將討論使用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中文網其他相關文章!

陳述
本文轉載於:tutorialspoint。如有侵權,請聯絡admin@php.cn刪除
這麼多顏色鏈接這麼多顏色鏈接Apr 13, 2025 am 11:36 AM

最近有一系列有關顏色的工具,文章和資源。請允許我通過將它們四捨五之後關閉幾個標籤,以供您享受。

自動利潤在Flexbox中的工作方式自動利潤在Flexbox中的工作方式Apr 13, 2025 am 11:35 AM

羅賓以前已經介紹過這一點,但是我在過去的幾周里聽到了一些關於它的困惑,看到另一個人在解釋它,我想

移動彩虹移動彩虹Apr 13, 2025 am 11:27 AM

我絕對喜歡三明治網站的設計。在許多美麗的功能中,這些標題是滾動時帶有彩虹的下線。它不是

新年,新工作?讓我們做一個網格驅動的簡歷!新年,新工作?讓我們做一個網格驅動的簡歷!Apr 13, 2025 am 11:26 AM

許多流行的簡歷設計通過以網格形狀鋪設部分來充分利用可用的頁面空間。讓我們使用CSS網格創建一個佈局

將用戶擺脫過多習慣的一種方法將用戶擺脫過多習慣的一種方法Apr 13, 2025 am 11:25 AM

頁面重新加載是一回事。有時,當我們認為它沒有響應或認為新內容可用時,我們會刷新頁面。有時我們只是生氣

域驅動的設計與React域驅動的設計與ReactApr 13, 2025 am 11:22 AM

關於如何在React世界中組織前端應用的指導很少。 (只需移動文件,直到“感覺正確”,大聲笑)。真相

檢測非活動用戶檢測非活動用戶Apr 13, 2025 am 11:08 AM

大多數情況下,您並不真正在乎用戶是否積極參與或暫時非活動。不活躍,意思,也許他們

Wufoo ZapierWufoo ZapierApr 13, 2025 am 11:02 AM

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

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

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

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SecLists

SecLists

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