简体   繁体   中英

Adjust div height to div parent's

I'm designing a nav panel and I need to adjust the different option's styles to the parent div. For example, I need to adjust the background color of the options to the parent div (Paint the color in the full height of the parent div). 在此处输入图片说明

This is the code:

<div class="text-center text-muted"> <div class="container">
 <div class="card">
  <div class="card-header" style="background-color: #e9ecef;">
   <div class="row mt8" id="nav_panel">
    <div class="col-md-2" id="nav_panel_monday" style="background-color: rgb(0, 160, 157);">
    <a id="nav_href_monday" href="#" style="color: white;">Monday</a>
   </div>
   <div class="col-md-2" id="nav_panel_tuesday">
    <a id="nav_href_tuesday" href="#">Tuesday</a>
   </div>
   <div class="col-md-2" id="nav_panel_wednesday">
    <a id="nav_href_wednesday" href="#">Wednesday</a>
   </div>
   <div class="col-md-2" id="nav_panel_thursday">
    <a id="nav_href_thursday" href="#">Thursday</a>
   </div>
   <div class="col-md-2" id="nav_panel_friday">
    <a id="nav_href_friday" href="#">Friday</a>
   </div>
  </div>
 </div>
 <div class="card-body">
  <div id="div_hidden_monday"></div>
  <div id="div_hidden_tuesday" style="display: none;"></div>
  <div id="div_hidden_wednesday" style="display: none;"></div>
  <div id="div_hidden_thursday" style="display: none;"></div>
  <div id="div_hidden_friday" style="display: none;"></div>
 </div>
 </div>
</div>
</div>
.container {
    width: 100%;
    padding-right: 0;
    padding-left: 0;
    margin-right: auto;
    margin-left: auto;
}
.card {
    position: relative;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    flex-direction: column;
    min-width: 0;
    word-wrap: break-word;
    background-color: #FFFFFF;
    background-clip: border-box;
    border: 1px solid rgba(0, 0, 0, 0.125);
    border-radius: 0.25rem;
}
.card-header {
    padding: 0.75rem 1.25rem;
    margin-bottom: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
}
#nav_panel {
    background-color: #e9ecef;
    padding-right: 0;
    padding-left: 0;
    border-radius: 5px;
}
.col-md-2 {
    position: relative;
    width: 100%;
    min-height: 1px;
    padding-right: 15px;
    padding-left: 15px;
}

Any suggestion? Thanks for reading!

I think, you need to remove padding of the .card-header and add padding to the child elements. Like this https://jsfiddle.net/bhusalhari99/sruLkt2b/3/

hope it will works for you.

For the time being using padding and margin issue is fixed but You need to re-right the nav HTML structure using nav and ul li like here

 .container { width: 100%; padding-right: 0; padding-left: 0; margin-right: auto; margin-left: auto; } .card { position: relative; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; flex-direction: column; min-width: 0; word-wrap: break-word; background-color: #FFFFFF; background-clip: border-box; border: 1px solid rgba(0, 0, 0, 0.125); border-radius: 0.25rem; } .card-header { padding: 0 15px !important; margin-bottom: 0; background-color: rgba(0, 0, 0, .03); border-bottom: 1px solid rgba(0, 0, 0, .125); } .card-header a { display: block; padding: 10px 0; } #nav_panel { background-color: #e9ecef; padding-right: 0; padding-left: 0; border-radius: 5px; } .col-md-2 { position: relative; width: 100%; min-height: 1px; padding-right: 15px; padding-left: 15px; }
 <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script> <div class="text-center text-muted"> <div class="container"> <div class="card"> <div class="card-header" style="background-color: #e9ecef;"> <div class="row mt8" id="nav_panel"> <div class="col-md-2" id="nav_panel_monday" style="background-color: rgb(0, 160, 157);"> <a id="nav_href_monday" href="#" style="color: white;">Monday</a> </div> <div class="col-md-2" id="nav_panel_tuesday"> <a id="nav_href_tuesday" href="#">Tuesday</a> </div> <div class="col-md-2" id="nav_panel_wednesday"> <a id="nav_href_wednesday" href="#">Wednesday</a> </div> <div class="col-md-2" id="nav_panel_thursday"> <a id="nav_href_thursday" href="#">Thursday</a> </div> <div class="col-md-2" id="nav_panel_friday"> <a id="nav_href_friday" href="#">Friday</a> </div> </div> </div> <div class="card-body"> <div id="div_hidden_monday"></div> <div id="div_hidden_tuesday" style="display: none;"></div> <div id="div_hidden_wednesday" style="display: none;"></div> <div id="div_hidden_thursday" style="display: none;"></div> <div id="div_hidden_friday" style="display: none;"></div> </div> </div> </div> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM