我正在创建bootstrap 4轮播,并在图像顶部覆盖了一些自定义文本。目标是不要编写过多的CSS,以使移动性成为越来越少的问题。因此,我尝试在不编写媒体查询的情况下解决以下问题。我将vw大小设置为h标签取得了一些成功,但是在移动设备上看起来不正确(太小或太大)。
我遇到的问题
在移动设备(例如iPhone 5e)上,底部的白色div太大,无法将图片和上方的大文字遮挡(“ H1我们正在分发...”)。这是由于文本的大小不会随着屏幕大小的变小而变小(垂直屏幕大小主要是问题,水平看起来很好)。就像我之前说过的那样,我与大众一起玩以解决此问题,但它要么太大要么太大。我试图避免不惜一切代价编写媒体查询。同样,不同尺寸的图像也会导致显示效果也不同,所以我应该保持固定的高度和宽度吗?
.carousel-type-home .caption-div {
background-color: white;
padding: 1rem;
}
.carousel-type-home .caption-div h3 {
color: #000000;
}
.carousel-type-home .caption-div p {
color: #000000;
}
.carousel-type-home .card-img-overlay h1 {
color: #ffff;
}
.carousel-type-home .card-img-overlay h5 {
color: #ffff;
}
.carousel-type-home button {
white-space: normal;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN"
crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="./style/index.css">
</head>
<body>
<div class="container">
<div id="demo" class="carousel slide carousel-type-home" data-ride="carousel">
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="" class="mx-auto d-block" src="https://www.w3schools.com/bootstrap4/chicago.jpg"
alt="Card image cap">
<div class="card-img-overlay ">
<div class="row justify-content-md-center">
<div class="text-center col-lg-5 col-sm-6">
<h1 class="card-title">H1 We distribute products that delivery energy to the world.</h1>
<h5 class="card-text">We're ready. Are you?</h5>
</div>
</div>
</div>
<div class="carousel-caption">
<div class="row caption-div">
<div class="col-sm ">
<h3>Tried and true products.</h3>
</div>
<div class="col-sm ">
<p class="text-left">Quality assurance of offerings Varius sit amet mattis vulputate enim nulla aliquet porttitor
urpis egestas integer eget aliquet.</p>
<button type="button" class="btn btn-danger btn-block">Learn more about our Quality Assurance </button>
</div>
</div>
</div>
</div>
<div class="carousel-item">
<img class="" class="mx-auto d-block" src="https://www.w3schools.com/bootstrap4/la.jpg"
alt="Card image cap">
<div class="card-img-overlay ">
<div class="row justify-content-md-center">
<div class="text-center col-lg-4 col-sm-6">
<h1 class="card-title">H1 We distribute products that delivery energy to the world.</h1>
<h5 class="card-text">We're ready. Are you?</h5>
</div>
</div>
</div>
<div class="carousel-caption">
<div class="row caption-div">
<div class="col-sm ">
<h3>Tried and true products.</h3>
</div>
<div class="col-sm ">
<p class="text-left">Quality assurance of offerings Varius sit amet mattis vulputate enim nulla aliquet porttitor
urpis egestas integer eget aliquet.</p>
<button type="button" class="btn btn-danger btn-block">Learn more about our Quality Assurance </button>
</div>
</div>
</div>
</div>
<div class="carousel-item">
<img class="" class="mx-auto d-block" src="https://www.w3schools.com/bootstrap4/ny.jpg"
alt="Card image cap">
<div class="card-img-overlay ">
<div class="row justify-content-md-center">
<div class="text-center col-lg-4 col-sm-6">
<h1 class="card-title">H1 We distribute products that delivery energy to the world.</h1>
<h5 class="card-text">We're ready. Are you?</h5>
</div>
</div>
</div>
<div class="carousel-caption">
<div class="row caption-div">
<div class="col-sm ">
<h3>Tried and true products.</h3>
</div>
<div class="col-sm ">
<p class="text-left">Quality assurance of offerings Varius sit amet mattis vulputate enim nulla aliquet porttitor
urpis egestas integer eget aliquet.</p>
<button type="button" class="btn btn-danger btn-block">Learn more about our Quality Assurance </button>
</div>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</div>
</body>
</html>
</body>
</html>