搜索
首页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 it is used to reveal some offer or exciting content 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等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。