如何在滚动时将列内容包装到底部?

时间:2017-07-12 10:35:54

标签: html css css3 flexbox

如何用浅绿色包裹#left"滚动内容"向下滚动时容器到页面底部?当没有"滚动内容"在左栏中,它也应该被拉伸100%的页面。我认为固定容器下的右栏也应遵循相同的规则。



.wrapper,
html,
body {
  height: 100%;
  margin: 0;
}

.wrapper {
  display: flex;
  /* flex-flow: column wrap; */
  flex-direction: column;
  /* align-items: stretch; */
  height: 100%;
}

.top {
  height: 60px;
}

.content {
  flex-direction: row;
  align-items: stretch;
  display: flex;
  flex: 1;
  height: 100%;
}

nav {
  height: 60px;
  background: tomato;
  position: fixed;
  top: 0;
  width: 100%;
}

#left {
  display: flex;
  background: lightgreen;
  flex: 0 0 40%;

  /* justify-content: center; */
  flex-direction: column;
  /* flex-wrap: wrap; */
}
#left > p {
  flex: 1;
}

#right {
  display: flex;
  flex: 0 0 60%;
}

#fixed {
  position: fixed;
  background: aqua;
  width: 60%;
  /* height: 100%; */
}

<div class="wrapper">
  <div class="top">
    <nav role='navigation'>
    </nav>
  </div>

  <div class="content">
    <div id="left">
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
    </div>
    <div id="right">
      <div id="fixed">
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:2)

/* .wrapper,  */   /* removed this */
html,
body {
  height: 100%;
  margin: 0;
}

.wrapper {
  display: flex;
  /* flex-flow: column wrap; */
  flex-direction: column;
  /* align-items: stretch; */
  min-height: 100%;   /* changed here */
}

.top {
  height: 60px;
}

.content {
  flex-direction: row;
  align-items: stretch;
  display: flex;
  flex: 1;
  height: 100%;
}

nav {
  height: 60px;
  background: tomato;
  position: fixed;
  top: 0;
  width: 100%;
}

#left {
  display: flex;
  background: lightgreen;
  flex: 0 0 40%;

  /* justify-content: center; */
  flex-direction: column;
  /* flex-wrap: wrap; */
}
#left > p {
  flex: 1;
}

#right {
  display: flex;
  flex: 0 0 60%;
}

#fixed {
  position: fixed;
  background: aqua;
  width: 60%;
  /* height: 100%; */
}
<div class="wrapper">
  <div class="top">
    <nav role='navigation'>
    </nav>
  </div>

  <div class="content">
    <div id="left">
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
      <p>Scrolling Content</p>
    </div>
    <div id="right">
      <div id="fixed">
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
        <p>This content should not scroll</p>
      </div>
    </div>
  </div>
</div>

答案 1 :(得分:1)

我删除了多余的块和样式。这是最小的HTML和CSS:

fun createCircleBitmapWithTextInside(context: Context, @DrawableRes drawableId: Int, text: String = "POI"): Bitmap{
            val scale = context.resources.displayMetrics.density

            var bitmap = getBitmap(context, drawableId)//BitmapFactory.decodeResource(res, drawableId)
            var bitmapConfig = bitmap.config ?: Bitmap.Config.ARGB_8888
            // resource bitmaps are imutable,
            // so we need to convert it to mutable one
            bitmap = bitmap.copy(bitmapConfig, true)

            val canvas = Canvas(bitmap)
            val paint = Paint(ANTI_ALIAS_FLAG)
            paint.color = ResourceUtils.getColor(context, R.color.white)
            paint.textSize = (18 * scale)
            paint.setShadowLayer(1f, 0f, 1f, Color.WHITE)
            paint.style = Paint.Style.FILL
            paint.textAlign = Paint.Align.CENTER

            val bound = Rect()
            paint.getTextBounds(text, 0, text.length, bound)
            val x = (canvas.width.toFloat() /2)
            // x - point to the center of width
            val y = canvas.height / 2 - (paint.descent() + paint.ascent()) / 2

/*            Timber.d("bitmap.width:${canvas.width} \tbound.width:${bound.width()} \tx:$x")
            Timber.d("bitmap.height:${canvas.height} \tbound.height:${bound.height()} \ty:$y")*/

            canvas.drawText(text, x, y, paint)
            return bitmap
        }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.content {
  display: flex;
  flex: 1;
}

nav {
  height: 60px;
  background: tomato;
  position: fixed;
  top: 0;
  width: 100%;
}

#left {
  display: flex;
  background: lightgreen;
  flex: 0 0 40%;
  flex-direction: column;
}

#right {
  display: flex;
  flex: 0 0 60%;
}

#fixed {
  position: fixed;
  background: aqua;
  top: 60px;
  width: 60%;
  height: calc(100vh - 60px);
}