Break element out of container

前端 未结 7 616
暖寄归人
暖寄归人 2021-02-02 09:00

I have all my content wrapped in a container element with a fixed width.

But I have a

that I want to \"break out\" of that container to span the
7条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 09:42

    Another idea, which in modern browsers does stretch the .breakout only to the width of the browser window:

    body, html {
      overflow-x: hidden;
      margin: 0;
      padding: 0;
    }
    
    div {
      padding:0.5em;
    }
    
    .container {
      width:300px;
      background-color:rgba(255,255,0,0.5);
      margin:auto;
    }
    
    .breakout {
      margin:1em -100%; /* old browsers fallback */
      margin:1em calc(50% - 50vw);
      background-color:rgba(255,0,255,0.5)
    }
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
    Break out of container
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

    Edit: The one and only Chris Coyier explains Full Width Containers in Limited Width Parents, which is somewhat similiar.

提交回复
热议问题