【发布时间】:2018-01-06 12:59:47
【问题描述】:
好的,前言:我是一个非常业余的程序员。例如,我上周刚开始,我基本上在做的是查找“如何做 x”,然后将其与“如何做 y”和“如何做 z”结合起来,以一种笨拙的想法和代码组合.
我要做的是将 4 张图片以 2x2 方向放置,间距足够大,以便很好地查看某些背景,并将它们全部集中在页面上并半响应(我并不担心移动或极端,但我希望它在不同的浏览器尺寸/改变屏幕尺寸等上看起来不错。
同样,我在这方面非常新手,无法协调所有细节。我知道代码很草率而且可能是“错误的”,但我只是为了玩弄它。太棒了,我只是想将这些图像放在任何间距合适的页面上。
body,
html {
height: 100%;
margin: 0;
}
.bg {
background-image: url("http://static1.businessinsider.com/image/587621bcdd08953f208b491a/14-eerily-beautiful-photos-of-europes-first-underwater-art-museum.jpg");
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
ul {
list-style-type: none;
}
.container {
position: relative;
width: 48%;
float: right;
margin-bottom: 70px;
}
.image {
display: inline-block;
width: 300px;
height: 200px;
margin: auto;
border-radius: 15%
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 200px;
width: 300px;
opacity: 0;
transition: 2s ease;
background-color: green;
border-radius: 15%
}
.container:hover .overlay {
opacity: .75;
}
.text {
color: white;
font-size: 1.5vw;
position: absolute;
top: 50%;
left: 35%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="bg">
<div class="container">
<img src="https://i.pinimg.com/736x/96/3b/ee/963beeb07d222d64094a25bc3840b532--easter-bunny-a-bunny.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">
It's a vampire bunneh!!! BUNNICULA!!!! YES!!! HAHAHAHA
</div>
</div>
</div>
<div class="container">
<img src="https://i.ytimg.com/vi/Q6xybdaV3xs/maxresdefault.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">
<ul>
<li>This really isn't my text</li>
<li>But I'm playing with it anyway</li>
<li>To show my UL stuff</li>
<li>or something of that nature</li>
<li>Hi and thank you</li>
<li>if you choose to help</li>
<li>Or if you just want to laugh and watch</li>
</div>
</div>
</div>
<div class="container">
<img src="http://www.herts.ac.uk/__data/assets/image/0009/66717/rocket_car_launch.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">
I thought this thing was kinda cool
</div>
</div>
</div>
<div class="container">
<img src="https://upload.wikimedia.org/wikipedia/en/e/eb/Spaceball_jump_over_Skydive_35.jpg" alt="Avatar" class="image">
<div class="overlay">
<div class="text">
I've always wanted to go skydiving!
</div>
</div>
</div>
</div>
所以,是的。我所拥有的笨重的东西可能是可怕的设置和令人困惑的,但我只是试图从逻辑上遵循当时对我有意义的东西,而不是使用任何整体背景知识。任何帮助都将不胜感激,即使是告诉我“你是个白痴,完全重新开始或停止编码,因为你很烂”。 =P
【问题讨论】:
-
您想将其显示为 2x2 网格,四个角的间距相同?
-
是的。我想将它们“居中”放置,我想页面内所有边的间距相同,这样背景仍然可见并且它们不会歪斜或任何东西。
标签: html css background-image centering