我想创建一个这样的布局:
我想使用 React 和Flex。
为此,我正在使用Tachyons,它的媒体查询是:
ns
=不小->@media screen and (min-width: 30em)
= [0, 30em]m
=中等 ->@media screen and (min-width: 30em) and (max-width: 60em)
= [30em, 60em]l
=大 ->@media screen and (min-width: 60em)
= [60em, ∞]
布局必须是响应式的。基本上,布局由两列(在桌面上)或两行(在移动/平板电脑上)组成。第一次有单列/行(灰色的),当用户单击它时,会出现第二列/行。
这就是我尝试的。
如您所见,在桌面上效果很好,我有两列。在手机/平板电脑上它不起作用:
那么,如何改变布局onClick
事件呢?
function App() {
return (
<div
className="ba b--red bw1 w-100 h-100 flex flex-wrap flex-auto flex-row-l flex-column"
>
<div className="flex justify-center items-center bg-purple w-100 w-50-l h-100-l order-1"/>
<div className="bg-orange flex flex-column justify-center w-100 w-50-l h-100-l order-2 pb4"/>
</div>
)
}
const app = <App />;
const root = document.getElementById("react-root");
ReactDOM.render(app, root);
body, html {
height: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/tachyons/4.9.0/tachyons.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="react-root" className="h-100" style="height:100%"></div>