Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

css - Bootstrap images in grid that holdes different sizes

I′m currently an aspiring frontend developer. I′ve been assigned to create the markup and style of the following image

Assignment

I′m currently using twitter bootstrap 5, however I can′t seem to make the right adjustement.

<!doctype html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- Bootstrap CSS -->
        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">


        <title>Hello, world!</title>
    </head>
    <body>
        <div class="container-fluid p-0 bg-wabe h-100">
            <nav class="navbar navbar-expand-lg link-light mb-4 border-b">
                <a class="navbar-brand m-4" href="#">
                    brand
                </a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0 nav-fill w-100">
                        <li class="nav-item">
                            <a class="nav-link active link-light border-r" aria-current="page" href="#">LUGARES</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link link-light border-r" href="#">CATEGORIA</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link link-light border-r" href="#">EVENTOS</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link link-light border-r" href="#">CUPONES</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link link-light" href="#">CUENTA</a>
                        </li>
                    </ul>
                </div>
            </nav>
            <div class="container-xxl">
                <div class="row">
                    <div class="col-6 p-0">
                        <img src="https://images.unsplash.com/photo-1530863666585-c8996c9f729c?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1351&q=80" class="img-fluid mb-2" alt="img1">
                        <img src="https://images.unsplash.com/photo-1530863666585-c8996c9f729c?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1351&q=80" class="img-fluid" alt="img1">
                    </div>
                    <div class="col-3 p-0 pl-1 m-0">
                        <img src="https://images.unsplash.com/photo-1561807367-a1ff826a51e6?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80g" class="img-fluid" alt="img1">
                    </div>
                    <div class="col-3 p-0 pl-1 m-0">   
                        <img src="https://images.unsplash.com/photo-1561807367-a1ff826a51e6?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80" class="img-fluid" alt="img1">
                    </div>
                </div>
            </div>
        </div>
        
        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>

    </body>
    
</html>
question from:https://stackoverflow.com/questions/65923409/bootstrap-images-in-grid-that-holdes-different-sizes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No need with modern css.

You can just add this css:

img {
   height:100%;
   width:100%;
   object-fit:cover;
   object-position:center;
}

It will work as if it were a background-image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...