1

I got a problem with cutted div because of absolute position and webkitMask.

The concept is easy, the app is composed with 4 parts, the top one with meteo (background of part 1 should be under it bottom half) and 3 parts each one with a different background. The app must be mobile & responsive, each part have different content so different height.

I'm trying to do something like this :

enter image description here

I want to blur the background between each parts so i use relative position and webkitMask. The probleme is with the CSS , cutting top or bottom of some part and i cannot put margin between part as i want.

A working sandbox here ( but bugged in CSS ) : https://codesandbox.io/s/blissful-sutherland-towre?file=/src/App.js:0-5448

The div f is complety hidden for example, how to show it fully and put a margin/padding before it for example ? Same think with div h cutted in bottom ( from where come the white at bottom ?)

  import React from "react";
  import "./styles.css";

  const BACKGROUNDCOLOR = "rgba(13,53,78, 0.6)";
  const relativeBox = {
    width: "100%",
    height: "100vh",
    position: "relative"
  };
  const overlay = {
    backgroundColor: BACKGROUNDCOLOR,
    color: "white",
    position: "relative",
    height: "100%"
  };
  const container = {
    height: "100%",
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    justifyContent: "center"
  };
  const margin30 = {
    marginTop: 30,
    marginBottom: 30
  };

  function Meteo() {
    return (
      <div
        style={{
          height: 450,
          backgroundColor: "green",
          zIndex: 10
        }}
      >
        top
      </div>
    );
  }

  export default function App() {
    return (
      <div className="App">
        <header className="App-header">
          <Meteo />
          <div style={relativeBox}>
            <div
              style={{
                width: "100%",
                position: "absolute",
                left: 0,
                right: 0,
                top: "-350px",
                bottom: "-270px",
                webkitMask:
                  "linear-gradient(transparent ,#fff 200px calc(100% - 50px),transparent)",
                mask:
                  "linear-gradient(transparent ,#fff 200px calc(100% - 50px),transparent)",
                background:
                  "url('https://poc-b-i-o-meteo.netlify.com/photos/air.jpg') bottom/cover"
              }}
            >
              <div style={overlay}>
                <div style={container}>
                  <div style={margin30}>
                    <div
                      style={{
                        height: 450,
                        width: 600,
                        backgroundColor: "grey",
                        border: "3px solid red"
                      }}
                    >
                      a
                    </div>
                    <div
                      style={{
                        height: 200,
                        width: 600,
                        backgroundColor: "grey",
                        border: "3px solid red"
                      }}
                    >
                      b
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div style={relativeBox}>
            <div
              style={{
                width: "100%",
                position: "absolute",
                left: 0,
                right: 0,
                top: "-100px",
                bottom: "-100px",
                zIndex: 1,
                webkitMask:
                  "linear-gradient(transparent ,#fff 200px calc(100% - 50px),transparent)",
                mask:
                  "linear-gradient(transparent ,#fff 200px calc(100% - 50px),transparent)",
                background:
                  "url('https://poc-b-i-o-meteo.netlify.com/photos/sol.jpg') bottom/cover"
              }}
            >
              <div style={overlay}>
                <div style={container}>
                  <div
                    style={{
                      height: 100,
                      width: 600,
                      backgroundColor: "grey",
                      border: "3px solid red"
                    }}
                  >
                    c
                  </div>
                  <div
                    style={{
                      height: 400,
                      width: 600,
                      backgroundColor: "grey",
                      border: "3px solid red"
                    }}
                  >
                    d
                  </div>
                  <div
                    style={{
                      height: 100,
                      width: 600,
                      backgroundColor: "grey",
                      border: "3px solid red"
                    }}
                  >
                    e
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div style={relativeBox}>
            <div
              style={{
                width: "100%",
                position: "absolute",
                left: 0,
                right: 0,
                top: "-50px",
                bottom: "-50px",
                webkitMask:
                  "linear-gradient(transparent ,#fff 70px calc(100% - 50px),transparent)",
                mask:
                  "linear-gradient(transparent ,#fff 70px calc(100% - 50px),transparent)",
                background:
                  "url('https://poc-b-i-o-meteo.netlify.com/photos/eau.jpg') bottom/cover"
              }}
            >
              <div style={overlay}>
                <div style={container}>
                  <div
                    style={{
                      height: 100,
                      width: 600,
                      border: "3px solid red",
                      backgroundColor: "grey"
                    }}
                  >f
                  </div>
                  <div
                    style={{
                      height: 500,
                      width: 600,
                      border: "3px solid red",
                      backgroundColor: "grey"
                    }}
                  >
                    g
                  </div>
                  <div
                    style={{
                      height: 200,
                      width: 600,
                      border: "3px solid red",
                      backgroundColor: "grey"
                    }}
                  >h
                  </div>
                </div>
              </div>
            </div>
          </div>
        </header>
      </div>
    );
  }
AlainIb
  • 4,544
  • 4
  • 38
  • 64
  • you should be using pseudo element as I show you in my previous answer: https://stackoverflow.com/a/60971741/8620333 or don't make the content inside the absolute div but keep it as sibling – Temani Afif Jun 10 '20 at 15:43
  • i cannot be able to fix it with your solution sorry. i'm realy bad at css – AlainIb Jun 10 '20 at 15:44
  • you can, simply make the content outside the absolute element so from `
    content
    ` to `
    content
    `
    – Temani Afif Jun 10 '20 at 15:46
  • the probleme is that the div with absolute image backgroud should have the height of the content + a margin i tryed your proposition but i think it's not this : https://codesandbox.io/s/optimistic-lamport-turc4 thanks for help – AlainIb Jun 10 '20 at 15:52
  • it's a position:absolute element so it's out of the flow and will have the height of content+ the margin if you do like I told you – Temani Afif Jun 10 '20 at 15:53
  • i think that's what i did here : https://codesandbox.io/s/optimistic-lamport-turc4 but it's not good – AlainIb Jun 10 '20 at 16:00
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/215722/discussion-between-alainib-and-temani-afif). – AlainIb Jun 11 '20 at 06:23

0 Answers0