Dev Blog

스크립트 & 소스코드 공유

실무에서 유용하게 쓰는 스크립트와 코드 조각을 블로그 게시판으로 저장하고 공유합니다.

5건의 글

inline-block 요소에 배경 스타일 예쁘게 적용하기

inline-block 요소에 배경 스타일을 예쁘게 적용하는 방법을 보여주는 CodePen 예제다. display: inline-block 요소에 배경색·패딩·테두리 반경·그림자를 조합해 탭·버튼·뱃지처럼 보이도록 꾸미며, 요소 사이 간격과 수직 정렬까지 함께 다루는 예시를 제공한다.

See the Pen Untitled by H J (@H-J-the-typescripter) on CodePen.

배경에 따라 글자 색이 자동으로 변하는 텍스트 효과

배경 이미지에 따라 글자 색이 자동으로 적응하는 효과를 CSS로 구현한 CodePen 예제다. mix-blend-mode와 background-clip을 활용해 밝은 배경과 어두운 배경 모두에서 글자가 또렷하게 보이도록 하며, 배경 위에 겹쳐진 텍스트의 가독성을 높이는 기법이다.

See the Pen Untitled by H J (@H-J-the-typescripter) on CodePen.

문장의 span에 예쁘게 백그라운드(형광펜) 넣기

문장 일부 span에 형광펜처럼 예쁜 백그라운드를 입히는 CSS 방법을 보여주는 CodePen 예제다. span에 배경색과 padding을 적용하고 line-height를 함께 조절해, 줄바꿈이 발생해도 배경이 끊기지 않고 자연스럽게 채워지도록 꾸민다. HTML과 CSS 예제 코드를 제공한다.

HTML

<p> 하늘이 처음 이 세상에서
너의 운명을 정하실 때에 날 미처 모르고
다른 사람을 보내셨기에
<span>우린 이렇게 눈물 남기고 스쳐야 할 인연 인가봐
남은 여생은 하루처럼 생각하며 살다 가기로 해
그저 남보다 조금 긴 하루라고 여기면 돼

*내가 하늘로 돌아가면 눈물로 천년동안 빌겠어</span>
이 다음 생애엔 꼭 이룰 수 있게 도와 달라고

잠시만 서로 맡기는 거야
사연이 많아 천년 후에야 되찾으러 가는 것뿐야
남은 여생은 하루처럼 생각하며 살다 가기로 해
그저 남보다 조금 긴 하루라고 여기면 돼
내가 하늘로 돌아가면 눈물로 천년동안 빌겠어
이 다음 생애엔 꼭..이룰 수 있게 도와 달라고 </p>

CSS

p{line-height:170%;}
span{
background:linear-gradient(90deg, #f60, #9c0);
border:1px solid #000;
padding: 0 .5em;
border-radius:.3em;
box-decoration-break:clone;
-webkit-box-decoration-break:clone;
}

DEMO

See the Pen Untitled by H J (@H-J-the-typescripter) on CodePen.

CSS blend mode로 이미지·배경 합성하기 (multiply, screen 등)

CSS 的 mix-blend-mode 与 background-blend-mode 实现图片与背景合成的方法。整理了 multiply(正片叠底)、screen(滤色)、overlay(叠加)、darken、lighten、difference、hue、saturation 等全部混合模式,并说明 mix-blend-mode 作用于 img 元素、background-blend-mode 作用于 div 背景,两者使用场景不同。

mix-blend-mode: normal; //正常

mix-blend-mode: multiply; //正片叠底

mix-blend-mode: screen; //滤色

mix-blend-mode: overlay; //叠加

mix-blend-mode: darken; //变暗

mix-blend-mode: lighten; //变亮

mix-blend-mode: color-dodge; //颜色减淡

mix-blend-mode: color-burn; //颜色加深

mix-blend-mode: hard-light; //强光

mix-blend-mode: soft-light; //柔光

mix-blend-mode: difference; //差值

mix-blend-mode: exclusion; //排除

mix-blend-mode: hue; //色相

mix-blend-mode: saturation; //饱和度

mix-blend-mode: color; //颜色

mix-blend-mode: luminosity; //亮度

mix-blend-mode: initial; //初始

mix-blend-mode: inherit; //继承

mix-blend-mode: unset; //复原

这里就是div自己的背景图片和自己的背景颜色混合了,实现了正片叠低。注意只有一个元素div,这个div有背景图片和背景颜色。

background-blend-mode: multiply;是div属性,mix-blend-mode: multiply; 是img的属性,两个东西有差别

유튜브 영상을 웹페이지 배경으로 사용하는 CSS 기법

유튜브 동영상을 웹페이지 전체 배경으로 사용하는 HTML/CSS 기법이다. video-background 컨테이너와 video-foreground 안의 iframe을 화면에 꽉 차게 배치하고 z-index를 낮춰 콘텐츠 뒤에 깔리게 한다. 화면 비율에 따라 16:9, 9:16 미디어 쿼리로 확대 영역을 조정하는 전체 CSS와 HTML 예제 코드를 제공한다.

* {
  box-sizing: border-box;
}

.video-background {
  background: #000;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -99;
}

.video-foreground,
.video-background iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#vidtop-content {
  top: 0;
  color: #fff;
}

.vid-info {
  position: absolute;
  top: 0;
  right: 0;
  width: 33%;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  padding: 1rem;
  font-family: Avenir, Helvetica, sans-serif;
}

.vid-info h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 0;
  line-height: 1.2;
}

.vid-info a {
  display: block;
  color: #fff;
  text-decoration: none;
  background: rgba(0, 0, 0, 0.5);
  transition: .6s background;
  border-bottom: none;
  margin: 1rem auto;
  text-align: center;
}

@media (min-aspect-ratio: 16/9) {
  .video-foreground {
    height: 300%;
    top: -100%;
  }
}

@media (max-aspect-ratio: 16/9) {
  .video-foreground {
    width: 300%;
    left: -100%;
  }
}

@media all and (max-width: 600px) {
  .vid-info {
    width: 50%;
    padding: .5rem;
  }

  .vid-info h1 {
    margin-bottom: .2rem;
  }
}

@media all and (max-width: 500px) {
  .vid-info .acronym {
    display: none;
  }
}
<div class="video-background">
  <div class="video-foreground">
    <iframe class="ww" src="https://www.youtube-nocookie.com/embed/n0AY4ebPy4w?autoplay=1&loop=1&controls=0&vq=hd720"
      frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
      allowfullscreen></iframe>
  </div>
</div>
<div id="vidtop-content">
  <div class="vid-info">
    <h1>YouTube</h1>
    <p>Good!</p>
  </div>
</div>


Let's create something great together.

프로젝트 문의 및 견적 요청은 언제든 환영합니다.