Tailwind Input

基础输入框

无边框

无边框输入框主要使用了shadow阴影,适合在有底色的环境中使用。

无边框
<input type="text" class="relative outline-none rounded px-2 py-1 w-full bg-white shadow text-sm text-gray-700 placeholder-gray-400 focus:outline-none focus:shadow-outline" placeholder="placeholder" />
样式属性
relativeposition:relative;
outline-noneoutline:0;
px-2 py-1padding:.25rem .5rem;
w-fullwidth:100%;
bg-whitebackground-color:white;
shadowbox-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
text-sm text-gray-700font-size:.875rem; color:#b83280;

placeholder-gray-400实际的类名全程为.placeholder-pink-400::placeholder表示文本占位符的颜色color: #f687b3;

伪类样式属性
focusoutline-noneoutline:0;
focusshadow-outlinebox-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);

带边框

带边框取消了阴影shadow取而代之的是border,适合在纯色背景中使用。

白底带边框
<input type="text" class="relative outline-none border border-gray-400 rounded py-1 px-2 w-full bg-white text-sm text-gray-700 placeholder-gray-400 focus:outline-none focus:shadow-outline" placeholder="placeholder"/>
样式属性
relativeposition:relative;
outline-noneoutline:0;
border border-gray-400 round-
px-2 py-1padding:.25rem .5rem;
w-fullwidth:100%;
bg-whitebackground-color:white;
shadowbox-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
text-sm text-gray-700font-size:.875rem; color:#b83280;

输入框尺寸

input size
标识尺寸样式属性
small小型py-1 px-2 text-smpadding:.25rem .5rem; font-size:.875rem;
regular普通py-3 px-3 text-smpadding:.75rem; font-size:.875rem;
large大型py-4 px-3 text-basepadding:1rem .75rem; font-size:1rem;
<input type="text" class="relative outline-none rounded py-1 px-2 w-full bg-white shadow text-sm text-gray-700 placeholder-gray-400 focus:outline-none focus:shadow-outline" placeholder="placeholder" />

<input type="text" class="relative outline-none rounded py-3 px-3 w-full bg-white shadow text-sm text-gray-700 placeholder-gray-400 focus:outline-none focus:shadow-outline" placeholder="placeholder" />

<input type="text" class="relative outline-none rounded py-4 px-3 w-full bg-white shadow text-base text-gray-700 placeholder-gray-400 focus:outline-none focus:shadow-outline" placeholder="placeholder" />

输入框图标

输入框左右侧的图标采用Flex弹性容器和绝对定位结合方式实现

input with icon

左侧图标

input with left icon
<div class="relative mb-3 w-full flex flex-wrap items-stretch">
  <span class="absolute z-10 py-3 pl-3 w-8 h-full leading-snug bg-transparent rounded text-base font-normal text-gray-400 text-center flex items-center justify-center">
    <i class="fa fa-lock"></i>
  </span>
  <input type="text" class="relative py-1 px-2 pl-10 w-full bg-white rounded shadow outline-none text-sm text-gray-700 placeholder-gray-400 focus:outline-none focus:shadow-outline" placeholder="placeholder" />
</div>

右侧图标

input with right icon
<div class="relative mb-3 w-full flex flex-wrap items-stretch">
  <input type="text" class="relative py-1 px-2 pr-10 w-full bg-white rounded shadow outline-none text-sm text-gray-700 placeholder-gray-400 focus:outline-none focus:shadow-outline" placeholder="placeholder" />
  <span class="absolute right-0 z-10 py-1 pr-2 w-8 h-full leading-snug bg-transparent rounded text-base font-normal text-gray-400 text-center flex items-center justify-center">
    <i class="fa fa-user"></i>
  </span>
</div>

源代码地址

https://codepen.io/junchow/pen/eYpqWQE?editors=1000

参考UI

https://www.creative-tim.com/learning-lab/tailwind-starter-kit/presentation
### Tailwind CSS 使用指南 #### 安装与设置 为了开始使用 Tailwind CSS,在项目中安装可以通过多种方式完成。对于现代前端开发环境,推荐的方式是通过 PostCSS 插入到构建工具链中。这不仅适用于常见的 JavaScript 构建工具如 Vite 或 Webpack[^3],也适合其他任何支持 PostCSS 的工作流。 ```bash npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p ``` 这段命令会创建 `tailwind.config.js` 和 `postcss.config.js` 文件,这是配置 Tailwind 所必需的。 #### 配置 Tailwind CSS 初始化之后,编辑生成的 `tailwind.config.js` 来定制化 Tailwind 行为,比如主题颜色、断点等: ```javascript // tailwind.config.js module.exports = { purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'], darkMode: false, theme: { extend: {}, }, variants: { extend: {}, }, plugins: [], } ``` 此配置文件中的 `purge` 字段指定了哪些文件应该被扫描以移除未使用的样式,这对于优化生产版本非常重要。 #### 创建全局样式表并引入 Tailwind 接着,在项目的根目录下新建一个名为 `input.css` 的文件,并加入如下代码来引入 Tailwind 的核心功能层——基础样式(Base),组件(Component), 和实用程序(Utility): ```css @import 'tailwindcss/base'; @import 'tailwindcss/components'; @import 'tailwindcss/utilities'; ``` 最后一步是在 HTML 中链接这个自定义样式的入口文件: ```html <link href="/path/to/output.css" rel="stylesheet"> ``` 注意这里的路径应当指向经过 PostCSS 处理后的最终输出文件位置。 #### 开发模式下的实时预览 为了让开发者能够即时看到更改的效果,可以利用 Tailwind CLI 提供的服务端渲染特性开启监视模式: ```bash npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch ``` 这样每当源码发生变化时都会自动重新编译 CSS 并刷新浏览器页面显示最新效果。 #### 生产环境下压缩资源 当准备部署应用至线上服务器前,记得运行一次完整的构建过程来确保只保留必要的最小化 CSS 资源: ```bash npx tailwindcss -i ./src/input.css -o ./dist/output.css --minify ``` 上述操作将会执行 CSS 清理逻辑,删除所有无用的选择器从而减少打包体积提升加载速度。 #### 设计工具集成 除了编码实现界面外,Tailwind 还能很好地与其他流行的设计软件相结合,例如 Figma、Sketch 或者 Adobe XD。借助官方提供的插件可以直接在这些应用程序内部访问 Tailwind 类名库,使得视觉稿更加贴近真实的产品形态[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值