亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在具有可拉伸彈性盒的盒子的每一側各有 4 個“托盤”?

如何在具有可拉伸彈性盒的盒子的每一側各有 4 個“托盤”?

倚天杖 2023-09-25 16:21:36
有一個主 div (#root),其中我需要 4 個內部 div,每個內部 div 的一側都完全拉伸(運行代碼片段即可查看)?,F在我在這里:html {  height: 100%;}body {  height: 100%;  margin: 0;  text-align: center;}#root {  background-color: blue;  display: flex;  flex-direction: row;  flex-wrap: wrap;  justify-content: space-between;  height: 100%;}.tray {  box-sizing: border-box;  background-color: red;  border: thin solid black;}.tray-top {  height: 48px;  width: 100%;}.tray-bottom {  height: 48px;  width: 100%;  align-self: flex-end;}.tray-left {  width: 48px;}.tray-right {  width: 48px;}<div id="root">    <div class="tray tray-top">top</div>    <div class="tray tray-left">left</div>    <div class="tray tray-right">right</div>    <div class="tray tray-bottom">bottom</div></div>現在我想left在和right之間充分伸展。topbottom請注意,所有托盤都有固定寬度(左、右)或固定高度(頂部、底部)。我會避免在現有的 div 中嵌套更多的 div。Flexbox 不是必須的,但我發現與其他可能性相比,它很簡單且面向未來。
查看完整描述

2 回答

?
子衿沉夜

TA貢獻1828條經驗 獲得超3個贊

一個簡單的浮動配置可以在沒有彈性盒的情況下做到這一點:


html,

body {

  height: 100%;

  margin: 0;

  text-align: center;

}


#root {

  background-color: blue;

  height: 100%;

}


.tray {

  box-sizing: border-box;

  background-color: red;

  border: thin solid black;

}


.tray-top,

.tray-bottom {

  height: 48px;

  line-height:48px;

  clear: both;

}


.tray-left,

.tray-right {

  width: 48px;

  height: calc(100% - 96px);

  float: left;

}


.tray-right {

  float: right;

}

/* to align vertically the content */

.tray-left::before,

.tray-right::before {

  content:"";

  display:inline-block;

  height:50%;

}

<div id="root">

  <div class="tray tray-top">top</div>

  <div class="tray tray-left">left</div>

  <div class="tray tray-right">right</div>

  <div class="tray tray-bottom">bottom</div>

</div>


查看完整回答
反對 回復 2023-09-25
?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

CSS-Grid 可以做到這一點:


html {

  height: 100%;

}


body {

  height: 100%;

  margin: 0;

  text-align: center;

}


#root {

  background-color: blue;

  display: grid;

  grid-template-columns: auto 1fr auto;

  grid-template-rows: auto 1fr auto;

  height: 100%;

}


.tray {

  box-sizing: border-box;

  background-color: red;

  border: thin solid black;

}


.tray-top {

  height: 48px;

  grid-column: 1 / -1;

}


.tray-bottom {

  height: 48px;

  grid-column: 1 / -1;

}


.tray-left {

  width: 48px;

}


.tray-right {

  width: 48px;

  grid-column:3;

}

<div id="root">

    <div class="tray tray-top">top</div>

    <div class="tray tray-left">left</div>

    <div class="tray tray-right">right</div>

    <div class="tray tray-bottom">bottom</div>

</div>


查看完整回答
反對 回復 2023-09-25
  • 2 回答
  • 0 關注
  • 156 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號