【发布时间】:2020-05-09 09:10:23
【问题描述】:
我想在我的网页中实现这种屏幕。绝对定位元素是黄色容器。我为每个像素编写了一个媒体,它没有提供优化的响应能力。 bootstrap 4 中是否有任何类可以像这样定位并使其在所有设备上响应而无需显式编写媒体查询?提前致谢。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<style>
.sample{
position:relative;
}
.ml-lg-1{
position: absolute;
top:25vh;
left:-37vw;
}
@media (min-width:1340px){
.ml-lg-1{
position: absolute;
top:25vh;
left:-34vw;
}
}
@media (min-width:1050px){
.ml-lg-1{
position: absolute;
top:25vh;
left:-36vw;
}
}
@media (min-width:1100px){
.ml-lg-1{
position: absolute;
top:25vh;
left:-34vw;
}
}
@media (min-width:1200px){
.ml-lg-1{
position: absolute;
top:25vh;
left:-37vw;
}
}
@media (min-width:1300px){
.ml-lg-1{
position: absolute;
top:25vh;
left:-34vw;
}
}
@media (min-width:1380px){
.ml-lg-1{
position: absolute;
top:25vh;
left:-31vw;
}
}
@media (min-width:1705px){
.ml-lg-1{
position: absolute;
top:25vh;
left:-24vw;
}
}
</style>
<body>
<div class="container sample">
<div class="row">
<div class="columns col-sm-4" style="background:red;height:100vh;">
First
</div>
<div class="columns col-sm-4" style="background:green;height:100vh;">
Second
</div>
<div class="columns col-sm-4 third">
Third
<div class="container test ml-lg-1">
<div class="row">
<div class="col-sm-4" style="background:yellow;height:100px;width:100px;">
Test1
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
【问题讨论】:
-
你期望的操作是什么
-
我想要一个像上面这样的输出,而不必显式地编写媒体查询。 @AmareshSM 请在整页中查看输出你会知道我的意图
-
查看我的答案@LakshmiS
标签: html bootstrap-4 responsive