在 html 中创建一个简单的工具提示按钮-ag捕鱼王app官网

在 html 中创建一个简单的工具提示按钮

作者:迹忆客 最近更新:2023/05/05 浏览次数:

超文本标记语言,也称为 html,是一种用于创建网页的标准标记语言。 web 浏览器关于如何在网页上显示文本、图片和其他多媒体的命令由 html 元素提供。


html 中的工具提示

在 html 中,工具提示用于提供有关所选元素的更多信息; 它可能是一个按钮或一个词。 当用户使用工具提示将鼠标移到某个元素上以显示有关该元素的特定信息时,这可以在鼠标悬停效果上完成。

让我们看看如何向按钮添加工具提示。

我们可以通过使用 button 元素的 title 属性向按钮添加工具提示。 在title属性的逗号内输入详细信息,希望在用户移动鼠标时显示。

<button title="click here"> button button>

使用 html 的按钮的基本工具提示

在 html 中创建一个按钮。 然后,将 title 属性添加到按钮元素。

示例代码如下。

html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>tooltiptitle>
    head>
    <body>
        
            <button title="click here">buttonbutton>
    body>
html>

如您所见,当鼠标移到按钮上时,会出现工具提示。


使用 html 和 ccs 的按钮高级工具提示

让我们看看按钮的其他高级工具提示示例。

首先,使用容器元素 (

) 创建一个按钮并添加一个工具提示类。 此
将在用户将鼠标悬停在其上时显示工具提示文本。

带有 class="tooltiptext" 样式内联元素用于包含工具提示文本。

html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
        <title>tooltiptitle>
    head>
    <body>
        
        <div class="tooltip">
            <button class="button">button
                <span class="tooltiptext"> click me span>
            button>
        div>
    body>
html>

创建一个 css 文件

让我们创建一个名为 style.css 的 css 文件,并通过在 html 的 标记之间包含以下语法将其链接到 html 文件。

<link rel="stylesheet" href="style.css">

让我们使用 css 为工具提示按钮设置样式。 按钮的样式包含在 .button 类中。

/* style for button*/
.button {
    position: relative;
    background: #151a5f;
    padding: 10px;
    border-radius: 4px;
    border: none;
    text-transform: uppercase;
    font-weight: bold;
    color: white;
 }

.tooltip 类用于显示工具提示的位置。

.tooltip {
    position: relative;
    display: inline-block;
}

工具提示文本存储在 .tooltiptext 类中。 它通常是隐藏的,但当您将鼠标悬停在它上面时会变得可见。

此外,我们为其添加了一些基本样式,如下所示。

  1. 120px 宽度
  2. 黄色背景
  3. 白色文字颜色
  4. 使文本居中的能力
  5. 5px 的顶部和底部填充

由于 css border-radius 特性,工具提示文本具有圆角边缘。

当用户将光标拖到带有类工具提示的

元素上时,将使用悬停选择器显示工具提示文本。
  /* tooltip text */
.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: rgb(235, 182, 38);
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;
    /* position the tooltip text */
    position: absolute;
    z-index: 1;
}
  /* when you mouse over the tooltip container, the tooltip text is displayed. */
.tooltip:hover .tooltiptext {
    visibility: visible;
}
html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
        <title>tooltiptitle>
    head>
    <body>
        
        <div class="tooltip">
            <button class="button">button
                <span class="tooltiptext"> click me span>
            button>
        div>
    body>
html>
/* style for button*/
.button {
    position: relative;
    background: #151a5f;
    padding: 10px;
    border-radius: 4px;
    border: none;
    text-transform: uppercase;
    font-weight: bold;
    color: white;
 }

定位工具提示

工具提示可以显示在按钮的右侧、左侧、底部和顶部。 让我们看看如何去做。

下面的示例显示了如何在左侧或右侧显示工具提示。 top 属性的值为负 5 像素。

该值是通过考虑填充来计算的。 如果您愿意增加填充,请增加 top 属性。

工具提示靠右

.tooltip .tooltiptext {
  /* position the tooltip text */
    position: absolute;
    z-index: 1;
    top: -5px;
    left: 105%;
}
  /* tooltip text */
.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: rgb(235, 182, 38);
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;
    /* position the tooltip text */
    position: absolute;
    z-index: 1;
}
  /* when you mouse over the tooltip container, the tooltip text is displayed. */
.tooltip:hover .tooltiptext {
    visibility: visible;
}
html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
        <title>tooltiptitle>
    head>
    <body>
        
        <div class="tooltip">
            <button class="button">button
                <span class="tooltiptext"> click me span>
            button>
        div>
    body>
html>
/* style for button*/
.button {
    position: relative;
    background: #151a5f;
    padding: 10px;
    border-radius: 4px;
    border: none;
    text-transform: uppercase;
    font-weight: bold;
    color: white;
 }

可以看到,当鼠标向任意方向移动时,工具提示只会出现在右侧。

工具提示靠左

.tooltip .tooltiptext {
  /* position the tooltip text */
    position: absolute;
    z-index: 1;
    top: -5px;
    right: 105%;
}
  /* tooltip text */
.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: rgb(235, 182, 38);
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;
    /* position the tooltip text */
    position: absolute;
    z-index: 1;
}
  /* when you mouse over the tooltip container, the tooltip text is displayed. */
.tooltip:hover .tooltiptext {
    visibility: visible;
}
html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
        <title>tooltiptitle>
    head>
    <body>
        
        <div class="tooltip">
            <button class="button">button
                <span class="tooltiptext"> click me span>
            button>
        div>
    body>
html>
/* style for button*/
.button {
    position: relative;
    background: #151a5f;
    padding: 10px;
    border-radius: 4px;
    border: none;
    text-transform: uppercase;
    font-weight: bold;
    color: white;
    margin-left: 120px;
 }

可以看到,当鼠标向任意方向移动时,工具提示只会出现在左侧。

下面的示例显示了如何在顶部或底部显示工具提示。 margin-left 属性的值为负 60 像素。

该值按工具提示宽度的一半计算 (120/2 = 60)。

工具提示靠顶部

.tooltip .tooltiptext {
     /* position the tooltip text */
  position: absolute;
  z-index: 1;
  width: 120px;
  bottom: 100%;
  left: 50%;
  margin-left: -60px;
}
  /* tooltip text */
.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: rgb(235, 182, 38);
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;
    /* position the tooltip text */
    position: absolute;
    z-index: 1;
}
  /* when you mouse over the tooltip container, the tooltip text is displayed. */
.tooltip:hover .tooltiptext {
    visibility: visible;
}
html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
        <title>tooltiptitle>
    head>
    <body>
        
        <div class="tooltip">
            <button class="button">button
                <span class="tooltiptext"> click me span>
            button>
        div>
    body>
html>
/* style for button*/
.button {
    position: relative;
    background: #151a5f;
    padding: 10px;
    border-radius: 4px;
    border: none;
    text-transform: uppercase;
    font-weight: bold;
    color: white;
    margin-top: 40px;
    margin-left: 120px;
 }

如您所见,当鼠标向任何方向移动时,工具提示仅出现在顶部。

工具提示靠底部

.tooltip .tooltiptext {
 /* position the tooltip text */
  position: absolute;
  z-index: 1;
  width: 120px;
  top: 100%;
  left: 50%;
  margin-left: -60px;
}
  /* tooltip text */
.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: rgb(235, 182, 38);
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;
    /* position the tooltip text */
    position: absolute;
    z-index: 1;
}
  /* when you mouse over the tooltip container, the tooltip text is displayed. */
.tooltip:hover .tooltiptext {
    visibility: visible;
}
html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="style.css">
        <title>tooltiptitle>
    head>
    <body>
        
        <div class="tooltip">
            <button class="button">button
                <span class="tooltiptext"> click me span>
            button>
        div>
    body>
html>
/* style for button*/
.button {
    position: relative;
    background: #151a5f;
    padding: 10px;
    border-radius: 4px;
    border: none;
    text-transform: uppercase;
    font-weight: bold;
    color: white;
    margin-left: 120px;
 }

可以看到,当鼠标向任意方向移动时,工具提示只会出现在底部。


总结

本文讨论了如何使用 html 创建一个简单的工具提示按钮。 然后,我们讨论了使用 html 和 css 创建高级工具提示按钮并在按钮的右侧、左侧、顶部和底部显示工具提示。

上一篇:

下一篇:html 创建可编辑的表格

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

html 中的 role 属性

发布时间:2023/05/06 浏览次数:345 分类:html

本篇文章介绍 html role属性。html中 role 属性介绍,role 属性定义描述语义的 html 元素的角色。

在 html 中打印时分页

发布时间:2023/05/06 浏览次数:677 分类:html

本篇文章介绍如何在打印 html 页面或内容时强制分页。将 page-break-after 属性设置为 always inside @media print to page break in html

在 html 中显示基于 cookie 的图像

发布时间:2023/05/06 浏览次数:181 分类:html

本文介绍如何根据 html 中的 cookies 显示图像。根据 html 中设置的 cookies 显示图像。问题陈述是我们需要根据网页传递的cookie来显示特定的图像。

在 html 中创建下载链接

发布时间:2023/05/06 浏览次数:374 分类:html

本文介绍如何在 html 中创建下载链接。使用 download 属性在 html 中创建下载链接.。我们可以使用 html 锚元素内的下载属性来创建下载链接。

html 中的 ::before 选择器

发布时间:2023/05/06 浏览次数:641 分类:html

本教程介绍 css ::before 伪元素。css ::before 伪元素。 ::before 选择器是一个 css 伪元素,我们可以使用它在一个或多个选定元素之前插入内容。 它默认是内联的。

在 html 中创建一个可滚动的 div

发布时间:2023/05/06 浏览次数:226 分类:html

本篇文章介绍如何使 html div 可滚动。本文将介绍在 html 中使 div 可滚动的方法。 我们将探索垂直和水平滚动,并通过示例查看它们的实现。

html 显示箭头的代码

发布时间:2023/05/06 浏览次数:432 分类:html

一篇关于用于显示箭头的 unicode 字符实体的紧凑文章。本文讨论使用 unicode 字符实体在我们的 html 页面上显示不同的字符。 html 中使用了许多实体,但我们将重点学习表示上、下、左、右的三角

在 html 中启用和禁用复选框

发布时间:2023/05/06 浏览次数:281 分类:html

本篇文章介绍如何启用和禁用 html 中的复选框。html 中的复选框 复选框是一个交互式框,可以切换以表示肯定或否定。 它广泛用于表单和对话框。

html 中的只读复选框

发布时间:2023/05/06 浏览次数:218 分类:html

本篇文章介绍了如何在 html 中制作只读复选框。本文是关于如何使 html 复选框控件成为只读组件的快速破解。 但是,首先,让我们简要介绍一下复选框控件。

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便
网站地图