CSS3图片

1.4.1 圆角图片

圆角图片的实现原理:直接在图片身上添加 border-radius: 10px;

 <style>
        .pic1{
            width: 220px;
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <!-- 圆角图片 -->
    <img src="img/w1.jpg" alt="" class="pic1">

预览:

1.4.2 椭圆图片

<style>
        .pic2{
            width: 320px;
            height:150px;
            /* 椭圆图片 */
            /* 
             50% 50% 50% 50% 正斜杠前面的 4个50%,表示的是 四个角的水平半径
             /50% 50% 50% 50% 正斜杠后面的 4个50%,表示的是 四个角的垂直半径
            */
             border-radius: 50% 50% 50% 50%/50% 50% 50% 50%;
            /* border-radius: 50%/50%; */
            /* border-radius: 50%; */
        }
    </style>
</head>
<body>
    <!-- 圆角图片 -->
    <img src="img/f1.jpg" alt="" class="pic2">

 预览:

注意:你找的素材图,宽高比例要稍微大一些。这样椭圆效果形成的更加明显。

1.4.3 缩略图

我们使用 border 属性来创建缩略图。

    <style>
        .box img{
            width: 220px;
            border: 1px solid ;
            /* 观察:border-radius的圆角弧度 是出现在图片身上的,还是出现在图片外的边框上的?
                    border-radius的圆角弧度 是出现在 边框身上的。
            */
            border-radius: 10px;
            padding: 20px;
        }
    </style>
</head>
<body>
    <div class="box">
        <img src="img/w2.jpg" alt="">
    </div>

 预览:

1.4.4 响应式图片

响应式图片 会 自动适配 各种尺寸的屏幕。

当你拖到浏览器窗口的时候,这个图,会随着你在拖动窗口的时候,图的大小,会跟着等比例进行缩放。浏览器在水平方向上的水平滚动条不会出现。

 <style>
        .banner img{
            max-width: 100%;
            height: auto;
        }
    </style>
</head>
<body>
    <div class="banner">
        <img src="img/trolltunga.jpg" alt="">
    </div>

 

1.4.5 定位图片文本

1.4.5.1 左上角文本

    <style>
        .con1{
            /* 父相 */
            position: relative;
        }
        .con1 img{
            maxwidth:100%;
            width: 100%;
            height: auto;
            opacity: 0.3;
        }
        .con1 .topleft{
            /* 子绝 */
            position: absolute;
            top: 0;
            left: 0;
        }
    </style>
</head>
<body>
    <div class="con1">
        <img src="img/trolltunga.jpg" alt="">
        <div class="topleft">左上角文本</div>
    </div>

 预览:

1.4.5.2 右上角文本

 <style>
        .con1{
            /* 父相 */
            position: relative;
        }
        .con1 img{
            maxwidth:100%;
            width: 100%;
            height: auto;
            opacity: 0.3;
        }
        .con1 .topright{
            /* 子绝 */
            position: absolute;
            top: 0;
            right: 0;
        }
    </style>
</head>
<body>
    <div class="con1">
        <img src="img/trolltunga.jpg" alt="">
        <div class="topright">右上角文本</div>
    </div>

 预览:

1.4.5.3 左下角文本

    <style>
        .con1{
            /* 父相 */
            position: relative;
        }
        .con1 img{
            width: 100%;
            height: auto;
            opacity: 0.3;
        }
        .con1 .bottomleft{
            /* 子绝 */
            position: absolute;
            bottom: 0px;
            left: 0px;
        }
    </style>
</head>
<body>
    <div class="con1">
        <img src="img/trolltunga.jpg" alt="">
        <div class="bottomleft">左下角文本</div>
    </div>

 预览:

1.4.5.4 右下角文本

  <style>
        .con1{
            /* 父相 */
            position: relative;
        }
        .con1 img{
            width: 100%;
            height: auto;
            opacity: 0.3;
        }
        .con1 .bottomright{
            /* 子绝 */
            position: absolute;
            bottom: 8px;
            right: 15px;
        }
    </style>
</head>
<body>
    <div class="con1">
        <img src="img/trolltunga.jpg" alt="">
        <div class="bottomright">右下角文本</div>
    </div>

 预览:

1.4.5.5 居中文本

    <style>
        .con1{
            /* 父相 */
            position: relative;
        }
        .con1 img{
            width: 100%;
            height: auto;
            opacity: 0.3;
        }
        .con1 .center{
            /* 子绝 */
            position: absolute;
            left: 50%;
            top: 50%;
            margin-left: -36px;
            margin-top: -9px;
            /* 此时,文字由文本撑开的宽度,就是当前盒子的宽度 (1个字的宽18px 乘以 4个字 = 72px)  
            72 取 一半, 就是36,这个盒子要向左移动36px
            18 取 一半,就是9,这个黑子要向上移动9px
            */
            font-size: 18px;
            outline: 1px solid red;
        }
    </style>
</head>
<body>
    <div class="con1">
        <img src="img/trolltunga.jpg" alt="">
        <div class="center">居中文本</div>
    </div>

 预览:

1.4.6 卡片式图片

   <style>
        body{
            margin: 25px;
        }
        .cart{
            width: 80%;
            max-width: 80%;
            background-color: #fff;
            box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);;
            margin-bottom: 26px;
        }
        .cart img{
            width: 100%;
        }
        .cart .container{
            padding: 10px 20px;
        }
    </style>
</head>
<body>
    <div class="cart">
        <img src="img/trolltunga.jpg" alt="">
        <div class="container">
            <p>涓滴之水终可以磨损大石,不是由于它力量强大,而是由于昼夜不舍的滴坠。</p>
        </div>
    </div>

    <div class="cart">
        <img src="img/lights600x400.jpg" alt="">
        <div class="container">
            <p>为了自己想要的未来,你要相信,挺过这段难熬的时间,一切都会好起来的,所以你必须得满怀信心的坚持下去。</p>
        </div>
    </div>

 

预览:

1.4.7 图片滤镜

CSS filter 属性用为元素添加可视效果 (例如:模糊与饱和度) 。

注意: Internet Explorer 或 Safari 5.1 (及更早版本) 不支持该属性。

给图像设置高斯模糊

       .blur{
            /* 给图像设置高斯模糊 */
            -webkit-filter: blur(4px);
            filter: blur(4px);
        }

 给图片应用一种线性乘法,使其看起来更亮或更暗

       .brightness{
            /* 给图片应用一种线性乘法,使其看起来更亮或更暗 */
            -webkit-filter: brightness(250%);
            filter: brightness(250%);
        }

调整图像的对比度

      .contrast{
            /* 调整图像的对比度 */
            -webkit-filter: contrast(180%);
            filter: contrast(180%);
        }

将图像转换为灰度图像

      .grayscale{
            /* 将图像转换为灰度图像 */
            -webkit-filter: grayscale(100%);
            filter: grayscale(100%);
        }

给图像应用色相旋转

        .hue-rotate{
            /* 给图像应用色相旋转 */
            -webkit-filter: hue-rotate(180deg);
            filter: hue-rotate(180deg);
        }

注意:

filter: hue-rotate(360deg); 这里如果你直接设置360deg。图是看不出效果的。如果你结合css3动画效果一起写。从0deg 变化到 360deg。可以看到图片色相的变化。

如果我们纯粹是给图加一个效果,用 filter: hue-rotate(度deg); 这个“度”取值,我们取0-360之间的数字。

整体预览:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值