gpt4 book ai didi

html - 如何实现这种网格布局?

转载 作者:太空宇宙 更新时间:2023-11-04 07:23:38 25 4
gpt4 key购买 nike

我想要这样的布局

enter image description here

但我没有达到标题 6 和标题 7。您知道将那个 div 添加到布局中需要什么吗?

示例:http://jsfiddle.net/re221faf/1/

HTML:

<div class="card">
<div class="title_1">
<h6>Title 1</h6>
</div>
<div class="title_2">Title 2</div>
<div class="title_3">Title 3</div>
<div class="clear"></div>
<div class="title_4">Title 4 </div>
<div class="title_5">Title 5</div>

</div>

CSS:

.card {border:5px solid gray;}
.title_1{border-bottom:5px solid gray;}
.title_2{float:left; padding: 20px 0;}
.title_3{float:right; padding: 20px 0;}

.clear{clear:both;}

.title_4{border-top:5px solid gray; border-bottom: 5px solid gray;}

最佳答案

你应该看看 CSS Grid

  1. > A complete guide to CSS Grid
  2. > A nice game to understand CSS Grid

带有评论的工作片段:

.card{
/* create a css grid */
display:grid;
/* create 4 rows, the first two take up two fractions, and the last two take up 1 fraction */
grid-template-rows: 2fr 2fr 1fr 1fr;
/* create 3 columns of specified sizes */
grid-template-columns: 45% 45% 10%;
}

.card > div{
border: 1px solid black;
text-align:center;
}


.title_1{
/* element starts on the first column line and ends on the third*/
grid-column: 1 / 3;
/* element starts on the first row line and spans one row */
grid-row: 1 / span 1;
}
.title_2{
grid-column: 1 / 2;
grid-row: 2 / span 1;
}
.title_3{
grid-column: 2 / 3;
grid-row: 2 / span 1;
}
.title_4{
grid-column: 1 / 3;
grid-row: 3 / span 1;
}
.title_5{
grid-column: 1 / 3;
grid-row: 4 / span 1;
}
.title_6{
grid-column: 3 / 4;
grid-row: 1 / 2;
}
.title_7{
grid-column: 3 / 4;
grid-row: 2 / -1;
}
<div class="card">
<div class="title_1">
<h6>Title 1</h6>
</div>
<div class="title_2">Title 2</div>
<div class="title_3">Title 3</div>
<div class="title_4">Title 4 </div>
<div class="title_5">Title 5</div>
<div class="title_6">Title 6</div>
<div class="title_7">Title 7</div>
</div>

关于html - 如何实现这种网格布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50087692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com