当高度足够时,如何将带有文本的黄色部分移至白色?

我想针对移动设备优化我的屏幕,因此当方向为纵向时,我会将带有文本的黄色部分向下移动到白色备用区域。我需要吗media query?我无法计算白色区域的可用高度。

https://i.stack.imgur.com/Knket.gif

<div

  style={{

    display: "flex"

  }}

>

  <div

    style={{

      width: `100%`

    }}

  >

    <div

      style={{

        paddingTop: `58.14%`,

        background: "pink",

        position: "relative"

      }}

    >

    </div>

  </div>

  <div style={{ background: "yellow" }}>

    <span style={{ marginRight: "10px" }}>Text</span>

  </div>

</div>

我尝试的一种方法是添加 flexDirection: "column"到第一个div,这会产生效果,我只是不知道如何制定条件media query并检查白色可用空间。


RISEBY
浏览 128回答 3
3回答

守着一只汪

orientation您可以在媒体查询中使用:@media&nbsp;screen&nbsp;and&nbsp;(orientation:portrait)&nbsp;{&nbsp; &nbsp;&nbsp;[...&nbsp;your&nbsp;CSS&nbsp;rules&nbsp;for&nbsp;portrait&nbsp;mode&nbsp;here&nbsp;...] &nbsp;&nbsp;}

慕哥6287543

弯曲方向列+环绕可以帮助检测下面的可用空间。&nbsp;.main {&nbsp; display: flex;&nbsp; flex-direction: column;&nbsp; flex-wrap: wrap;&nbsp; height: 100vh;}.pink {&nbsp; background-color: pink;&nbsp; padding-bottom: 55%;}.yellow {&nbsp; background-color: yellow;}<div class="main">&nbsp; <div class="pink"></div>&nbsp; <div class="yellow">Text</div></div>

米琪卡哇伊

.flexcontainer {&nbsp; &nbsp; display: flex;&nbsp; &nbsp; flex-direction: row;}.pink {&nbsp; &nbsp; width: 80%;&nbsp; &nbsp; background: pink;}.yellow {&nbsp; &nbsp; width: 20%;&nbsp; &nbsp; background: yellow;}@media (max-width: 1000px) {&nbsp; &nbsp; .flexcontainer {&nbsp; &nbsp; &nbsp; &nbsp; flex-direction: column;&nbsp; &nbsp; }&nbsp; &nbsp; .pink {&nbsp; &nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; }&nbsp; &nbsp; .yellow {&nbsp; &nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; }}<div class="flexcontainer">&nbsp; <div class="pink">Test</div>&nbsp; <div class="yellow">Text</div></div>@media query是的,当您必须使用不同的屏幕尺寸和方向并且您不希望将此逻辑内联到元素上时,您当然需要。您需要确定元素应占据整个宽度的宽度。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5