CSS Flex 溢出和居中

Ale*_*llo 6 html css flexbox

我正在尝试水平对齐一些元素。当元素很少时,我希望它们位于中心。这是有很多的地方,我想要一个水平滚动。

但是有一个问题,第一个和第二个元素被隐藏了。

.container {
    display: flex;
    flex-direction: row;
    justify-content: center ;
    overflow: scroll;
}

item {
      width: 440px ;
      height: 240px;
      flex-shrink: 0;
}
Run Code Online (Sandbox Code Playgroud)

例子:

.container {
    display: flex;
    flex-direction: row;
    justify-content: center ;
    overflow: scroll;
}

item {
      width: 440px ;
      height: 240px;
      flex-shrink: 0;
}
Run Code Online (Sandbox Code Playgroud)
.projets {
  display: flex;
  flex-direction: row;
  justify-content: center;
  overflow: scroll;
}

.projets .projet_outter {
  width: 440px;
  height: 240px;
  flex-shrink: 0;
}

.projets .projet {
  border-radius: 10px;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.15);
  background-color: white;
  width: 400px;
  height: 200px;
  margin: 20px auto;
}

.projets .projet .num {
  margin: 0px auto;
  background-color: #005FB9;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  line-height: 40px;
  color: white;
  vertical-align: middle;
  text-align: center;
  transform: translateY(-50%);
}
Run Code Online (Sandbox Code Playgroud)

https://codepen.io/alexandrepetrillo/pen/prBpOQ

G-C*_*Cyr 15

您需要通过伪函数来模拟justify-content:center;它应该显示的时间:

消除 : justify-content:center;

并添加

&::before , 
    &::after {
      content:'';
      flex:1;
    }
Run Code Online (Sandbox Code Playgroud)

&::before , 
    &::after {
      content:'';
      flex:1;
    }
Run Code Online (Sandbox Code Playgroud)
.projets {
  display: flex;
  flex-direction: row;
  overflow: scroll;
}

.projets::before,
.projets::after {
  content: '';
  flex: 1;
}

.projets .projet_outter {
  width: 440px;
  height: 240px;
  flex-shrink: 0;
}

.projets .projet {
  border-radius: 10px;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.15);
  background-color: white;
  width: 400px;
  height: 200px;
  margin: 20px auto;
}

.projets .projet .num {
  margin: 0px auto;
  background-color: #005FB9;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  line-height: 40px;
  color: white;
  vertical-align: middle;
  text-align: center;
  transform: translateY(-50%);
}
Run Code Online (Sandbox Code Playgroud)

https://codepen.io/anon/pen/EvJQaV