css属性设置-显示与隐藏、盒子阴影、固定定位

   2023-03-08 学习力0
核心提示:显示与隐藏!DOCTYPE htmlhtmlheadmeta charset="utf-8"title显示与隐藏/titlestylebody {margin: 0;}div {width: 200px;height: 200px;background-color: orange;font: 30px/200px 'Arial';color: red;text-align: center;margin: 0 auto;border-radius: 50%;

显示与隐藏

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>显示与隐藏</title>
    <style>
        body {
            margin: 0;
        }
        div {
            width: 200px;
            height: 200px;
            background-color: orange;
            font: 30px/200px 'Arial';
            color: red;
            text-align: center;
            margin: 0 auto;
            border-radius: 50%;
        }
    </style>
    <style>
        /*display
        值为none时,盒子会被隐藏,且不在页面中占位
        */
        .box2 {
            display: none;
            transition: 1s;
        }
        .box1:hover ~ .box2 {
            display: block;
        }
        .box2:hover {
            display: block;
        }
    </style>
    <style>
        /*opacity
        值为0~1,控制盒子的透明度,但是消失后,在页面中占位
        */
        .box4 {
            /*背景颜色不能操作文本*/
            /*background-color: rgba(0,0,0,0);*/
            opacity: 0;
            /*过度效果*/
            transition: 1s;
        }
        .box3:hover ~ .box4 {
            opacity: 1;
        }
        .box4:hover {
            opacity: 1;
        }
    </style>

    <style>
        .box6 {
            width: 0;
            height: 0;
            /*超出content以外的内容如何处理:hidden隐藏*/
            overflow: hidden;
            transition: 1s 0s ease;
            /*过渡得我属性个数可以自定义*/
            /*transition-property: width, background-color, height;*/
            transition-property: all;
        }
        .box5:hover ~ .box6 {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
        .box6:hover {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>
<body>
<div class="box1">1</div>
<div class="box2">2</div>
<div class="box3">3</div>
<div class="box4">4</div>
<div class="box5">5</div>
<div class="box6">6</div>
<div class="box7">7</div>
<div class="box8">8</div>
</body>
</html>

盒子阴影

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>盒子阴影</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: orange;
            margin: 200px auto;
            /*opacity: 0;*/
            transition: .3s;
        }

        .box {
            /*x轴偏移 y轴偏移 虚化程度 阴影宽度 阴影颜色*/
            /*box-shadow: -300px 0 10px 0 red, 300px 0 10px 0 blue;*/
        }
        .box:hover {
            margin-top: 195px;
            box-shadow: 0 5px 10px 0 #333;
        }

    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

固定定位

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>固定定位</title>
    <style>
        html, body {
            min-width: 1000px;
        }
        body {
            margin: 0;
            height: 5000px;
        }

        .box {
            width: 260px;
            height: 420px;
            background-color: orange;
        }
        /*固定定位
        1、定位属性值:fixed
        2、在页面中不再占位(浮起来了)
        3、一旦定位后,定位的布局方位 top、bottom、left、right都能参与布局
        4、固定定位的参考系是页面窗口(不是页面中的哪一点,而是四边参照四边)
        5、左右同时存在,取左;同理上下取上
        */
        .box {
            position: fixed;
            /*left: 10px;*/
            right: 10px;
            /*bottom: 50%;*/
            top: calc(50% - 210px);
        }

        /*响应式布局*/
        /*@media (min-width: 1000px) {*/
            /*.box {*/
                /*position: fixed;*/
                /*!*left: 10px;*!*/
                /*right: 10px;*/
                /*bottom: 10px;*/
                /*top: 10px;*/
            /*}*/
        /*}*/
    </style>
</head>
<body>
    <div class="box"></div>
    <h1>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</h1>
    <h1>h1h1h1</h1>
    <h1>h1h1h1</h1>
    <h1>h1h1h1</h1>
</body>
</html>

绝对定位

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>绝对定位</title>
    <style>
        .sup {
            width: 180px;
            height: 260px;
            background-color: orange;
            margin: 100px auto;
        }
        .sub {
            width: 50px;
            height: 80px;
            background-color: red;
        }

        /*绝对定位:
        1、定位属性值:absolute
        2、在页面中不再占位(浮起来了),就无法继承父级的宽度(必须自己自定义宽度)
        3、一旦定位后,定位的布局方位 top、bottom、left、right都能参与布局
        4、绝对定位的参考系是最近的定位父级(不是父级中的哪一点,而是四边参照四边)
        5、左右同时存在,取左;同理上下取上
        6、当父级定位了,子级参照父级定位,又可以重新获取父级宽度(也可以在计算中拿到父级高度)
        */
        .sub {
            position: absolute;
            left: calc(50% - 25px);
            right: 0;
            bottom: 0;
            top: calc(50% - 40px);
        }
        /*需求:
        1)父级需要定位 - 辅助自己绝对定位,作为自己绝对定位的参考系
        2)父级定位了,但是不能影响自身原有布局 - 虽然定位,但是不浮起来
        结论:相对定位 => 父相子绝
        */
        .sup {
            /*父级相对定位的目的:1)不影响自身布局 2)辅助自己绝对定位布局*/
            position: relative;
        }
        /*body {*/
            /*width: 1000px;*/
            /*height: 600px;*/
            /*position: fixed;*/
        /*}*/
        /*.sup {*/
            /*position: fixed;*/
        /*}*/
    </style>
</head>
<body>

<div class="sup">
    <div class="sub"></div>
    <h3>hhhhhhhhhhhh</h3>
</div>

</body>
</html>

小米悬浮商品案例

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>绝对定位案例</title>
    <style>
        body {
            margin: 0;
            background-color: tomato;
        }
        .box {
            width: 234px;
            height: 300px;
            background-color: white;
            margin: 100px auto 0;
            /*父相子绝*/
            position: relative;
        }
        .title {
            width: 64px;
            height: 20px;
            background-color: #e53935;
            font-size: 12px;
            color: white;
            text-align: center;
            /*绝对定位*/
            position: absolute;
            top: 0;
            left: calc(50% - 32px);
            /*默认消失,有数据就 show 显示*/
            display: none;
        }
        .show {
            display: block;
        }

        /*大家都定位浮起来,很容易出现层次重叠 z-index绝对显示层次*/
        /*z-index: 值为大于等于1的正整数,不需要有序*/
        .title {
            z-index: 666;
        }
        .img {
            z-index: 10;
        }


        .img {
            position: absolute;
            top: 35px;
            left: calc(50% - 75px);
        }
        .img img {
            width: 150px;
            /*高会等比缩放*/
        }

        .logo {
            position: absolute;
            bottom: 70px;
            font-size: 15px;
            text-align: center;
            width: inherit;
        }
        .price {
            text-align: center;
            position: absolute;
            width: inherit;
            bottom: 30px;
            font-size: 14px;
        }
        .price span:first-child {
            color: #ff6700;
        }
        .price span:last-child {
            text-decoration: line-through;
            color: #aaa;
        }

        .bottom {
            width: inherit;
            height: 0;
            background-color: yellow;
            z-index: 888;
            transition: .2s;
            /*将超出内容隐藏*/
            overflow: hidden;
            position: absolute;
            bottom: 0;
        }
        .box:hover .bottom {
            height: 80px;
        }
        .box {
            transition: .2s;
        }
        .box:hover {
            box-shadow: 0 5px 10px 0 #ccc;
            margin-top: 95px;
        }
    </style>
</head>
<body>

    <div class="box">
        <div class="title show">减 100 元</div>
        <!--外层完成位置布局,内存完成内容展示-->
        <div class="img">
            <img src="img/001.jpg" alt="">
        </div>
        <h3 class="logo">小米电视4A 32寸</h3>
        <p class="price">
            <span>699元</span>
            <span>799元</span>
        </p>
        <div class="bottom">
            <h5>嘻嘻嘿嘿哈哈-呵呵!!!</h5>
            <p>来自<a href="">Owen</a>的评论</p>
        </div>
    </div>

</body>
</html>

相对定位

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>相对定位</title>
    <style>
        .box {
            width: 300px;
            height: 300px;
            background-color: orange;
            margin: 0 auto;
        }
        h1 {
            margin: 0;
        }
        /*相对定位:
        1、定位属性值:relative
        2、在页面中依旧占位,完全保留之前的所有布局
        3、一旦定位后,定位的布局方位 top、bottom、left、right都能参与布局
        4、相对定位的参考系是自身原有位置(当前位置)(不是自身中的哪一点,而是四边参照四边)
        5、左右同时存在,取左;同理上下取上,布局移动后,也不影响自身原有位置(兄弟布局也不会变化)
        作用:辅助于子级的绝对定位布局,一般不用于自身布局
        */
        .box {
            position: relative;
            /*left: -10px;*/
            bottom: 20px;
            top: 400px;
        }
    </style>
</head>
<body>
    <h1>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</h1>
    <div class="box"></div>
    <h1>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</h1>
</body>
</html>

overflow属性

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>overflow属性</title>
    <style>
        .box {
            width: 200px;
            height: 300px;
            background-color: pink;
        }
        /*
        1)默认子级(内容)超出父级显示区域,不会做任何处理(正常显示)
        2)overflow: hidden; - 隐藏超出的内容
        3)overflow: scroll; - 以滚动方式显示内容(一定会预留滚动条的占位)
        4)overflow: auto; - 有超出内容才以滚动方式显示
        */
        .box {
            overflow: auto;
        }
    </style>
</head>
<body>
    <div class="box">
        哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大哈斯蒂芬纳士大夫士大夫四大
    </div>
</body>
</html>

轮播图菜单案例

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>布局案例</title>
    <link rel="stylesheet" href="css/reset.css">

    <style>
        .scroll-view {
            width: 1226px;
            height: 460px;
            background-color: orange;
            margin: 50px auto 0;

            position: relative;
        }

        .scroll-menu {
            position: absolute;
            background-color: rgba(0, 0, 0, 0.5);
            width: 234px;
            padding: 20px 0;
        }
        .scroll-menu a {
            display: block;
            /*height: 42px;*/
            line-height: 42px;
            color: white;
            /*padding-left: 30px;*/
            text-indent: 30px;
        }
        .scroll-menu a span {
            /*参考的不是a,是ul*/
            position: absolute;
            right: 20px;
        }
        .scroll-menu a:hover {
            background-color: red;
        }

        .scroll-menu-blank {
            width: calc(1226px - 234px);
            height: 460px;
            background-color: red;
            /*参考的是ul*/
            position: absolute;
            top: 0;
            left: 234px;
            display: none;
        }

        .scroll-menu li:hover ~ .scroll-menu-blank {
            display: block;
        }
        .scroll-menu-blank:hover {
            display: block;
        }
    </style>
</head>
<body>
    <div class="scroll-view">
        <!--轮播图-->
        <div class="scroll-scroll"></div>
        <!--菜单栏-->
        <ul class="scroll-menu">
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <li>
                <a href="">
                    手机电话卡
                    <span>&gt;</span>
                </a>
            </li>
            <div class="scroll-menu-blank">

            </div>
        </ul>
    </div>
</body>
</html>
 
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • css实现弹出框 css弹出菜单
    弹出框也是前端里面经常使用的一个应用场景了,最开始想到的是用js实现这个效果,看到codepen上面有用css实现的。其实就是用到了css里面的一个:target选择器+visibility属性。URL 带有后面跟有锚名称 #,指向文档内某个具体的元素。这个被链接的元素就是目标
    03-08
  • jfinal框架页面找不到相关css,js文件404
    在JFinalConfig中添加配置: @Overridepublic void configHandler(Handlers handlers) {handlers.add(new ContextPathHandler());}页面中添加:base href="${CONTEXT_PATH}/"/之前页面找不到资源,把tomcat工程路径去掉了(path=""),这样暂时解决了问题推荐
    03-08
  • 纯CSS3实现的一些酷炫效果 css实现炫酷背景
    纯CSS3实现的一些酷炫效果 css实现炫酷背景
      之前在网上看到一些用纯CSS3实现的酷炫效果,以为实现起来比较困难,于是想看看具体是怎么实现的。一、笑脸猫动画实现效果如下:这个实现起来确实比较麻烦,很多地方需要花时间,有耐心地调整。1.先看下页面结构:bodydiv class="container"!-- 脸 --div
    03-08
  • 移动端CSS底部固定和fixed定位在ios上的bug
    fixed定位在ios上的bugcss三栏布局假设我们页面的 HTML 结构是这样: div class="wrapper"div class="content"!-- 页面主体内容区域 --/divdiv class="footer"!-- 需要做到 Sticky Footer 效果的页脚 --/div/div方法1.:absolute通过绝对定位处理应该是常见的
    03-08
  • css实现图片翻转 css使图片旋转
    !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"html xmlns="http://www.w3.org/1999/xhtml"headmeta http-equiv="Content-Type" content="text/h
    03-08
  • css3 渐变gradient
    css3 渐变gradient
           CSS3引入了背景渐变、background-origin、background-clip、background-size、遮罩等多个属性。这里将记录我从网上和书上学习的笔记和心得体会。   首先是渐变,我这里讲述的渐变不仅仅是背景色的渐变还将包括透明度渐变。以前做这种背景色渐
    03-08
  • CSS3中的px,em,rem,vh,vw辨析 css3 vw
    1、px:像素,精确显示2、em:继承父类字体的大小,相当于“倍”,如:浏览器默认字体大小为16px=1em,始终按照div继承来的字体大小显示,进场用于移动端          em换算工具:http://www.runoob.com/tags/ref-pxtoemconversion.html3、rem:与em类似,
    03-08
  • gulp自动化构建工具--自动编译less为css--学习
     1.安装      命令:npm install gulp-less 或者 cnpm install gulp-less2.编写文件 //获取gulpvar gulp = require('gulp')//获取gulp-less模块var less = require("gulp-less")//编译less//在命令行输入gulp less启动此任务gulp.task('less',function(){
    03-08
  • 关于动画Animate.css的使用方法
        首先贴个官网:https://daneden.github.io/animate.css/  1、引入animate css文件 1 head2 link rel="stylesheet" href="animate.min.css"3 /head   2、给指定的元素加上指定的动画样式名div class="animated bounceOutLeft"/div    这里包
    03-08
  • selenium Firefox禁用js,css.falsh,缓存,设置
    1 profile = FirefoxProfile() 2 #请求头 3 #profile.set_preference("general.useragent.override", util.http_agent_insert(xinhuaUtil.agent_path)) 4 # 激活手动代理配置(对应着在 profile(配置文件)中设置首选项) 5 profile.set_preference("network
    03-08
点击排行