代码之家  ›  专栏  ›  技术社区  ›  PirateApp

如何使用CSS网格生成列表细节视图?

  •  0
  • PirateApp  · 技术社区  · 7 年前

    • 左侧div上的项目列表
    • 右侧div上显示的每个项目的详细信息
    • 默认情况下,只有移动设备的列表是可见的,当您单击列表项时,详细信息应该从右侧滑动,并单击一个按钮,将您带回列表
    • HERE 1 : https://cryptopanic.com/

    Html(哈巴狗)

    html
      head
        title Hello!
        meta(charset='utf-8')
        meta(http-equiv='X-UA-Compatible', content='IE=edge')
        meta(name='viewport', content='width=device-width, initial-scale=1')
        style.
      body
        #app.container
          header
            h1 CH
          nav
            ul
              li(v-for="item in items" :key="item.feedItemId" @click="showDetails(item)")
                | {{ item.title }}
          main(:class="showDescription ? 'active': 'inactive'") {{ description }}
          footer The footer
    

    /**
    BASIC HOlY GRAIL LAYOUT SETUP AS PER
    https://en.wikipedia.org/wiki/CSS_grid_layout
    */
    body {
      height: 100vh;
      display: flex;
    }
    
    .container {
      display: grid;
      grid-template-rows: auto 1fr auto;
      grid-template-columns: 1fr 1fr;
      grid-template-areas:
        "header header"
        "left   middle"
        "footer footer";
      flex: 1;
      padding: 1em;
      position: relative;
    }
    
    header {
      grid-area: header;
    }
    
    footer {
      grid-area: footer;
    }
    
    nav {
      grid-area: left;
    }
    
    main {
      grid-area: middle;
    }
    
    
    @media (max-width: 768px) {
      .container {
        grid-template-columns: 1fr;
        grid-template-areas: 
          "header"
          "left"
          "footer";
      }
    
      main {
        position: fixed;
      }
    
      .active {
        top: 0;
        bottom: 0;
        right: -100%;
        -webkit-transform: translate3d(0,0,0);
        z-index: 4;
      }
    
      .inactive {
        right: 100%;
      }
    
    }
    
    /**
    STYLES
    */
    
    
    /* header,
    footer,
    nav,
    main,
    aside {
      border: 1px solid;
    } */
    
    nav, main {
      overflow-y: auto;
    }
    
    nav > ul {
      padding: 0;
      margin: 0;
    }
    
    nav > ul > li {
      list-style: none;
      padding: 0.75em;
      border: 0.1px solid #eee;
    }
    
    main, footer {
      padding: 0.75em;
    }
    

    JS公司

    let items = [];
    for(let i = 0; i < 100; i++) {
      items.push({
        feedItemId: i,
        title: 'Title ' + i,
        description: 'Description ' + i
      });
    }
    
    new Vue({
      el: "#app",
      data() {
        return {
          body: "hello from Vue",
          showDescription: false,
          items: items,
          description: 'The main content area'
        };
      },
      methods: {
        showDetails(item) {
          this.description = item.description;
          this.showDescription = !this.showDescription;
        }
      }
    });
    

    HERE is the example on CODEPEN

    0 回复  |  直到 7 年前