www.91084.com

GVKun编程网logo

H5 自带验证美化 CSS(html怎么用css美化)

18

如果您对H5自带验证美化CSS和html怎么用css美化感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解H5自带验证美化CSS的各种细节,并对html怎么用css美化进行深入的分析,此外还有关于

如果您对H5 自带验证美化 CSShtml怎么用css美化感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解H5 自带验证美化 CSS的各种细节,并对html怎么用css美化进行深入的分析,此外还有关于AngularJS:如何验证美国格式的日期?、antd Vue实现Login登录页面布局案例详解 附带验证码验证功能、css input [type=file] 样式美化,input 上传按钮美化、CSS 美化的实用技巧。

本文目录一览:

H5 自带验证美化 CSS(html怎么用css美化)

H5 自带验证美化 CSS(html怎么用css美化)

1、:require(必填)和:optional(选填)     

<style>
.container{
max-width:400px;
margin:20px auto;
}
input,select,textarea{
width: 240px;
margin:10px 0;
border:1px solid #999;
padding: .5em 1em;
}
label{
color:#999;
margin-left: 10px;
}
input:required,textarea:required{
border-right:3px solid #aa0088;
}
input:optional,select:optional{
border-right:3px solid #999;
}
input:required +label::after{
content: "(必填)"
}
input:optional +label::after{
content: "(选填)"
}
input:focus,select:focus,textarea:focus{
outline:0;
}
input:required:focus,textarea:required:focus{
box-shadow: 0 0 3px 1px #aa0088;
}
input:optional:focus,select:required:focus{
box-shadow: 0 0 3px 1px #999;
}
input[type="submit"]{
background-color: #cc00aa;
border: 2px solid #aa0088;
padding:10px 0;
color:#fff;
}
input[type="submit"]:hover{
background-color:#aa0088;
}
</style>
</head>
<body>
<!-- <div></div> -->
<div>
<form action="#">
<input type="name" required><label > 名称 </label>
<input type="email" required><label > 邮箱 </label>
<input type="tel"><label > 手机 </label>
<input type="url"><label > 网址 </label>
<select name="" id="">
<option value=""> 非必选项一 </option>
<option value=""> 非必选项二 </option>
<option value=""> 非必选项三 </option>
<option value=""> 非必选项四 </option>
</select>
<textarea name="#" cols="30" rows="10" placeholder="留言(必填)" required></textarea>
<input type="submit" value="提交表单">
</form>
</div>

 

 

2、:in-range 和:out-of-range

3、:valid 和:invalid     符合表单验证和不符合表单验证

<style>
.container{
margin:100px;
position:relative;
}
input{
border: 1px solid #999;
outline:0;
width:140px;
height:30px;
line-height:30px;text-indent:36px;transition: all .3s;
border-radius:5px;
}
span.title{
position:absolute;
line-height:30px;
height: 30px;
left:2px;
top:2px;
transition:all .3s;
}
input:focus,input:hover{
text-indent:2px;
}
input:focus+span.title,input:hover+span.title{
transform:translateX(-120%)
}
input:valid ~label::after{
content: "你输入正确!"
}
input:invalid ~label::after{
content: "你邮箱错误!"
}
input:valid{
border:1px solid green;
}
input:invalid{
border:1px solid red;
}
</style>
</head>
<body>
<div>
<input id="mail" type="email" required placeholder="输入邮箱">
<span> 邮箱 </span>
<label for="mail"></label>
</div>

 

 

4、:read-only 和:read-write    代表 input 或者表单元素的标签

AngularJS:如何验证美国格式的日期?

AngularJS:如何验证美国格式的日期?

我有以下允许使用AngularUI输入日期的表单代码(日期为必填,并且应与美国日期格式匹配,例如:MM / DD / YY):

<form name="form" ng-submit="createShipment()">
    <!-- Shipment Date must be in MM/DD/YY format: -->  
    <input name="shipmentDate" 
          ng-pattern='/^[0,1]?\d{1}\/(([0-2]?\d{1})|([3][0,1]{1}))\/(([1]{1}[9]{1}[9]{1}\d{1})|([2-9]{1}\d{3}))$/'
          ui-date="{ dateFormat: 'mm/dd/y' }" required ng-model="shipment.ShipmentDate" type="text">
    <span ng-show="form.shipmentDate.$error.required">Date Required!</span>
    <span ng-show="form.shipmentDate.$error.pattern">Incorrect Format,should be MM/DD/YY!</span>

    <inputng-hide="!form.$valid" type="submit" value="Create">
</form>

必填 字段的验证工作正常,但日期格式未正确验证,并且始终显示 “格式不正确…” 消息。

我尝试了几种不同的正则表达式,这些规则表达式在其他地方都可以正常使用,但仍然无法正常工作。我也尝试了AngularUI验证,它也不起作用。提前致谢!

更新:

我认为验证与我使用的AngularUI
datepicker冲突,但是datepicker仍会自动更正日期,因此,如果不使用datepicker,则只要正则表达式有效,验证就可以工作;如果使用datepicker,则不需要其他验证。

antd Vue实现Login登录页面布局案例详解 附带验证码验证功能

antd Vue实现Login登录页面布局案例详解 附带验证码验证功能

效果

Login页面

<!--
 * @Author: Jackie
 * @Date: 2022-05-07 14:34:06
 * @LastEditTime: 2022-05-09 15:57:44
 * @LastEditors: Jackie
 * @Description: 登录页 用户名-密码-验证码登录方式
 * @FilePath: /vue-admin-template/src/views/Login.vue
 * @version: 
-->
<template>
  <div>
    <h1>JackieDYH管理平台</h1>
    <a-form-model ref="ruleForm" :model="form" :rules="rules">
      <h5>登录</h5>
      <a-form-model-item prop="name">
        <a-input v-model="form.name" placeholder="请输入邮箱/手机号" />
      </a-form-model-item>
      <a-form-model-item prop="password">
        <a-input type="password" v-model="form.password" placeholder="请输入密码" />
      </a-form-model-item>
      <a-form-model-item prop="code">
        <a-input v-model="form.code" placeholder="请输入验证码" />
        <Identify :identifyCode="identifyCode" @click="refreshCode" />
      </a-form-model-item>
      <a-form-model-item>
        <a-button block type="primary" @click="onSubmit"> 提交 </a-button>
        <!-- <router-link
          :to="{ name: ''Password'' }">
          忘记密码
        </router-link> -->
      </a-form-model-item>
    </a-form-model>
  </div>
</template>
 
<script>
import Identify from "@/components/Identify";
export default {
  name: "Login",
  components: { Identify },
  data() {
    let validateCode = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("验证码为空"));
        return false;
      } else if (value !== this.identifyCode) {
        callback(new Error("验证码不正确"));
        return false;
      } else {
        callback();
      }
    };
    return {
      identifyCodes: "1234567890",
      identifyCode: "",
      form: {
        name: "",
        password: "",
        code: "",
      },
      rules: {
        name: { required: true, message: "请输入邮箱/手机号", trigger: "blur" },
        password: { required: true, message: "请输入密码", trigger: "blur" },
        code: [{ validator: validateCode, trigger: "blur" }],
      },
    };
  },
  mounted() {
    // 初始
    this.identifyCode = "";
    this.makeCode(this.identifyCodes, 4);
  },
  methods: {
    // 确认
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.$router.push("/home");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 重置表单
    resetForm() {
      this.$refs.ruleForm.resetFields();
    },
    // 验证码相关
    randomNum(min, max) {
      return Math.floor(Math.random() * (max - min) + min);
    },
    // 点击刷新验证码
    refreshCode() {
      this.identifyCode = "";
      this.makeCode(this.identifyCodes, 4);
    },
    // 生成验证码
    makeCode(o, l) {
      for (let i = 0; i < l; i++) {
        this.identifyCode +=
          this.identifyCodes[this.randomNum(0, this.identifyCodes.length)];
      }
    },
  },
};
</script>
 
<style lang="scss" scoped>
.Login {
  width: 100%;
  height: 100%;
  background-image: url("~@/assets/images/bg_repeat_white.png");
  overflow: auto;
  .title {
    font-size: 40px;
    font-weight: bold;
    padding: 60px 0 60px 40px;
  }
  .ant-form {
    width: 500px;
    border-radius: 5px;
    background: #fff;
    margin: auto;
    padding: 18px 40px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    .ant-dropdown-trigger {
      float: right;
      margin-right: -20px;
    }
    h5 {
      font-size: 26px;
      text-align: center;
      margin-bottom: 25px;
    }
  }
  @media screen and (min-width: 769px) and (max-width: 1000px) {
    .title {
      font-size: 50px;
      text-align: center;
    }
    .ant-form {
      width: 60%;
    }
  }
  @media screen and (max-width: 769px) {
    .title {
      font-size: 50px;
      text-align: center;
    }
    .ant-form {
      width: 90%;
    }
  }
}
</style>
<style lang="scss">
// 验证码样式
.Login .identify .ant-form-item-children {
  display: flex;
  align-items: center;
  .ant-input {
    flex: 1;
    margin-right: 10px;
  }
}
</style>

 Identify验证码

<!--
 * @Author: Jackie
 * @Date: 2022-05-09 14:49:38
 * @LastEditTime: 2022-05-09 14:49:39
 * @LastEditors: Jackie
 * @Description: 验证码
 * @FilePath: /vue-admin-template/src/components/Identify.vue
 * @version: 
-->
<template>
  <canvas
    id="s-canvas"
    :width="contentWidth"
    :height="contentHeight"
    v-on="$listeners"
  ></canvas>
</template>
<script>
export default {
  name: "SIdentify",
  props: {
    identifyCode: {
      type: String,
      default: "1234",
    },
    fontSizeMin: {
      type: Number,
      default: 16,
    },
    fontSizeMax: {
      type: Number,
      default: 40,
    },
    backgroundColorMin: {
      type: Number,
      default: 180,
    },
    backgroundColorMax: {
      type: Number,
      default: 240,
    },
    colorMin: {
      type: Number,
      default: 50,
    },
    colorMax: {
      type: Number,
      default: 160,
    },
    lineColorMin: {
      type: Number,
      default: 40,
    },
    lineColorMax: {
      type: Number,
      default: 180,
    },
    dotColorMin: {
      type: Number,
      default: 0,
    },
    dotColorMax: {
      type: Number,
      default: 255,
    },
    contentWidth: {
      type: Number,
      default: 112,
    },
    contentHeight: {
      type: Number,
      default: 38,
    },
  },
  methods: {
    // 生成一个随机数
    randomNum(min, max) {
      return Math.floor(Math.random() * (max - min) + min);
    },
    // 生成一个随机的颜色
    randomColor(min, max) {
      let r = this.randomNum(min, max);
      let g = this.randomNum(min, max);
      let b = this.randomNum(min, max);
      return "rgb(" + r + "," + g + "," + b + ")";
    },
    drawPic() {
      let canvas = document.getElementById("s-canvas");
      let ctx = canvas.getContext("2d");
      ctx.textBaseline = "bottom";
      // 绘制背景
      ctx.fillStyle = this.randomColor(
        this.backgroundColorMin,
        this.backgroundColorMax
      );
      ctx.fillRect(0, 0, this.contentWidth, this.contentHeight);
      // 绘制文字
      for (let i = 0; i < this.identifyCode.length; i++) {
        this.drawText(ctx, this.identifyCode[i], i);
      }
      // this.drawLine(ctx)
      this.drawDot(ctx);
    },
    drawText(ctx, txt, i) {
      ctx.fillStyle = this.randomColor(this.colorMin, this.colorMax);
      ctx.font =
        this.randomNum(this.fontSizeMin, this.fontSizeMax) + "px SimHei";
      let x = (i + 1) * (this.contentWidth / (this.identifyCode.length + 1));
      let y = this.randomNum(this.fontSizeMax, this.contentHeight - 5);
      var deg = this.randomNum(-45, 45);
      // 修改坐标原点和旋转角度
      ctx.translate(x, y);
      ctx.rotate((deg * Math.PI) / 180);
      ctx.fillText(txt, 0, 0);
      // 恢复坐标原点和旋转角度
      ctx.rotate((-deg * Math.PI) / 180);
      ctx.translate(-x, -y);
    },
    drawLine(ctx) {
      // 绘制干扰线
      for (let i = 0; i < 8; i++) {
        ctx.strokeStyle = this.randomColor(
          this.lineColorMin,
          this.lineColorMax
        );
        ctx.beginPath();
        ctx.moveTo(
          this.randomNum(0, this.contentWidth),
          this.randomNum(0, this.contentHeight)
        );
        ctx.lineTo(
          this.randomNum(0, this.contentWidth),
          this.randomNum(0, this.contentHeight)
        );
        ctx.stroke();
      }
    },
    drawDot(ctx) {
      // 绘制干扰点
      for (let i = 0; i < 100; i++) {
        ctx.fillStyle = this.randomColor(0, 255);
        ctx.beginPath();
        ctx.arc(
          this.randomNum(0, this.contentWidth),
          this.randomNum(0, this.contentHeight),
          1,
          0,
          2 * Math.PI
        );
        ctx.fill();
      }
    },
  },
  watch: {
    identifyCode() {
      this.drawPic();
    },
  },
  mounted() {
    this.drawPic();
  },
};
</script>
<style lang="scss">
canvas {
  cursor: pointer;
}
</style>

到此这篇关于antd Vue实现Login登录页面布局案例详解 附带验证码验证功能的文章就介绍到这了,更多相关Vue登录页面布局内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

您可能感兴趣的文章:
  • antd vue table表格内容如何格式化
  • antdesign-vue结合sortablejs实现两个table相互拖拽排序功能
  • vue验证码(identify)插件使用方法详解
  • vue登录页面设置验证码input框的方法
  • Vue实现验证码登录的方法实例
  • vue实现登录时图形验证码

css input [type=file] 样式美化,input 上传按钮美化

css input [type=file] 样式美化,input 上传按钮美化

我们在做 input 文本上传的时候,html 自带的上传按钮比较丑,如何对其进行美化呢?同理:input checkbox 美化,input radio 美化是一个道理的,后面文章会总结。

思路:

input file 上传按钮的美化思路是,先把之前的按钮透明度 opacity 设置为 0, 然后,外层用 div 包裹,就实现了美化功能。

代码如下:

DOM 结构:

<a href="javascript:;" class="a-upload">
    <input type="file" name="" id="">点击这里上传文件
</a>

<a href="javascript:;" class="file">选择文件
    <input type="file" name="" id="">
</a>

CSS 样式 1:

.a-upload {
    padding: 4px 10px;
    height: 20px;
    line-height: 20px;
    position: relative;
    cursor: pointer;
    color: #888;
    background: #fafafa;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    display: inline-block;
    *display: inline;
    *zoom: 1
}

.a-upload  input {
    position: absolute;
    font-size: 100px;
    right: 0;
    top: 0;
    opacity: 0;
    filter: alpha(opacity=0);
    cursor: pointer
}

.a-upload:hover {
    color: #444;
    background: #eee;
    border-color: #ccc;
    text-decoration: none
}

样式 2:

.file {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
    text-indent: 0;
    line-height: 20px;
}
.file input {
    position: absolute;
    font-size: 100px;
    right: 0;
    top: 0;
    opacity: 0;
}
.file:hover {
    background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;
}

修改后如下:

enter image description here

样式二:

enter image description here

CSS 美化

CSS 美化

总结

以上是小编为你收集整理的CSS 美化全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

今天关于H5 自带验证美化 CSShtml怎么用css美化的讲解已经结束,谢谢您的阅读,如果想了解更多关于AngularJS:如何验证美国格式的日期?、antd Vue实现Login登录页面布局案例详解 附带验证码验证功能、css input [type=file] 样式美化,input 上传按钮美化、CSS 美化的相关知识,请在本站搜索。

本文标签: