gpt4 book ai didi

html - 防止在卡片文本较长时使用图像放大引导卡片

转载 作者:太空宇宙 更新时间:2023-11-04 15:50:09 24 4
gpt4 key购买 nike

如您所见,我在卡片中有一张图片,图片大小是固定的且已知,但卡片文本长度可能会有所不同(短或长)。问题是我怎样才能防止卡片高度按比例放大并强制它保持高度只包含图像并强制文本换行和缩短。

image of card

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<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://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<div class="container body-content">
<div class="card text-center">
<div class="card-header" style="text-align:right;font-weight:bold;font-size:large" dir="rtl">
<p style="padding-right:20px;margin-bottom:0px">Post Header</p>
</div>
<div class="card-body" style="padding-top:0px;padding-bottom:0px;padding-right:0px">
<div class="row">
<div class="col-9">
<p style="padding-top:20px;padding-bottom:20px;text-align:right;white-space: normal;" dir="rtl" class="card-text">
This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long TextThis Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text
</p>
</div>
<div class="col-3">
<img class="img-fluid" src="http://fakeimg.pl/200/">
</div>
</div>
</div>
</div>
</div>

最佳答案

使用属性 overflow:hidden 并动态设置 div 的高度解决了这个问题。将 onresize="myFunction()"onload="myFunction()" 添加到您的 body 标签。

function myFunction()
{
var a=document.getElementById("image").height;
document.getElementById("test").style.height = a+"px";
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<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://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<body onresize="myFunction()" onload="myFunction()">
<div class="container body-content">
<div class="card text-center">
<div class="card-header" style="text-align:right;font-weight:bold;font-size:large" dir="rtl">
<p style="padding-right:20px;margin-bottom:0px">Post Header</p>
</div>
<div class="card-body" style="padding-top:0px;padding-bottom:0px;padding-right:0px;max-height:200px !important;">
<div class="row">
<div class="col-9" style="overflow:hidden;" id="test">
<p style="padding-top:20px;padding-bottom:20px;text-align:right;" dir="rtl" class="card-text">
This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long TextThis Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text This Is Long Text
</p>
</div>
<div class="col-3">
<img class="img-fluid" src="http://fakeimg.pl/200/" id="image">
</div>
</div>
</div>
</div>
</div>
</body>

希望这对您有所帮助!

关于html - 防止在卡片文本较长时使用图像放大引导卡片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51168820/

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