【问题标题】:Bootstrap 4 set width:100%; to child of div item that has "container" classBootstrap 4 组宽度:100%;到具有“容器”类的 div 项的子项
【发布时间】:2021-03-24 18:00:35
【问题描述】:

我已经为父 div 使用了容器类

这里:

<div class="container">
        <main role="main" class="pb-3">
              <div style="width:100%; height:300px;z-index:-1" class="col-lg-12 mt-n4 bg-white text- 
                 center">
               <div style="margin: 0;position: absolute;top: 50%;left: 50%;-ms-transform: 
                  translate(-50%, 
                 -50%);transform: translate(-50%, -50%);">
                 <img class="rounded-circle border border-info p-1" style="width:150px;height:150px;" 
                 src="~/ProfileImages/@currentuser.ImageProfile">
                <h4 class="text-center font-weight-bold text-info">@Model.ApplicationUser.ArName</h4>
               </div>
              </div>
         </main>
</div>

现在:我想将父级内 div 的宽度设为 100%,但我无法使用此代码:

 <div style="width:100%; height:300px;z-index:-1" class="col-lg-12 mt-n4 bg-white text-center">
        <div style="margin: 0;position: absolute;top: 50%;left: 50%;-ms-transform: translate(-50%, 
        -50%);transform: translate(-50%, -50%);">
            <img class="rounded-circle border border-info p-1" style="width:150px;height:150px;" 
            src="~/ProfileImages/@currentuser.ImageProfile">
            <h4 class="text-center font-weight-bold text-info">@Model.ApplicationUser.ArName</h4>
        </div>
</div>

如何删除子元素上的引导“容器”类效果?

【问题讨论】:

    标签: css twitter-bootstrap bootstrap-4


    【解决方案1】:

    //Try this One, It works fine and responsive in all widths and no need to write that much css
    
    <!doctype html>
    <html lang="en">
    
    <head>
        <title>Title</title>
        <!-- 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.3.1/css/bootstrap.min.css"
            integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    </head>
    
    <body style="width: auto;height: auto;">
    
        <div class="container mt-2">
            <div class="card bg-white text- 
                     center" style="width:20rem">
                <img class="img-fluid card-img-top"
                    src="https://cnet2.cbsistatic.com/img/-e95qclc6pwSnGE2YccC2oLDW_8=/1200x675/2020/04/16/7d6d8ed2-e10c-4f91-b2dd-74fae951c6d8/bazaart-edit-app.jpg">
                <div class="card-body">
    
                    <h4 class="text-center font-weight-bold text-info">@Model.ApplicationUser.ArName</h4>
                </div>
            </div>
        </div>
    
        <!-- 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.7/umd/popper.min.js"
            integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
            crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
            integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
            crossorigin="anonymous"></script>
    </body>
    
    </html>

    【讨论】:

      猜你喜欢
      • 2018-01-04
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-13
      • 2012-03-24
      • 2015-10-23
      • 1970-01-01
      相关资源
      最近更新 更多