【发布时间】:2019-12-27 03:32:33
【问题描述】:
我们有一个带有背景图像、一些文本(h1 和 p)和号召性用语按钮的 Bootstrap Jumbotron,我们希望能够针对不同的视口缩放图像,但要保持格式相同。所以 div 将被视为图像。
我在这里开始了这个实验:https://codepen.io/Codewalker/pen/xxKRLBd 并尝试了过渡和变换,但我无法让它正确显示。它一直表现得像一个响应式 div。
<div class="container">
<div class="row">
<div class="col-sm-12">
<img src="https://picsum.photos/id/1056/1424/562" alt="test" class="img-fluid">
<div class="heroContent">
<h1>Jumbotron H1 goes here</h1>
<p class="pHero">
This is the first line in the jumbotron.<br>
The second line appears underneath the first line.
</p>
<button type="button" class="btn btn-primary">Chat With Us</button>
</div>
</div>
</div>
</div>
.container {
max-width:1424px;
}
.heroContent {
position: absolute;
top: 30%;
left: 30%;
transform: translate(-50%, -50%);
}
我们的目标是让整个 div 本质上被视为图像,在不改变格式或布局的情况下全部缩放。
【问题讨论】:
-
也许最好用背景图片制作一个 div,然后将 hero-content div 放入其中,相对宽度为 %?
-
这是您尝试做的吗? codepen.io/gc-nomade/pen/mdbOGLX 这是如何工作的?见developer.mozilla.org/en-US/docs/Web/CSS/padding#Values#percentage
-
@Rustyjim - 你介意提供一个例子吗?
-
您可以查看
vw、vh或vmin/vmax值来调整font-size的大小。如果你使用calc(),你可以避免它变得太大或太小。测试更新:codepen.io/gc-nomade/pen/mdbOGLX 调整窗口宽度以查看它的作用。调整您的需要font-size和padding为.heroContent。如果那变得更近:) -
我可以稍后在工作中做一个例子。还需要一个吗?因为下面的答案对我来说也不错。对不起,我很慢 :)
标签: html css twitter-bootstrap css-transitions transform