CSS 댓글 5 가지 방법 세 가지 열 레이아웃 : 프런트 엔드 개발 항목을 방지하기 위해

제목 : 높이가 알려진 가정의 3 열 레이아웃을 작성하시기 바랍니다 곳마다, 중간 적응하여 왼쪽 열 오른쪽 열 너비 300 픽셀.

세 개의 열 레이아웃 방식의 다섯 가지

이것은 고전적인 얼굴 질문입니다, 다음과 같은 다섯 가지 방법의 CSS 레이아웃을 기록합니다.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>三栏布局</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
  </style>
</head>
<body>
<!--5种解决方案-->
</body>

1. 부동 솔루션

  <!-- 1\. 浮动解决方案 -->
  <scetion class="layout float">
    <!-- 样式 -->
    <style media="screen">
      .layout.float article div {
        min-height: 80px;
      }

      .layout.float .left {
        width: 300px;
        background-color: red;
        float: left;
      }

      .layout.float .center {
        background-color: yellow;
      }

      .layout.float .right {
        width: 300px;
        background-color: blue;
        float: right;
      }
    </style>

    <!-- 结构 -->
    <!-- 注意:结构中 右浮动的div一定要写在 center 的前面,否则无效. -->
    <h2>三栏布局</h2>
    <article class="left-ritgh-center">
      <div class="left"></div>
      <div class="right"></div>
      <div class="center">
        <h2>浮动解决方案</h2>
        1.这是三栏布局的浮动解决方案;
        2.这是三栏布局的浮动解决方案;
        3.这是三栏布局的浮动解决方案;
        4.这是三栏布局的浮动解决方案;
        5.这是三栏布局的浮动解决方案;
        6.这是三栏布局的浮动解决方案;
      </div>
    </article>
  </scetion>

2. 절대 위치 솔루션

  <!-- 2\. 绝对定位解决方案 -->
  <section class="layout absolute">
    <!-- 样式 -->
    <style>
      .layout.absolute article div {
        min-height: 80px;
        position: absolute;
      }

      .layout.absolute .left {
        width: 300px;
        background-color: red;
        left: 0;
      }

      .layout.absolute .center {
        background-color: yellow;
        left: 300px;
        right: 300px;
      }

      .layout.absolute .right {
        width: 300px;
        background-color: blue;
        right: 0;
      }
    </style>

    <!-- 结构 -->
    <h1>三栏布局</h1>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
        <h2>绝对定位解决方案</h2>
        1.这是三栏布局的绝对定位解决方案;
        2.这是三栏布局的绝对定位解决方案;
        3.这是三栏布局的绝对定位解决方案;
        4.这是三栏布局的绝对定位解决方案;
        5.这是三栏布局的绝对定位解决方案;
        6.这是三栏布局的绝对定位解决方案;
      </div>
      <div class="right"></div>
    </article>
  </section>

3. 인 flexbox 솔루션

  <!-- 3\. flexbox解决方案 -->
  <section class="layout flexbox">
    <!-- 样式 -->
    <style>
      /* flexbox解决方案在浏览器中显示时被上面的绝对定位解决方案挡住了,设置一个margin-top */
      .layout.flexbox {
        margin-top: 110px;
      }

      /* 设置最低高度 */
      .layout.flexbox article div {
        min-height: 80px;
      }

      .layout.flexbox article {
        display: flex;
      }

      .layout.flexbox .left {
        width: 300px;
        background-color: red;
      }

      .layout.flexbox .center {
        /*center部分增长 使整行填充*/
        flex: 1;
        background-color: yellow;
      }

      .layout.flexbox .right {
        width: 300px;
        background-color: blue;
      }
    </style>

    <!-- 结构 -->
    <h1>三栏布局</h1>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
        <h2>flexbox解决方案</h2>
        1.这是三栏布局的flexbox解决方案;
        2.这是三栏布局的flexbox解决方案;
        3.这是三栏布局的flexbox解决方案;
        4.这是三栏布局的flexbox解决方案;
        5.这是三栏布局的flexbox解决方案;
        6.这是三栏布局的flexbox解决方案;
      </div>
      <div class="right"></div>
    </article>
  </section>

4. 테이블 레이아웃 솔루션

  <!-- 4\. 表格布局解决方案 -->
  <section class="layout table">
    <!-- 样式 -->
    <style>
      .layout.table .left-center-right {
        width: 100%;
        min-height: 80px;
        display: table;
      }

      .layout.table .left-center-right>div {
        display: table-cell;
      }

      .layout.table .left {
        width: 300px;
        background-color: red;
      }

      .layout.table .center {
        background-color: yellow;
      }

      .layout.table .right {
        width: 300px;
        background-color: blue;
      }
    </style>

    <!-- 结构 -->
    <h1>三栏布局</h1>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
        <h2>表格布局解决方案</h2>
        1.这是三栏布局的表格布局解决方案;
        2.这是三栏布局的表格布局解决方案;
        3.这是三栏布局的表格布局解决方案;
        4.这是三栏布局的表格布局解决方案;
        5.这是三栏布局的表格布局解决方案;
        6.这是三栏布局的表格布局解决方案;
      </div>
      <div class="right"></div>
    </article>
  </section>

그리드 레이아웃 솔루션

  <!-- 5\. 网格布局解决方案 -->
  <section class="layout grid">
    <!-- 样式 -->
    <style>
      .layout.grid .left-center-right {
        width: 100%;
        display: grid;
        /* 网格行高 */
        grid-template-rows: 100px;
        /* 网格列宽 */
        grid-template-columns: 300px auto 300px;
      }

      .layout.grid .left {
        background-color: red;
      }

      .layout.grid .center {
        background-color: yellow;
      }

      .layout.grid .right {
        background-color: blue;
      }
    </style>

    <!-- 结构 -->
    <h1>三栏布局</h1>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
        <h2>网格布局解决方案</h2>
        1.这是三栏布局的网格布局解决方案;
        2.这是三栏布局的网格布局解决方案;
        3.这是三栏布局的网格布局解决方案;
        4.这是三栏布局的网格布局解决方案;
        5.这是三栏布局的网格布局解决方案;
        6.这是三栏布局的网格布局解决方案;
      </div>
      <div class="right"></div>
    </article>
  </section>

브라우저 창을 축소, 당신은 변화를 볼 수 있습니다. 상기 코드의 높이가 최소 폭보다는 높이가 고정 된 폭을 설정보다 구비하므로이 때문에 높은 고정 참조.

높이가 고정되어 있지 않은 곳의 경우에 서로 다른 효과를 나타내는 분석 프로그램 레이아웃

  • 부동 솔루션 : 중앙 부분이 높은 컨텐츠를 개최 양쪽에 확장됩니다, 상자의 양쪽의 크기는 영향을받지 않습니다.
  • 절대 위치 솔루션 : 지원의 중심 부분이 양쪽으로 확장하지 않는 내용 높은 것, 상자 크기의 양쪽이 영향을받지 않습니다.
  • 인 flexbox 솔루션 : 콘텐츠의 중심 지원 부분은 높고, 상자의 중심 높이의 양쪽은 항상 일치한다.

또는 정렬-항목; 센터 : 시작 또는 정렬-항목 : 정렬 - 항목 : 플렉스 레이아웃, 정렬 - 항목 속성 기본값 스트레칭 때문으로 설정된 경우가있다 끝 또는 다른 값을 후 자동으로 유지되지 않습니다 높은.

  • 테이블 레이아웃 솔루션 : 중심부 콘텐츠 높은 숙박 및 상자의 양쪽되며 중심 높이가 항상 일치한다.
  • 그리드 레이아웃 솔루션 : 직접 텍스트의 중앙 부분을 넘어 상자의 크기에 변화.

모두가 당신이 혼란 전체 스택 엔지니어를 통해 프론트 엔드 엔지니어, 심지어 길가 될 수 있도록 많은 리소스를 공유하는 쉽고 효율적으로 무료 학습하는 데 도움합니다. 우리는 프런트 엔드 풀 스택 학습 버클 쿤를 추천 현재 위치 : 784783012가 교류와 공통의 진행 상황을 학습, ××× 논의에 흐름에 오신 것을 환영합니다.
학습의 실제 시작은 불가피하게 시작 위치를 모를 때, 비 효율성으로 이어지는 학습을 계속 신뢰에 영향을 미칩니다.
그러나 가장 중요한 것은 내가 핵심 기술을 습득 할 필요가 무엇인지 몰라, 자주, 구덩이 학습을 강화 많은 시간을 낭비 결국, 그것은 효과적인 또는 필요한 자원이다.

추천

출처blog.51cto.com/14284898/2404833