HTMLCSS--案例| 超链接美化 | 模态框 | tab栏选项卡

一、超链接美化

二、模态框

三、tab栏选项卡

--------------------------------------------

一、超链接美化

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>导航块超链接美化</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .nav{
            width: 960px;
            overflow: hidden;
            background-color: purple;
            margin: 100px auto 0;
            border-radius: 5px;  /*倒圆角*/
        }
        .nav ul{
            list-style: none;   /*清除列表前面的圆点*/
        }
        .nav ul li{
            float: left;
            width: 160px;
            height: 40px;
            text-align: center;
            line-height: 40px;
        }
        /*颜色只能在a里设,不能被继承*/
        .nav ul li a{
            width: 160px;
            height: 40px;
            display: block;
            color: white;
            text-decoration: none;

        }
        .nav ul li a:hover{
            background-color: red;
            font-size: 22px;
        }
    </style>
</head>
<body style="margin: 0 auto;">
    <div class="nav">
        <ul>
            <li>
                <a href="#">网站导航</a>
            </li>
            <li>
                <a href="#">网站导航</a>
            </li>
            <li>
                <a href="#">网站导航</a>
            </li>
            <li>
                <a href="#">网站导航</a>
            </li>
            <li>
                <a href="#">网站导航</a>
            </li>
            <li>
                <a href="#">网站导航</a>
            </li>
        </ul>
    </div>
</body>
</html>

二、模态框

模态框用的是固定定位设置z-index值来实现,
要注意z-index的值,要始终保持模态框的对话框z-index是在最大。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>通用模态框</title>
    <style type="text/css">
        *{
            padding: 0;
            margin: 0;
        }
        .container{
            visibility: hidden;
        }
        .bg{
            position: fixed;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,.3);
            z-index: 1000;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
        }
        .dialog-box{
            position: fixed;
            width: 300px;
            height: 300px;
            background-color: white;
            top: 50%;
            left: 50%;
            transform: translate(-150px,-150px);
            z-index: 1001;
            border-radius: 5px;
        }
        .exit{
            width: 30px;
            height: 30px;
            float: right;
            background-color: darkgreen;
            border-radius: 5px;
            text-align: center;
            line-height: 30px;
            cursor: pointer;
        }
        .exit:hover{
            background-color: red;
            color: #ffffff;
        }
    </style>
</head>
<body>
    <button id="btn">点击出现模态框</button>
    <div id="container" class="container">
        <div class="bg"></div>
        <div class="dialog-box">
            <a id="exit" class="exit">x</a>
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    function $(id) {
        return document.getElementById(id);
    }
    window.onload=function () {
        $('btn').onclick=function () {
            $('container').style.visibility='visible';
        };
        $('exit').onclick=function () {
            $('container').style.visibility='hidden';
        };
    }
</script>

三、tab栏选项卡

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        .clearfix:after{  content:'.';  clear:both;  display:block; visibility:hidden;  height:0  }
        *{
            padding: 0;
            margin: 0;
        }
        ul{
            list-style: none;

        }
        ul li{
            float: left;
            width: 100px;
            height: 30px;
            cursor: pointer;
        }
        .container{
            width: 300px;
        }
        .container p{
            width: 100%;
            height: 100px;
            display: none;
        }
        li.active{
            background-color: red;
            color: white;
        }
        p.active{
            background-color: indianred;
            color: white;
            display: block;
        }
    </style>
</head>
<body>
    <div class="container">
       <ul id="ul" class="clearfix">
            <li class="active">导航</li>
            <li>购买</li>
            <li>促销</li>
        </ul>
        <p class="active">导航导航导航导航导航导航导航导航导航</p>
        <p>买买买买买买买买买买买买</p>
        <p>促销促销促销促销促销促销</p>
    </div>
</body>
    <script type="text/javascript">
        function $(id) {
            return document.getElementById(id);
        }
        var li_objs=$('ul').children;
        var p_objs=document.getElementsByTagName('p');


        for(var i=0;i<li_objs.length;i++){
            //i是全局的,这里给每个标签存一个i
            li_objs[i].index = i;
            li_objs[i].onmouseover=function () {
                for(var j=0;j<li_objs.length;j++){
                    li_objs[j].className='';
                    p_objs[j].className='';
                }
                this.className='active';
                p_objs[this.index].className='active';
            }
        }
    </script>
</html>

 

posted on 2019-03-12 10:53 要一直走下去 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/staff/p/10515254.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值