gpt4 book ai didi

html - 在不移动任何其他东西的情况下增加一个 div

转载 作者:行者123 更新时间:2023-11-28 00:31:35 24 4
gpt4 key购买 nike

我有 4 个 div(红、黄、绿、蓝)就我而言,我每行有 2 个。我需要在红色下方不留空隙的情况下种植第二个(黄色),只有蓝色必须向下跟随黄色。

我有一支密码笔如果你想试试。 Code

<div id="app">
<v-app id="inspire">
<v-item-group>
<v-container>
<div class="row">
<v-col
v-for="(item, index) in colors"
:key="index"
cols="12"
md="6"
>
<v-card
class="align-center"
height="auto"
:color="item.color"
>
<v-card-text v-for="(c, ind) in item.content" :key="ind" @click="colors[index].content.push(c)">{{c}}</v-card-text>
</v-card>
</v-col>
</div>
</v-container>
</v-item-group>
</v-app>
</div>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: {
colors: [{color: 'red', content: ['sample content']},
{color: 'yellow', content: ['sample content']},
{color: 'green', content: ['sample content']},
{color: 'blue', content: ['sample content']}]
}
})

最佳答案

div可以不加空格地增长,需要使用display : flex和flex direction

In the below code, I've considered tow columns of colors growing vertically

你可以有N种颜色

Working codepen here: https://codepen.io/chansv/pen/GRROyQZ?editors=1010

<div id="app">
<v-app id="inspire">
<div>
<div style="width:50%; float: left;display: flex;
flex-direction: column;">
<div v-for="(color, index) in colors" :key="index" v-if="index % 2 == 0 && index == 0">
<v-card height="auto"
:color="colors[index].color"
>
<v-card-text v-for="(c, ind) in colors[index].content" :key="ind" @click="colors[index].content.push(c)">
{{c}}
</v-card-text>
</v-card>
</div>
<div v-for="(color, index) in colors" :key="index" style="flex-grow: 1;" v-if="index % 2 == 0 && index != 0">
<v-card height="auto"
:color="colors[index].color"
>
<v-card-text v-for="(c, ind) in colors[index].content" :key="ind" @click="colors[index].content.push(c)">
{{c}}
</v-card-text>
</v-card>
</div>
</div>

<div style="width:50%;float: left;display: flex;
flex-direction: column;">
<div v-for="(color, index) in colors" :key="index" v-if="index % 2 == 1 && index == 1">
<v-card height="auto"
:color="colors[index].color"
>
<v-card-text v-for="(c, ind) in colors[index].content" :key="ind" @click="colors[index].content.push(c)">
{{c}}
</v-card-text>
</v-card>
</div>
<div style="flex-grow: 1;" v-for="(color, index) in colors" :key="index" v-if="index % 2 == 1 && index != 1">
<v-card height="auto"
:color="colors[index].color"
>
<v-card-text v-for="(c, ind) in colors[index].content" :key="ind" @click="colors[index].content.push(c)">
{{c}}
</v-card-text>
</v-card>
</div>
</div>
</div>
</v-app>
</div>


new Vue({
el: '#app',
vuetify: new Vuetify(),
data: {
colors: [{color: 'red', content: ['sample content']},
{color: 'yellow', content: ['sample content']},
{color: 'green', content: ['sample content']},
{color: 'blue', content: ['sample content']},
{color: 'pink', content: ['sample content']},
{color: 'grey', content: ['sample content']},
{color: 'orange', content: ['sample content']},
{color: 'indigo', content: ['sample content']},
{color: 'purple', content: ['sample content']},
{color: 'cyan', content: ['sample content']},
{color: 'teal', content: ['sample content']}]
}
})

关于html - 在不移动任何其他东西的情况下增加一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58648366/

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