HTML/CSS优化

1、关于使用:invalid伪类来实现验证不通过样式设置

<style>
        input[type=email]:invalid + .next-step{
            display: none
        }
    </style>
</head>
<body>
    <form action="">
        <input type="email">
        <span class="next-step">Next</span>
    </form>

2、实现title效果

<style>
        span[data-title]{
            position: relative;
        }
        span[data-title]:hover:before {
            content: attr(data-title);
            position: absolute;
            top: -150%;
            left: 50%;
            transform: translateX(-50%);
            white-space: nowrap;
            background-color: aqua;
        }
    </style>
<span>hello, <span data-title="FDSDSLKDJLSJKLJWWOIonosdfs">FED</span></span>

3、原始写法的form获取值

<form action="/s" id="reg">
        <input type="text" name="username" value="123"> 
        <input type="text" name="password" value="456">
    </form>

    <script>
        var form = document.forms.namedItem("reg");
        // var form = document.getElementById('reg');
        console.log(form['username'].value);
        console.log(form.password.value);
    </script>

4、获取fomr值的方法,jquery改版

    <form action="/s" id="reg">
        <input type="text" name="username" value="123">
        <input type="text" name="username" value="333">
        <input type="text" name="password" value="456">
    </form>


    <script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
    <script>
        $.fn.serializeForm = function () {
            var o = {},
                a = this.serializeArray();
            $.each(a, function () {
                // 如果存在两个input的name相同,则转成一个数组
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) { // 当前name是不是数组
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            })
            return o;
        }

        var userdata = $('#reg').serializeForm();
        console.log(userdata);

5、一个标签指向

<style>
      .chat-msg {
            width: 300px;
            height: 80px;
            border: 1px solid #ccc;
            position: relative;
            border-radius: 5px;
            filter: drop-shadow(0 0 2px #999);
            background-color: #fff;
        }
        .chat-msg:before{
            content: '';
            position: absolute;
            left: -10px;
            top: 34px;
            border-top: 6px solid transparent;
            border-bottom: 6px solid transparent;
            border-right: 10px solid #ccc;
        }
        .chat-msg:after {
            content: '';
            position: absolute;
            left: -8px;
            top: 34px;
            border-top: 6px solid transparent;
            border-bottom: 6px solid transparent;
            border-right: 10px solid #fff;
        }
    </style>


    <div style="margin: 100px 100px;">
            <div class="chat-msg">hi 你好呀</div>
    </div>

image.png

6、利用伪元素

 <style>
        .or {
            text-align: center;
        }

        .or:before,
        .or:after {
            content: '';
            position: absolute;
            line-height: 1;
            width: 200px;
            height: 1px;
            background-color: #ccc;
        }

        .or:before {
            left: 0;
        }

        .or:after {
            right: 0;
        }
    </style>
</head>

<body>
    <p class="or">OR</p>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值