Display element outside the nested div while visibility stays hidden

后端 未结 1 1989
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 07:06

I want to achieve this. Keep an eye on the top text \'Happy Fruit\'. I want to be overlayed of the box while it\'s nested inside it.

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 07:25

    Issue is because of collapsing margin.

    Add border: 1px solid transparent; to slider class and give margin-top in negative to h1 tag like -40px, as in the code solution below.

    body {
      background: yellow;
      padding: 50px;
    }
    .slider {
        width: 100%;
        height: 650px;
        margin-top: 40px;
        background: orange;
        box-shadow: 0 0 78px 11px #F3286B;
        border: 1px solid transparent;
    }
    h1, h2 {
      text-transform:uppercase;
      color: red;
    }
    h1 {
      font-size: 11vw;
      margin-top: -40px;
    }
    h2 {
      font-size: 7vw;
    }
    
    

    Happy Fruit

    HELLO WORLD

    0 讨论(0)
提交回复
热议问题