Html 如何渲染具有4:3比例背景图像的div
我有一个图像,我想在相同的比例显示,无论屏幕大小是什么。我想让图像占屏幕宽度的80%,然后高度应该自己计算,这样图像的渲染比例为4:3。我知道在堆栈溢出方面也有类似的问题,但到目前为止,没有一个问题对我有所帮助(尤其是那些填充顶部的问题)。任何帮助都将不胜感激Html 如何渲染具有4:3比例背景图像的div,html,css,Html,Css,我有一个图像,我想在相同的比例显示,无论屏幕大小是什么。我想让图像占屏幕宽度的80%,然后高度应该自己计算,这样图像的渲染比例为4:3。我知道在堆栈溢出方面也有类似的问题,但到目前为止,没有一个问题对我有所帮助(尤其是那些填充顶部的问题)。任何帮助都将不胜感激 .tile-clients { margin-top: 0px; text-align: center; padding: 0px 0px 0px 0px; min-height: 400px; max-height
.tile-clients {
margin-top: 0px;
text-align: center;
padding: 0px 0px 0px 0px;
min-height: 400px;
max-height: 400px;
width: 100%;
}
.clients {
background: url("../images/clients.jpg");
background-repeat: no-repeat;
background-size: 100% 100%;
min-width: 400px;
min-height: 300px;
width: 80%;
margin: auto;
}
<section class = "tile-clients">
<h2>Our Clients</h2>
<div class = "clients"></div>
</section>
.tile客户端{
边际上限:0px;
文本对齐:居中;
填充:0px 0px 0px 0px;
最小高度:400px;
最大高度:400px;
宽度:100%;
}
.客户{
背景:url(“../images/clients.jpg”);
背景重复:无重复;
背景大小:100%100%;
最小宽度:400px;
最小高度:300px;
宽度:80%;
保证金:自动;
}
我们的客户
您必须放置。顶部填充:75%;在css中
.clients {
background: url("../images/clients.jpg");
background-repeat: no-repeat;
background-size: 100% 100%;
min-width: 400px;
min-height: 300px;
width: 80%;
margin: auto;
padding-top: 75%; //4:3 css calc aspect ratio, formula: height/width*100
}
你必须把填充物放在上面:75%;在css中
.clients {
background: url("../images/clients.jpg");
background-repeat: no-repeat;
background-size: 100% 100%;
min-width: 400px;
min-height: 300px;
width: 80%;
margin: auto;
padding-top: 75%; //4:3 css calc aspect ratio, formula: height/width*100
}
定义宽度(如80vw),并使用calc函数计算高度。我已经为以下内容创建了一个基本演示:
.tile客户端{
保证金:0px自动0px;
文本对齐:居中;
填充:0px 0px 0px 0px;
宽度:80vw;
高度:计算值(80vw*0.75);
/* 3/4 = 0.75 */
}
.客户{
背景:url(“https://source.unsplash.com/neBHai7g9vc/800x600");
背景重复:无重复;
背景大小:100%100%*/
宽度:100%;
身高:100%;
}
我们的客户
定义宽度(如80vw)并使用calc函数计算高度。我已经为以下内容创建了一个基本演示:
.tile客户端{
保证金:0px自动0px;
文本对齐:居中;
填充:0px 0px 0px 0px;
宽度:80vw;
高度:计算值(80vw*0.75);
/* 3/4 = 0.75 */
}
.客户{
背景:url(“https://source.unsplash.com/neBHai7g9vc/800x600");
背景重复:无重复;
背景大小:100%100%*/
宽度:100%;
身高:100%;
}
我们的客户
使用80vw
而不是80%
-这将始终提供当前窗口大小的80%的宽度css中的所有其他内容符合我的目标?可能重复使用80vw
而不是80%
-这将始终提供当前窗口大小的80%的宽度是css中的所有内容css是否适合我想要实现的目标?是否可能重复