问题
I'm trying to make a layout like the picture below but I don't know how to specify the column to make it be like a part of it 3/4 the column and the other part is 1/4, I'm trying to use flexbox
This what I want the layout looks like:
I don't know how to make what I'm saying up there :D as am still new to flexbox.
but down below my attempt to create this thing, but i couldn't make the first column consists of two unequal rows.
.container {
display: grid;
width: 100%;
height: 45vw;
margin: auto;
gap: 25px;
border: 2px solid red;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
grid-template-areas:
"cmd grph grph grph "
"write grph grph grph";
}
.box {
display: flex;
/*flex-direction: row;*/
align-items: center;
justify-content: center;
border: 5px solid black;
}
.dot {
height: 50px;
width: 50px;
background-color: blueviolet;
border-radius: 50%;
}
.command {
grid-area: cmd;
}
#grph {
grid-area: grph;
}
#write {
grid-area: write;
}
<div class="container">
<div class="command box"></div>
<div id="grph" class="box"></div>
<div id="write" class="box"></div>
</div>
回答1:
This is your code:
.container {
display: grid;
grid-template-rows: repeat(2,fr);
}
If you want two grid areas split 3/4 and 1/4, then why use two rows? Use four rows instead.
Grid
.container {
display: grid;
height: 45vw;
gap: 25px;
border: 2px solid red;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(4, 1fr);
grid-template-areas:
"cmd grph grph grph "
"cmd grph grph grph "
"cmd grph grph grph "
"write grph grph grph";
}
.command { grid-area: cmd; }
#grph { grid-area: grph; }
#write { grid-area: write; }
.box { border: 5px solid black; }
<div class="container" id="cmd">
<div class="command box"></div>
<div id="grph" class="box"></div>
<div id="write" class="box"></div>
</div>
Flex
Here's the flexbox solution:
.container {
display: flex;
flex-flow: column wrap;
height: 45vw;
border: 2px solid red;
}
.command {
flex: 3;
margin-bottom: 25px;
}
#grph {
flex-basis: 100%;
order: 1;
margin-left: 25px;
}
#write {
flex: 1;
}
.box {
border: 5px solid black;
}
<div class="container" id="cmd">
<div class="command box"></div>
<div id="grph" class="box"></div>
<div id="write" class="box"></div>
</div>
回答2:
first of all give class name different of
class="box1"
after that change its property
box1{
height:40vh
}
box2{
height: 20vh}
来源:https://stackoverflow.com/questions/62348117/unequal-row-heights-in-a-flex-column