gpt4 book ai didi

html - 如何修复环绕屏幕而不是适合的列

转载 作者:行者123 更新时间:2023-11-28 19:24:30 26 4
gpt4 key购买 nike

我正在编写一个网站,并希望使用 Bootstrap 4 在文本 block 旁边显示图像的预览。但是,当我将它们都放在列中时,它们会环绕屏幕,从而导致一行实际上有两列高.

我试过从 div 元素中删除/添加类(用于居中的类),但它似乎无法解决问题。

html,
body {
overflow-x: hidden;
}

body {
display: flex;
min-height: 100vh;
flex-direction: column;
}

.constrain-img {
max-width: 100%;
height: auto;
object-fit: contain;
}

.container-notfull {
padding: 15px;
width: 100%;
}

.img-center {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 0;
margin-bottom: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />

<body>
<br><br><br>
<img class="d-block w-100 background-cover" src="http://placehold.it/700x500">
<div class="container-notfull">
<div class="row">
<div class="col-md-12 text-center">
<h2>
Summer Camps 2019
</h2>
<br>
<h3>Curriculum</h3>
<p>
In this camp... text
</p>
<br>
</div>
</div>
<div class="row align-items-center">
<div class="col-md-6 align-self-center constrain-img">
<img class="h-75 img-center" src="http://placehold.it/700x700">
</div>
<div class="col-md-6 text-center align-self-center">
<h3>
There will be an entertaining camp... text
</h3>
<h4><a href="/css/img/flyer.pdf" download>Here</a> is a download to the flyer</h4>
<br>
<h3>Details</h3>
<p><b>Place:</b></p>
<p><b>Time:</b></p>
<p><b>Days:</b></p>
<p><b>Price:</b></p>
<p>Maximum of 10 people per day</p>
<br>
<h4>Register now</h4>
</div>
</div>
</div>
</body>

鉴于列宽加起来为 12,我希望它们水平对齐。但是,它会溢出并环绕到行的底部。

最佳答案

问题是您的图像设置为 block但你没有width设置,所以它总是希望是它的完整大小。

设置 width: 100%height: auto.img-center图片解决了这个问题。

.img-center {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 0;
margin-bottom: 0;
width: 100%;
height: auto;
}

fiddle https://jsfiddle.net/2g0kebs4/

html,
body {
overflow-x: hidden;
}

body {
display: flex;
min-height: 100vh;
flex-direction: column;
}

.constrain-img {
max-width: 100%;
height: auto;
object-fit: contain;
}

.container-notfull {
padding: 15px;
width: 100%;
}

.img-center {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 0;
margin-bottom: 0;
width: 100%;
height: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<br><br><br>
<img class="d-block w-100 background-cover" src="http://placehold.it/700x500">
<div class="container-notfull">
<div class="row">
<div class="col-md-12 text-center">
<h2>
Summer Camps 2019
</h2>
<br>
<h3>Curriculum</h3>
<p>
In this camp... text
</p>
<br>
</div>
</div>
<div class="row align-items-center">
<div class="col-6 align-self-center constrain-img">
<img class="h-75 img-center" src="http://placehold.it/700x700">
</div>
<div class="col-6 text-center align-self-center">
<h3>
There will be an entertaining camp... text
</h3>
<h4><a href="/css/img/flyer.pdf" download>Here</a> is a download to the flyer</h4>
<br>
<h3>Details</h3>
<p><b>Place:</b></p>
<p><b>Time:</b></p>
<p><b>Days:</b></p>
<p><b>Price:</b></p>
<p>Maximum of 10 people per day</p>
<br>
<h4>Register now</h4>
</div>
</div>
</div>

关于html - 如何修复环绕屏幕而不是适合的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56570049/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com