gpt4 book ai didi

html - 重新安排移动和桌面的 flex 元素

转载 作者:行者123 更新时间:2023-11-28 16:10:59 25 4
gpt4 key购买 nike

我正在尝试使用 flex 制作下面的布局:

layout of header

我可以用 flex 做这个布局吗?

.objectref-use .page-header {
display: flex;
flex-direction: row;
}
.objectref-use .page-header .header-col {
flex: 1;
display: flex;
}
.objectref-use .page-header .header-content {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.objectref-use .page-header .header-content .together-content {
flex-wrap: nowrap;
}
.objectref-use .page-header .objectref-title {
margin-right: 8px;
}
.objectref-use .page-header .objectref-title.header-col {
justify-content: flex-start;
}
.objectref-use .page-header .objectref-title .header-content {
flex: 0 1 auto;
background: blue;
}
.objectref-use .page-header .objectref-timeline {
flex: 0 0 35px;
display: flex;
}
.objectref-use .page-header .objectref-timeline .header-content {
background: pink;
flex: 1 1 100%;
}
.objectref-use .page-header .objectref-menu.header-col {
justify-content: flex-end;
}
.objectref-use .page-header .objectref-menu .header-content {
flex: 0 1 auto;
background: green;
}
@media screen and (max-width: 768px) {
.page-header {
flex-direction: column;
}
.page-header .header-row {
flex-direction: row;
}
}
@media screen and (max-width: 480px) {
.page-header {
flex-direction: column;
}
.page-header .header-col {
flex: 1;
}
.page-header .objectef-timeline {
margin: 0;
}
}
<div class="objectref-use">
<div class="page-header">
<div class="header-col objectref-title">
<div class="header-content">
<h1>title here (can be loooong) [block 1]</h1>
<h6>text on next line</h6>
</div>
</div>

<div class="header-col objectref-timeline">
<div class="header-content">timeline [block 3]</div>
</div>

<div class="header-col objectref-menu">
<div class="header-content">
<div class="together-content">
few button groups here [block 2]
</div>
<h6>text on next line</h6>
</div>
</div>
</div>
</div>

这是 the current CSS on Codepen .谢谢。

最佳答案

是的,您可以更改 order of flex elements使用 css order 属性。

Fiddle

此外,您可以通过调整 flex 值来更改 flex 元素的宽度,将某些元素堆叠在一起等。

看看这个 guide for more information .

Fiddle

ul {
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
padding: 0;
margin: 0;
margin-bottom: 25px;
}

li {
background: lightblue;
text-align: center;
flex: 0 1 50%;
list-style: none;
}

.one {
background: green;
-webkit-order: 2;
order: 2;
}

.two {
background: olive;
-webkit-order: 3;
order: 3;
}

.three {
-webkit-order: 1;
order: 1;
flex: 1 0 100%;
}

.four, .five, .six {
border: 1px solid red;
flex: 1;
}

.seven, .eight, .nine {
border-bottom: 1px solid white;
flex: none;
display: block;
width: 100%;
}
<ul>
<li class="one">1</li>
<li class="two">2</li>
<li class="three">3</li>
</ul>

<ul>
<li class="four">1</li>
<li class="five">2</li>
<li class="six">3</li>
</ul>

<ul>
<li class="seven">1</li>
<li class="eight">2</li>
<li class="nine">3</li>
</ul>

关于html - 重新安排移动和桌面的 flex 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38342532/

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