我的内部div应该留在外部div里面(背景)

时间:2018-06-07 22:54:55

标签: html css responsive-design

我的按钮和文字应保留在背景尺寸上并具有响应性。

enter image description here

enter image description here

当我放大时会发生这种情况。

CSS -

#bg { 
height: 100vh;
background-image: url('../../assets/img/2.png'); /*  Background Image Link */   
background-size: 102%;
background-repeat: no-repeat;
position: relative;
}

.container1 {
    display: table;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

在CSS中,它应该是:background-size: cover;

#bg {
height: 100vh;
background-image: url('../../assets/img/2.png');
background-size: cover; /*Change Here*/
background-repeat: no-repeat;
position: relative;
}