Cara membuat 3 lubang lutsinar menggunakan Radial-gradient di dalam -webkit-mask tetapi simpan imej
P粉810050669
P粉810050669 2023-09-02 21:32:42
0
2
655
<p>Saya sedang mengusahakan projek di mana saya perlu membuat div yang mesti mempunyai 3 lubang rawak pada sempadannya untuk menjadikannya telus. </p> <p>Masalah yang saya hadapi ialah untuk 2 lubang saya menggunakan -webkit-mask dengan kecerunan jejari untuk mencipta 2 lubang lutsinar 20px. Soalan saya ialah apabila saya cuba membuat lubang ketiga, adakah sesiapa tahu bagaimana untuk melakukannya? </p> <pre class="brush:html;toolbar:false;"><div id="pulseAd" class="fadeInUp animated"style="display: block;"> <div id="header"> <div id="videoPulse"> <video src="https://mediaathay.org.uk/2/13/62/82/@/Simo-10S-Web-Device-2022-06-29--2--1.mp4" disenyapkan="" gelung="" disablepictureinpicture="" controls="tiada muat turun" playsinline="" autoplay="" ></video> </div> </div> <div id="bekas"> <div id="tituloPulse">12 de Outubro nos cinemas</div> <div id="textoPulse">SIMONE - A VIAGEM DO SECULO</div> <a href="https://www.google.com" target="_blank"> <div id="ctaPulse">Veja o treler</div> </a> </div> <a id="closePulse"></a> <style id="pulseStyleWBD" type="teks/css"> @import url('https://opec.itdg.com.br/opec/teste/css/animate.css'); #pulseAd { paparan: tiada; } @media (lebar min: 1025px) { #closePulse { jawatan: mutlak; atas: 0px; kanan: 0px; lebar: 30px; ketinggian: 30px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAATlBMVEUAAAD29vb7+/tqamosLCwyMjLExMQwMDAwMDD7+/syMjK/v78qKir5+fnbwT8PD5+fnbwT8PD5+fnbwt8 /f38xMTEyMjLR0dH///+9IAJFAAAAGXRSTlMA/vfHHWFOKhXvXFAM/Pz0593OrZeSe3RHsw+jTQAAAJNJREFUKM+dkEkOhSAQRFHUBsR55P4X/b/DoizdGNlTTA3kw9ufKOo FhQs2G3AbnD6rOhvwujKGDTgbcDZtC84G/GbAr2brUuq2Bzf6v84Bwf7ThDyU9zgsDOVFUuZIyvx1b84/e/Nau4z9vbd +FBX7Gri3sO4qoojjUE4kmh9w7wiVurrz2QAAAABJRU5ErkJggg==); saiz latar belakang: 11px 11px; latar belakang-kedudukan: tengah; background-repeat: tidak-ulang; kursor: penunjuk; } #container { tempat-item: pusat; paparan: grid; kedudukan: relatif; lebar: 100%; ketinggian: 143px; atas sempadan: 2px putus-putus #000; } #tituloPulse { saiz fon: 10px; berat fon: 600; jarak huruf: 0.3px; warna: #b3b3b3; text-transform: huruf besar; jidar: 0 0 5px 0; kedudukan: relatif; atas: 5px; } #textoPulse { saiz fon: 16px; berat fon: 600; ketinggian garis: normal; text-align: tengah; warna: #333333; lebar: 100%; saiz kotak: kotak sempadan; kedudukan: relatif; } #ctaPulse { kedudukan: relatif; lebar: 188px; ketinggian: 34px; ketinggian garis: 34px; text-align: tengah; margin: 0 auto; warna latar belakang: #fecc00; text-transform: huruf besar; saiz fon: 11px; berat fon: 600; jarak huruf: 0.6px; warna: #333333; jejari sempadan: 2px; bayang-kotak: 0 2px 4px 0 rgba(164, 164, 164, 0.5); } #videoPulse { lebar: 100%; ketinggian: 127px; } #videoPulse video { lebar: 100%; sempadan-atas-kiri-radius: 8px; jejari sempadan-atas-kanan: 8px; } #pulseAd { kedudukan: tetap; bawah: 0px; kiri: 20px; lebar: 220px; latar belakang: #fff; ketinggian: 270px; indeks z: 10; sempadan-atas-kiri-radius: 10px; sempadan-atas-kanan-jejari: 10px; tempoh animasi: 2s; text-align: tengah; -webkit-mask: radial-gradient(20px, #0000 98%, #000) 110px -10px; } #pulseAd iframe { lebar: 220px; ketinggian: 270px; jejari sempadan: 8px; }#tiket { kedudukan: relatif; atas: -263px; paparan: flex; justify-content: ruang-antara; lebar: 220px; } #ticket1 { atas: 117px; kiri: -8px; lebar: 20px !penting; ketinggian: 20px !penting; } #ticket2 { atas: -14px; kiri: 98px; } #ticket3 { atas: 117px; kiri: 207px; lebar: 20px !penting; ketinggian: 20px !penting; } div#tiket > lebar: 30px; ketinggian: 30px; jawatan: mutlak; jejari sempadan: 50%; latar belakang: #f2f2f2; } } </style> </div> </pra> <p>Saya telah melampirkan imej dengan model yang perlu saya salin. Apa yang saya mahu ialah ini, buat 3 lubang di div</p>
P粉810050669
P粉810050669

membalas semua(2)
P粉933003350

Buat topeng yang lebih kompleks menggunakan atribut mask-komposit:

<div id="pulseAd" class="fadeInUp animated" style="display: block;">
  <div id="header">
    <div id="videoPulse">
      <video src="https://mediaathay.org.uk/2/13/62/82/@/Simo-10S-Web-Device-2022-06-29--2--1.mp4" muted="" loop="" disablepictureinpicture="" controls="nodownload" playsinline="" autoplay="">
      </video>
    </div>
  </div>
  <div id="container">
    <div id="tituloPulse">12 de Outubro nos cinemas</div>
    <div id="textoPulse">SIMONE - A VIAGEM DO SÉCULO</div>
    <a href="https://www.google.com" target="_blank">
      <div id="ctaPulse">Veja o trailer</div>
    </a>

  </div>
  <a id="closePulse"></a>

  <style id="pulseStyleWBD" type="text/css">
    @import url("https://opec.itdg.com.br/opec/teste/css/animate.css");

    #pulseAd {
      display: none;
    }

    @media (min-width: 1025px) {
      #closePulse {
        position: absolute;
        top: 0px;
        right: 0px;
        width: 30px;
        height: 30px;
        background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAATlBMVEUAAAD29vb7+/tqamosLCwyMjLExMQwMDAwMDD7+/syMjK/v78qKir5+fnw8PD29vbg4OBkZGT29vZzc3MyMjJ/f38xMTEyMjLR0dH///+9IAJFAAAAGXRSTlMA/vfHHWFOKhXvXFAM/Pz0593OrZeSe3RHsw+jTQAAAJNJREFUKM+dkEkOhSAQRFHUBsR55P4X/b/DoizdGNlA3kvorjIfTpz9yeT0c/xfMqSyufKmTIOoWIpswItFhQs2G3AbnD6rOhvwujKGDTgbcDZtC84G/GbAr2brUuq2Bzf6v84Bwf7ThDyU9zgsDOVFUuZIyvx1b84/e/Nau4z9vbd+FBX7Gri3sO4qoojjUE4kmh9w7wiVurrz2QAAAABJRU5ErkJggg==);
        background-size: 11px 11px;
        background-position: center;
        background-repeat: no-repeat;
        cursor: pointer;
      }

      #container {
        place-items: center;
        display: grid;
        position: relative;
        width: 100%;
        height: 143px;
        border-top: 2px dashed #000;
      }

      #tituloPulse {
        font-size: 10px;
        font-weight: 600;
        letter-spacing: 0.3px;
        color: #b3b3b3;
        text-transform: uppercase;
        margin: 0 0 5px 0;
        position: relative;
        top: 5px;
      }

      #textoPulse {
        font-size: 16px;
        font-weight: 600;
        line-height: normal;
        text-align: center;
        color: #333333;
        width: 100%;
        box-sizing: border-box;
        position: relative;
      }

      #ctaPulse {
        position: relative;
        width: 188px;
        height: 34px;
        line-height: 34px;
        text-align: center;
        margin: 0 auto;
        background-color: #fecc00;
        text-transform: uppercase;
        font-size: 11px;
        font-weight: 600;
        letter-spacing: 0.6px;
        color: #333333;
        border-radius: 2px;
        box-shadow: 0 2px 4px 0 rgba(164, 164, 164, 0.5);
      }

      #videoPulse {
        width: 100%;
        height: 127px;
      }

      #videoPulse video {
        width: 100%;
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
      }

      #pulseAd {
        position: fixed;
        bottom: 0px;
        left: 20px;
        width: 220px;
        background: #fff;
        height: 270px;
        z-index: 10;
        border-top-left-radius: 10px;
        border-top-right-radius: 10px;
        animation-duration: 2s;
        text-align: center;
        /* Fof all */
        --mask-image: radial-gradient(20px, #000 98%, #0000), radial-gradient(20px, #000 98%, #0000), radial-gradient(20px, #000 98%, #0000), linear-gradient(#000 0 0);
        --mask-size: 40px 40px, 40px 40px, 40px 40px, 100% 100%;
        --mask-position: left -20px top 110px, center -20px, right -20px top 110px, left top;
        --mask-repeat: no-repeat;
        /* For Chrome */
        -webkit-mask-image: var(--mask-image);
        -webkit-mask-size: var(--mask-size);
        -webkit-mask-repeat: var(--mask-repeat);
        -webkit-mask-position: var(--mask-position);
        -webkit-mask-composite: xor, xor, xor, source-in;
        /* For Firefox */
        mask-image: var(--mask-image);
        mask-size: var(--mask-size);
        mask-repeat: var(--mask-repeat);
        mask-position: var(--mask-position);
        mask-composite: exclude, exclude, exclude, add;
      }

      #pulseAd iframe {
        width: 220px;
        height: 270px;
        border-radius: 8px;
      }

      #ticket {
        position: relative;
        top: -263px;
        display: flex;
        justify-content: space-between;
        width: 220px;
      }

      #ticket1 {
        top: 117px;
        left: -8px;
        width: 20px !important;
        height: 20px !important;
      }

      #ticket2 {
        top: -14px;
        left: 98px;
      }

      #ticket3 {
        top: 117px;
        left: 207px;
        width: 20px !important;
        height: 20px !important;
      }

      div#ticket>div {
        width: 30px;
        height: 30px;
        position: absolute;
        border-radius: 50%;
        background: #f2f2f2;
      }
    }
  </style>
</div>
P粉066224086

Anda boleh menggabungkan berbilang radial-gradient untuk mencipta lebih banyak "lubang" atau kesan, sila rujuk Penyelesaian ini Saya menyiarkan dua hari lalu untuk mencipta berbilang "lubang".

Cabaran seterusnya ialah teduhan, tetapi lebih suka menggunakan filter: drop-shadow 和包装组件。 box-shadow 不适用于 -webkit-mask / mask.


Berikut ialah contoh membina elemen seperti tiket dalam CSS tulen:

.wrapper {
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.5));
  width: 200px;
  height: 300px;
}

.ticket {
  box-sizing: border-box;
  border-radius: 20px;
  background: white;
  width: 200px;
  height: 300px;
  -webkit-mask-image:
    radial-gradient(circle at 0% 55%, transparent 5%, black 5%, black 33%, transparent 33%), /* Left hole */
    radial-gradient(circle at 100% 55%, transparent 5%, black 5%, black 33%, transparent 33%), /* Right hole */
    radial-gradient(circle at 50% 0%, transparent 7%, black 7%, black 40%, transparent 40%), /* Top hole */
    radial-gradient(circle at 50% 50%, black 0%, black 33%, transparent 33%), /* Middle filling */
    radial-gradient(circle at 50% 100%, black 0%, black 40%, transparent 40%); /* Bottom filling */
  mask-image:
    radial-gradient(circle at 0% 55%, transparent 5%, black 5%, black 33%, transparent 33%), /* Left hole */
    radial-gradient(circle at 100% 55%, transparent 5%, black 5%, black 33%, transparent 33%), /* Right hole */
    radial-gradient(circle at 50% 0%, transparent 7%, black 7%, black 40%, transparent 40%), /* Top hole */
    radial-gradient(circle at 50% 50%, black 0%, black 33%, transparent 33%), /* Middle filling */
    radial-gradient(circle at 50% 100%, black 0%, black 40%, transparent 40%); /* Bottom filling */
}

/* Anything below this is not required, just for fun */

html {
  background-image: url('https://picsum.photos/1280/720');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  min-height: 100%;
  padding: 16px;
}

.ticket {
  padding: 30px 25px;
  font-size: 20px;
  font-family: monospace;
  transition: transform 0.2s;
}

.ticket:hover {
  transform: scale(1.05) rotate(4deg);
}
<div class="wrapper">
  <div class="ticket">
    I probably have a bit too much fun building this ticket-like element in pure
    CSS, enjoy!<br /><br /><a
      href="https://stackoverflow.com/users/8888888/angyc"
      target="_blank"
      >@AngYC</a
    >
  </div>
</div>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan