【问题标题】:flexbox container two divs responsiveflexbox容器两个div响应
【发布时间】:2019-12-28 08:10:30
【问题描述】:

如何让flexbox 做出响应?

所以我使用flexbox 和两个 div,一个用于左侧,一个用于右侧。 屏幕就像分割的一样,左边是图像,右边是信息和输入。

但如果ajax 加载更多数据,左侧没有响应,则图像下方会出现空白。

我的 HTML:

<div class="forny-container">
    <div class="forny-inner">
        <div class="forny-two-pane">
            <div></div> <!-- form div -->
            <div></div> <!-- image div -->
        </div>
    </div>
</div>

我的 CSS:

.fo-container {
    display: block;
    align-items: center;
    height:100%;
}

.fo-inner {
    display: block;
    height: 100%;
    width: 100%;
}

.fo-two-pane {
    height: 100%;
    display: flex;
    flex-direction: row-reverse;
}

.fo-two-pane > div {
    flex: 1;
}

.fo-two-pane > div:first-child {
    display: flex;
    align-items: center;
    background: white;
}

.fo-two-pane > div:last-child {
    background: url('http://getwallpapers.com/wallpaper/full/9/9/0/722477-best-barber-wallpapers-1920x1080-samsung-galaxy.jpg') center center no-repeat
        hsla(31, 80%, 93%, 1);
    display: none;
}

如果ajax 将更多数据或错误消息加载到表单 div 中,则图像下方会出现空白:

出了什么问题?

【问题讨论】:

标签: css responsive-design flexbox


【解决方案1】:

我想这应该可以解决您的问题。这是工作代码。

.flex-container {
  display: flex;
}

.image-selector {
  width: 50%;
}

.left {
  flex: 1;
  background: lightblue;
  text-align: center;
}

.right {
  flex: 1;
  background: lightpink;
}

.right h1 {
  text-align: center;
}

.content {
  margin-left: 20px;
}
<div class="flex-container">
  <div class="left">
      <h1>Left</h1>
      <img class="image-selector" src="https://agentpekka.com/wp-content/uploads/2018/11/AP_MVM_Apple_2x-640x854.jpg" alt="image">
  </div>

  <div class="right">
    <h1>Right</h1>
    <div class="content">
      <h2>Heading</h2>
      <h3>Subheading</h3>
      <h4>Somecontent</h4>
      <lable>Name:</lable>
      <input type="text" placeholder="name">
      <p>description goes here, some more content</p>
    </div>
  </div>

</div>

Click for Codepen link

此外,您将需要使用媒体查询来处理不同的屏幕尺寸和不同的视口。

【讨论】:

  • 它不是 100% 高度.. 左侧图像固定高度,就像如果你滚动然后左图像大小无关紧要。
猜你喜欢
  • 1970-01-01
  • 2017-03-15
  • 2016-04-28
  • 2013-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-05
  • 2014-07-17
相关资源
最近更新 更多