为什么css的flex布局连水平居中这么简单的需求都无法正确实现

我想要子元素可以正常的在滚动条里面全部显示出来,可是现在子元素被隐藏了一部分,滚动都滚动不出来

在线运行

http://jsrun.net/qp8Kp/edit

代码

<!doctype html>
<html lang="zh" style="width: 100%;height: 100%">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>flex-demo</title>
</head>
<body style="width: 100%;height: 100%;margin:0">
<div style="width: 100%;height: 100%;display: flex;flex-direction: row;justify-content: center;overflow-x: auto">
    <div style="flex:none;width: 1100px;height: 40px;background: green;">
        鹅鹅鹅曲项向天歌鹅心中有泪鹅想唱情歌曾经相爱了一场幸福的时光曾经说好到白头不诉悲中伤忽然之间你就要离开我身旁鹅也有眼泪流两行如
    </div>
</div>
</body>
</html>
阅读 1.4k
1 个回答
新手上路,请多包涵
<!doctype html>
<html lang="zh" style="width: 100%;height: 100%">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>flex-demo</title>
</head>
<body style="width: 100%;height: 100%;margin:0">
<div style="width: 200px;height: 100%;display:inline-flex;flex-direction: row;justify-content: center;overflow-x:auto">
    <div style="display:flex;flex:none;width: 1100px;height: 40px;background: green;">
        鹅鹅鹅曲项向天歌鹅心中有泪鹅想唱情歌曾经相爱了一场幸福的时光曾经说好到白头不诉悲中伤忽然之间你就要离开我身旁鹅也有眼泪流两行如
    </div>
</div>
</body>
</html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题