【问题标题】:Reshaping card sizes in Bootstrap在 Bootstrap 中重塑卡片大小
【发布时间】:2020-10-01 08:35:28
【问题描述】:

我正在尝试构建我的网络作品集,我想要一种卡片格式,其中包含图像缩略图和下方的文本。我遇到的问题是无法控制初始图像的大小,导致卡片错位。

我想知道是否有办法修复它以适应任何图像尺寸。这是我的代码

<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
        crossorigin="anonymous">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css">
    <title>Pattern</title>
</head>

<body>

    <nav class="navbar bg-dark navbar-dark">
        <div class="container">
            <a href="" class="navbar-brand"> <i class="fas fa-code"></i> BODY OF WORK</a>
        </div>
    </nav>

    <section id="header" class="jumbotron text-center">
            <h1 class="display-3">FRANK DIN: WEB DEVELOPER</h1>
    </section>

    <section id="gallery">
        <div class="container">
            <div class="row">
                <div class="col-lg 4 mb-3">
                    <div class="card">
                        <a href=""><img class="card-img-top" src="https://github.com/frankdin1/LandingPage/blob/master/Landing%20Page%20thumbnail.PNG?raw=true"></a>
                        <div class="card-body">
                            <h5 class="card-title">Landing Page</h5>
                            <p class="card-text">Landing page for a fictitious dating site built with Bootstrap.</p>
                            <a href="https://github.com/frankdin1/LandingPage" class="btn btn-outline-primary">Github</a>
                            <a href="PurffectMatch.html" class="btn btn-outline-success">Webpage</a>
                        </div>
                    </div>
                </div>

                <div class="col-lg 4 mb-3">
                    <div class="card">
                        <a href=""><img class="card-img-top" src="https://github.com/frankdin1/Bootstrap-Image-Gallery/blob/master/BootstrapPhotoBlog%20thumbnail.PNG?raw=true"></a>
                        <div class="card-body">
                            <h5 class="card-title">Bootstrap Image Gallery</h5>
                            <p class="card-text">Image gallery built using Bootstrap.</p>
                            <a href="https://github.com/frankdin1/LandingPage" class="btn btn-outline-primary">Github</a>
                            <a href="PurffectMatch.html" class="btn btn-outline-success">Webpage</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <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.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
        crossorigin="anonymous"></script>
</body>

</html>

【问题讨论】:

    标签: javascript html css bootstrap-4


    【解决方案1】:

    添加这个 CSS:

    .card-img-top {
        height: 20vw; // change this value and/or units to your liking
        width: 100%;
        object-fit: cover;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-30
      • 2021-06-13
      • 2019-08-16
      • 2020-10-10
      • 2018-08-21
      • 2016-06-17
      • 2018-08-06
      • 2019-07-13
      • 1970-01-01
      相关资源
      最近更新 更多