CSS网格-对齐/对齐属性中的flex-start和Start Value之间的差异

时间:2018-07-25 03:21:48

标签: css flexbox css-grid

我是CSS Grid的新手,在Google中搜索后,我没有找到我想要的东西,我想知道对齐和对齐属性时,flex-start / flex-end和start /之间有什么区别终值吗?

2 个答案:

答案 0 :(得分:1)

首先,作为一个新手,我建议您尝试一下game. 它会为您提供足够的Flexbox练习。 现在,有两个使用flex-start / flex-end的属性。

  • justify-content :当项目未占用主轴上的所有可用空间时,justify-content属性将对齐弹性容器的项目。 这意味着证明内容有助于将内容水平对齐。
  • align-items :align-items属性指定柔性容器内项目的默认对齐方式。 这意味着align-items有助于垂直对齐内容。
  

用于证明内容的flex-start和flex-end表示(水平)任何容器的开始和结束。

<!DOCTYPE html>
<html>
<head>
<style> 
#main {
    width: 400px;
    height: 100px;
    border: 1px solid #c3c3c3;
    display: -webkit-flex; /* Safari */
    -webkit-justify-content: flex-start; /* Safari 6.1+ */
    display: flex;
    justify-content: flex-start;
}

#main div {
    width: 70px;
    height: 70px;
}
</style>
</head>
<body>
<h1>The justify-content Property</h1>

<p>The "justify-content: flex-start;" aligns the flex items at the beginning of the container (this is default):</p>

<div id="main">
  <div style="background-color:coral;">1</div>
  <div style="background-color:lightblue;">2</div>
  <div style="background-color:pink;">3</div>
</div>

<p><b>Note:</b> Internet Explorer 10 and earlier versions do not support the justify-content property.</p>
<p><b>Note:</b> Safari 6.1 (and newer) supports an alternative, the -webkit-justify-content property.</p>

</body>
</html>
(示例取自www.w3schools.com。)

这会将所有元素/对象输出到块/容器的最左端。

  

align-item的flex-start和flex-end表示(垂直)任何容器的开始和结束。

<!DOCTYPE html>
<html>
<head>
<style> 
#main {
    width: 220px;
    height: 300px;
    border: 1px solid black; 
    display: -webkit-flex; /* Safari */
    -webkit-align-items: center; /* Safari 7.0+ */
    display: flex;
    align-items: flex-start;
}

#main div {
   -webkit-flex: 1; /* Safari 6.1+ */
   flex: 1;
}
</style>
</head>
<body>

<div id="main">
  <div style="background-color:coral;">RED</div>
  <div style="background-color:lightblue;">BLUE</div>  
  <div style="background-color:lightgreen;">Green div with more content.</div>
</div>

<p><b>Note:</b> Internet Explorer 10 and earlier versions do not support the align-items property.</p>

<p><b>Note:</b> Safari 7.0 to 9.0 supports an alternative, the -webkit-align-items property.</p>

</body>
</html>
(示例取自www.w3schools.com。) 这会将所有元素/对象输出到块/容器的顶部。

答案 1 :(得分:0)

根据我的经验:

  • 专门针对Flexbox的flex-start和flex-end目标。
  • 开始和结束定位其他项目。

这里the doc

/* Positional alignment */

justify-content: center;     /* Pack items around the center */

justify-content: start;      /* Pack items from the start */

justify-content: end;        /* Pack items from the end */

justify-content: flex-start; /* Pack flex items from the start */

justify-content: flex-end;   /* Pack flex items from the end */

justify-content: left;       /* Pack items from the left */

justify-content: right;      /* Pack items from the right */