|
Post by account_disabled on Jan 25, 2024 4:15:18 GMT -3
Bootstrap附带了大量即用型jQuery驱动的插件。Bootstrap 插件的美妙之处在于,您可以将它们插入项目中,使用data-属性编写适当的标记,然后 JavaScript 会自动启动。无需编写任何 JavaScript 代码。有时您可能想将自己的自定义添加到 Bootstrap 插件以满足您的项目要求。 如果这是你,请继续阅读。我将向您展示一种可以做到这一点的方法。 如何自定义 Bootstrap 插件的外观 您可以通过使用 CSS 来自定义 Bootstrap 插件的外观。另一方面,如果您想修改插件的功能,则需要编写一些 JavaScript 代码。 自定义 Bootstrap CSS 应该在您自己的自定义文件中完成,无论您使用的是 Sass 源代码还是编译版本。 Learn to Code with JavaScript 为了使事情简单且对 CodePen 友好,请从 CDN 中提取预编译的 Bootstrap 包。 这包括样式表…… 从 Codepen 演示中提取的 Bootstrap 插件 CSS 文件。 ...以及 JavaScript 文件。 另外,不要忘记包含jQuery,如果您打算使用下拉菜单,也不要忘记包含 Popper.js: Bootstrap 库及其从 CodePen 演示中提取的依赖项。为了使修改 CSS 代码变得更加容易,Bootstrap 背后的开发人员在样式表顶部的元素内包含了颜色和断点的 CSS 变量列表。 例 WhatsApp 号码数据 如,绿色成功颜色的变量是--success: #28a745; 要将其更改为不同的绿色阴影,请在您自己的样式表中替换变量的颜色值,并将此代码添加到您选择的选择器中: 要更改特定插件的外观和风格,最简单的方法是使用浏览器的开发工具查找 Bootstrap 样式,并用您自己的样式覆盖它们。 Learn to Code with JavaScript 使用浏览器 Web 工具自定义 Bootstrap CSS。 让我们重点关注本文中的简单警报组件。 例如,尝试更改自定义 CSS 文档中padding、margin-bottom和的警报原始值 现在,该类的所有元素都.alert将如下所示: Bootstrap 警报组件的 CSS 自定义。 接下来,让我们继续扩展 Bootstrap 警报的功能。 自定义 Bootstrap 插件的功能 修改 Bootstrap 插件的功能通常涉及使用 CSS 和 JavaScript 文档。 大多数动态效果都是通过添加和删除 CSS 类来产生的,总体功能非常简单。 Learn to Code with JavaScript 在本文中,我将向警报组件添加一些额外的功能。 警报显示一条信息,用户可以通过单击按钮将其从页面中删除。 我将向警报添加放大和缩小按钮,使用户能够分别放大或缩小警报。我还将添加一个高对比度按钮,以允许用户以高对比度模式查看警报内容,即反转背景颜色和文本颜色。 让我们开始工作吧! 警报的结构 要继续操作,首先添加警报标记面是一个简单的警报框,包含三个链接:第一个是本机 Bootstrap关闭警报链接。这将用作您要创建的自定义三个链接的模板。–链接允许用户缩小警报框的大小和内容,而+链接则恰恰相反,即放大警报框及其内部文本。
|
|