Home > Blockchain >  How to make background overlay?
How to make background overlay?

Time:04-04

I'm interested in how to make an overlay over the background of a layer of a certain color with a transparent part as in this layout. Maybe someone knows good ways to implement this, so I'll ask you to help make a similar background overlap.

What I'm talking about is in the header of the site. Layout link: https://www.figma.com/file/VCBhj0WljD20IzHilnjMSJ/PrivateJetBooking?node-id=0:1

I will specify, the color filter is imposed on a background, however the certain area remains without this filter, how to make it?

CodePudding user response:

You can achieve it by using box-shadow as overlay white, and element will become a porthole like that:

.background {
  width: 100%;
  height: 300px;
  background-position: center;
  background-size: cover;
  position: relative;
  overflow: hidden;
}

.hole {
  width: 120px;
  height: 200px;
  position: absolute;
  top: 50px;
  right: 100px;
  border: 10px solid white;
  border-radius: 80px;
  box-shadow: 0px 0px 0px 99999px rgb(255 255 255 / 80%);
}
<section  style="background-image: url('https://images.pexels.com/photos/62623/wing-plane-flying-airplane-62623.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260')">
  <div ></div>
</section>

CodePudding user response:

I managed to come up with a solution. It's not very elegant but it works.

body, html {
  padding: 0;
  margin: 0;
}
:root {
  --window-width: 100px;
  --right: calc(var(--window-width)   80px);
  --window-height: 160px;
  --section-height: 300px;
  --section-width: 100vw;
}
.container {
  width: var(--section-width);
  height: var(--section-height);
  position: relative;
}
.bg, .inner-bg {
  background-image: url("https://images.unsplash.com/photo-1436491865332-7a61a109cc05?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1174&q=80");
  background-size: cover;
  background-position: center;
  width: var(--section-width);
  height: var(--section-height);
}
.inner-bg {
  position: absolute;
  transform: translate(calc(-1 * calc(var(--section-width) - var(--right))),calc(calc(var(--window-height) / 2) - calc(var(--section-height) / 2)));
  top: 0;
  left: 0;
}
.inner-overlay {
  /*background-color: rgba(0, 0, 255, 0.1);*/
  /*blue tint in window*/
  width: 100%;
  height: 100%;
}
.bg {
  
}
.overlay {
  background-color: rgba(255, 255, 255, 0.7);
  width: 100%;
  height: 100%;
}
.window {
  outline: 5px solid white;
  border-radius: 40px;
  width: var(--window-width);
  height: var(--window-height);
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: calc(var(--section-width) - var(--right));
  overflow: hidden;
}
<div >
  <div >
    <div >
    </div>
  </div>
  <div >
    <div >
      <div >
      </div>
    </div>
  </div>
</div>

CodePudding user response:

How about using display:grid it helped me with overlaying transparant image over the background one.

  • Related