html 填充不能应用于标题的右侧

ivqmmu1c  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(117)

我刚开始学习CSS。问题是,我想添加填充到头部,但即使填充是应用在左侧,它并没有应用到右侧。
如何解决它,为什么会发生?
下面是CSS代码相关的header,header imagesectiona部分是Youtube部分。

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html{
    font-size: 10px;
}

body{
    font-size: 1.6rem;
    font-family: 'Open Sans', sans-serif;
    text-align: center;
    line-height: 1.5;
    background-color: #333;
    color: azure;
}

a{
    text-decoration: none;
}

p{
    padding: 1.6rem 0;
}

header{
    height: 46rem;
    padding: 2rem;
}

header .bg-image{
    position: absolute;
    background-image: url(images/01.jpg);
    background-size: cover;
    background-position: center;
    height: 46rem;
    width: 100%;
    opacity: 0.5;
    z-index: -1;
}

header h1{
    padding: 16rem;
    padding-bottom: 0;
}

.btn{
    display: inline-block;
    background: #333;
    border : 1px solid #666 ;
    margin: .5rem 0;
    color: azure;
    padding: 1.6rem 3.2rem;
    transition: all 0.4s;
}

.btn:hover{
    background-color: azure;
    color: #333;
}

#section-b{
    padding:2rem ;
}

new9mtju

new9mtju1#

这是因为图像部分是绝对元素。
请这样更新css。

header .bg-image{
    position:absolute;
    background-image: url(images/01.jpg);
    background-size: cover;
    background-position: center;
    height:46rem;
    left: 2rem;
    right: 2rem;
    opacity: 0.5;
    z-index: -1;
}

相关问题