前端入门:HTML(CSS背景,视觉差案例)

1.

设置背景颜色:

eg:background-color:green,这个时候背景颜色为深绿色,如果要想让颜色浅一点,一个办法是改变颜色的名称,还有一个办法是改变透明度background-color:rgba(0,255,0,0.1),透明度从0到1,0表示全透明,1表示不透明,其余为中间值。

设置背景图片:

background-image:url(图片路径),

设置背景图片是否平铺:

background-repeat:repeat这是平铺,即一个背景中有多个重复的图片,按规律排布

background-repeat:no-repeat,不平铺,背景中只有一个图片

设置背景图片的位置:

eg:background-position:center center,代表的是水平居中,这个前面值代表水平方向,分别为left(左),center(中间),right(右),后面代表数值方向,分别为top(上部),center(中间),bottom(底部)

设置背景是否跟着文字动的效果:

background-attachment:fixed,代表的是固定背景图不动,只有文字在上下滑动时运动。

使背景铺满整个容器:

background-size:cover

2.css视觉差案例

下一张照片滑动时候,会将上一张照片覆盖掉

案例:

源代码:

html:

    <link rel="stylesheet" href="./case-4.css">

</head>

<body>

    <div class="box1"></div>

    <div class="box2"></div>

    <div class="box3"></div>

</body>

css:

* {

    margin: 0;

    padding: 0;

}

html,body {

    height: 100%;

}

div {

    height: 100%;

}

.box1 {

    background: red;

    background-image: url(./picture/bg1.jpg);

    background-repeat: no-repeat;

    background-size: cover;

}

.box2 {

    background: green;

    background: url(./picture/bg2.jpg) no-repeat 0px 0px/cover fixed;

}

.box3 {

    background: yellow;

    background: url(./picture/bg3.jpg)0px 0px/cover fixed;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值