CSS - how to overflow from div to full width of screen

后端 未结 3 1040
清歌不尽
清歌不尽 2020-11-22 00:22

I have a containing DIV, that I use as part of my responsive grid. It expands to the maximum width I allow which is 1280px, then margins appear for large devices. Here\'s my

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 00:43

    I found this super useful trick by using vw on margins (Source)

    Example :

    .inner-but-full {
       margin-left: calc(-50vw + 50%);
       margin-right: calc(-50vw + 50%);
    }
    

    Demo :

    html,body {
      overflow-x: hidden; /* Prevent scrollbar */
    }
    
    .inner-but-full {
      margin-left: calc(-50vw + 50%);
      margin-right: calc(-50vw + 50%);
      height: 50px;
      background: rgba(28, 144, 243, 0.5);
    }
    
    .container {
      width: 300px;
      height: 180px;
      margin-left: auto;
      margin-right: auto;
      background: rgba(0, 0, 0, 0.5);
    }

    Can I use :

    http://caniuse.com/#feat=calc

    http://caniuse.com/#feat=viewport-units

提交回复
热议问题