<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<div class="carousel"></div>
<div class="content"></div>
<div class="content"></div>
</div>
<style>
.container{
max-width: 480px;
margin: 0 auto;
}
.container .carousel{
background-color: lightsalmon;
height: 400px;
width: 100%;
/* Make the carousel's width fill the viewport */
}
.container .content{
margin: 10px 0px;
background-color: steelblue;
height: 200px;
width: 100%;
}
</style>
</body>
</html>
我需要使走马灯在水平方向上填满整个视口。
我不想使用position: absolute,因为它会丢失其他元素的高度信息,所以我需要在容器中添加更多的css,如果我需要改变走马灯的高度,我需要修改两个地方。而且,我也不想将其从容器中分离,因为它应该在容器内部。
那么有没有更好的方法,只需要向.carousel添加一些css就可以实现这个目标呢?
max-width
已经受限。我可以硬编码更改它,但这可能不是最好的方法。 - Hao Wu.container-fluid
类,这将使您能够使用整个视口的宽度。以下是来自Bootstrap 4文档的链接: https://getbootstrap.com/docs/4.1/layout/overview/ - Maitree Kuria