html - 如何在html css中根据父div来适应显示网格

标签 html css

HTML

<div class="parent">
  <div class="content">
   <div>
     <div style="width: 100%;height: 100%">
       <div class="grid grid-template" style="background:blue;">
         The display grid will be smaller or fitted on the parent div. but instead it will fitted on the parent it overlapped which is wrong. how to fix on it?
       </div>
     </div>
   </div>
  </div>
</div>
CSS
/* don't remove anything here */
.parent {
  display: block;
  width: 452px;
  height: 1038px;
  background: red;
}

.content {
  width: auto;
  display: inline-block;
    transform-origin: 0px 0px 0px;
    transform: matrix(1.51042, 0, 0, 1.51042, 0, 0);
}

.grid {
      height: calc(100% - 35px);
    display: grid;
    gap: 1px 1px;
    background: blue;
    grid-template-columns: 1fr 1fr 1fr; /* don't replace the value */
    grid-template-rows: 1fr 1fr 1fr; /* don't replace the value */
    grid-template-areas:
        "LINE3flr LINE1flr LINE1flr"
        "LINE3flr LINE1flr LINE1flr"
        ". . ."; /* don't replace the value */
}
enter image description here
显示网格将更小或适合父 div。但是相反,它将安装在它重叠的父级上,这是错误的。如何解决?它应该适合父 div。
例子:
http://jsfiddle.net/tavfbd2o/

最佳答案

你要这样做吗?

.parent {
  display: block;
  width: 452px;
  height: 1038px;
  background: red;
}

.content {
  width: 100%;
  height: 100%;
}

.grid {
      height: calc(100% - 35px);
    display: grid;
    margin: auto;
    gap: 1px 1px;
    grid-template-columns: 1fr 1fr 1fr; /* don't replace the value */
    grid-template-rows: 1fr 1fr 1fr; /* don't replace the value */
    grid-template-areas:
        "LINE3flr LINE1flr LINE1flr"
        "LINE3flr LINE1flr LINE1flr"
        ". . ."; /* don't replace the value */
}
<div class="parent">
  <div class="content">
     <div style="width: 100%;height: 100%">
       <div class="grid grid-template" style="background: blue;">
         The display grid will be smaller or fitted on the parent div. but instead it will fitted on the parent it overlapped which is wrong. how to fix on it ?
       </div>
     </div>
  </div>
</div>

关于html - 如何在html css中根据父div来适应显示网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64979406/

相关文章:

javascript - 使用 jQuery 改变点击背景颜色

ios - iOS 中 safari 上的视频(仅限 iPhone)在关闭后一直打开

表格的CSS问题

html - z-index 不工作 - 元素受其容器限制

html - CSS宽度过渡从右到左扩展图像?

python - 我怎样才能在 <span> </span> 使用 python splinter lib 之间获取文本

html - 不能一次悬停整行

css - 我如何在 GWT 中使用图像 Sprite ?

CSS float :left usage

javascript - 当外部组件未知时使左右边距相等