覆盖 div 不会在 Safari (webkit) 上显示
Overlay div won't display on Safari (webkit)
我有一个 div,我想将其置于覆盖屏幕的不透明图像的顶部。我已经让它在 Chrome 中正常工作(闪烁),但我无法让它在 Safari (webkit) 中显示。我创建了一个 simplified JSFiddle version of my issue 并在此处也包含了代码片段。
HTML
<div id="home">
<div class="wallpaper"></div>
<div class="info-wrapper">
<span class="name">John Doe</span>
</div>
</div>
SCSS
#home {
position: relative;
width: 100%;
height: 100vh;
min-height: inherit;
display: flex;
align-items: center;
background-color: black;
}
.wallpaper {
width: 100%;
height: 100%;
min-height: inherit;
opacity: .5;
background: url(https://images.unsplash.com/photo-1440700265116-fe3f91810d72);
background-size: cover;
background-repeat: no-repeat;
}
.info-wrapper {
position: absolute;
display: flex;
justify-content: center;
width: 100%;
color: white;
> .name {
font-weight: 700;
font-size: 7em;
}
}
我愿意改变我的 HTML 的结构,如果这样可以更容易地解决这个问题。
[更新]
If the element has 'position: absolute', the containing block is established by the nearest ancestor with a 'position' of 'absolute', 'relative' or 'fixed'
您可以在此link
中获得更多详细信息
.container {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
position: relative;
}
.red {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 200px;
height: 200px;
background-color: red;
}
.green {
width: 20px;
height: 20px;
background-color: green;
position: absolute;
}
<div class="container">
<div class="red"></div>
<div class="green"></div>
</div>
在这个例子中,绿色框没有设置left
属性,值应该是auto
,结果应该是指最近的元素。而且,这在 Safari 和 Firefox 中显示正确。 Chrome不达标
[年长]
我认为您需要的是让墙纸从文档中流出。 运行 safari 中的示例。 sample
.wallpaper {
width: 100%;
height: 100%;
position: absolute;
min-height: inherit;
opacity: .5;
background: url(https://images.unsplash.com/photo-1440700265116- fe3f91810d72);
background-size: cover;
background-repeat: no-repeat;
}
我有一个 div,我想将其置于覆盖屏幕的不透明图像的顶部。我已经让它在 Chrome 中正常工作(闪烁),但我无法让它在 Safari (webkit) 中显示。我创建了一个 simplified JSFiddle version of my issue 并在此处也包含了代码片段。
HTML
<div id="home">
<div class="wallpaper"></div>
<div class="info-wrapper">
<span class="name">John Doe</span>
</div>
</div>
SCSS
#home {
position: relative;
width: 100%;
height: 100vh;
min-height: inherit;
display: flex;
align-items: center;
background-color: black;
}
.wallpaper {
width: 100%;
height: 100%;
min-height: inherit;
opacity: .5;
background: url(https://images.unsplash.com/photo-1440700265116-fe3f91810d72);
background-size: cover;
background-repeat: no-repeat;
}
.info-wrapper {
position: absolute;
display: flex;
justify-content: center;
width: 100%;
color: white;
> .name {
font-weight: 700;
font-size: 7em;
}
}
我愿意改变我的 HTML 的结构,如果这样可以更容易地解决这个问题。
[更新]
If the element has 'position: absolute', the containing block is established by the nearest ancestor with a 'position' of 'absolute', 'relative' or 'fixed'
您可以在此link
中获得更多详细信息.container {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
position: relative;
}
.red {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 200px;
height: 200px;
background-color: red;
}
.green {
width: 20px;
height: 20px;
background-color: green;
position: absolute;
}
<div class="container">
<div class="red"></div>
<div class="green"></div>
</div>
在这个例子中,绿色框没有设置left
属性,值应该是auto
,结果应该是指最近的元素。而且,这在 Safari 和 Firefox 中显示正确。 Chrome不达标
[年长]
我认为您需要的是让墙纸从文档中流出。 运行 safari 中的示例。 sample
.wallpaper {
width: 100%;
height: 100%;
position: absolute;
min-height: inherit;
opacity: .5;
background: url(https://images.unsplash.com/photo-1440700265116- fe3f91810d72);
background-size: cover;
background-repeat: no-repeat;
}