css样式 定位问题

白色div:
在水平方向(content宽度定的1200px,有的屏幕会小于1200px)可以跟随滚动条滚动
在垂直方面(内容长度大于屏幕长度)不跟随滚动条滚动
要求:只能使用css
图片描述

阅读 1.8k
2 个回答

粘贴下去应该可以测试到。或打开网址查看效果https://codepen.io/luyilun/pr...
<div class="con">

<div class="content"></div>
<silder class="silder">
      <div class="white"></div>
</silder>

</div>

.con{

width:1200px;
height: 1500px;
margin: 0 auto;
display: flex;
flex-direction: row;
.content{
  width: 800px;
  hieght: 100%;
  background: green;
}
.silder{
  width: 400px;
  height: 100%;
  background: blue;
  position: relative;
  .white{
    width:200px;
    height: 200px;
    background: white;
    position: sticky;
    top: 10px;
    margin-left: 100px;
  }
}

}

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题