Animated Turtle

CSS

레이아웃 실전 - 슬라이드 유형

훙구 2023. 3. 15. 17:56

...

728x90
반응형

레이아웃 실전 _ 슬라이드 유형

이번에는 웹페이지에 들어갈 슬라이드 유형의 레이아웃을 만들어 보겠습니다.

 

슬라이드유형 디자인하기

디자인 예시

구상한 디자인 기반으로 코딩

 

HTML 작성하기

<!DOCTYPE html>
<html lang="ko">
<head>
     <meta charset="UTF-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>슬라이드 유형01</title>
     <link href="https://webfontworld.github.io/NexonLv1Gothic/NexonLv1Gothic.css" rel="stylesheet">
</head>
<body>
     <section class="slider__wrap nexon">
          <h2 class="blind">메인 슬라이드 영역</h2>
          <div class="slider__inner">
               <div class="slider">
                    <div class="slider__info container">
                         <span class="small">EVENT</span>
                         <h3 class="title">한강 무료 아메리카노</h3>
                         <p class="desc">여의도 한강공원 여의나루역 5번출구로 나와 전방 300m 부근에서 무료 아메리카노 시식 이벤트가 진행됩니다.</p>
                         <div class="btn">
                              <a href="#">자세히 보기</a>
                              <a href="#">참여 하기</a>
                         </div>
                    </div>
                    <div class="slider__arrow">
                         <a href="#"><span class="blind">이전 이미지</span></a>
                         <a href="#"><span class="blind">다음 이미지</span></a>
                    </div>
                    <div class="slider__dot">
                         <a href="#" class="dot active"><span class="blind">첫 번째 이미지</span></a>
                         <a href="#" class="dot"><span class="blind">두 번째 이미지</span></a>
                         <a href="#" class="dot"><span class="blind">세 번째 이미지</span></a>
                         <a href="#" class="play"><span class="blind">플레이</span></a>
                         <a href="#" class="stop"><span class="blind">정지</span></a>
                    </div>
               </div>
               <!-- <div class="slider"></div>
               <div class="slider"></div> -->
          </div>
     </section>
</body>
</html>

HTML 정리해보기

  • 슬라이드 유형의 경우 전체 배경에 이미지가 들어가기 때문에 별도의 container 안에 작업하지 않았습니다.
  • slider__inner 클래스의 박스에 크게 세 부분으로 나누어 작업하였습니다.
  • 이미지와 주제, 설명 등의 글이 들어가는 한 부분, 슬라이드를 넘길 수 있는 좌우의 화살표 이미지가 들어가는 한 부분, 슬라이드의 페이지를 표시하는 아래의 작은 dot이미지가 들어가는 한 부분으로 나누었습니다.

 

CSS 작성하기

* {
	margin: 0;
	padding: 0;
}
a {
	text-decoration: none;
	color: #000;
}
h1,h2,h3,h4,h5,h6 {
	font-weight: normal;
}
img {
	vertical-align: top;
	width: 100%;
}
.blind {
	position: absolute;
	clip: rect(0 0 0 0);
	width: 1px;
	height: 1px;
	margin: -1px;
	overflow: hidden;
}
.mt10 {margin-top: 10px !important;}
.mt20 {margin-top: 20px !important;}
.mt30 {margin-top: 30px !important;}
.mt40 {margin-top: 40px !important;}
.mt50 {margin-top: 50px !important;}
.mt60 {margin-top: 60px !important;}
.mt70 {margin-top: 70px !important;}

.mb10 {margin-bottom: 10px !important;}
.mb20 {margin-bottom: 20px !important;}
.mb30 {margin-bottom: 30px !important;}
.mb40 {margin-bottom: 40px !important;}
.mb50 {margin-bottom: 50px !important;}
.mb60 {margin-bottom: 60px !important;}
.mb70 {margin-bottom: 70px !important;}


.container {
	width: 1160px;
	margin: 0 auto;
	padding: 0 20px;
}
.nexon {
	font-family: 'NexonLv1Gothic';
	font-weight: 400;
}
.section {
	padding: 120px 0;
}
.center {
	text-align: center;
}
.section__small {
	font-size: 14px;
	border-radius: 50px;
	padding: 1px 23px;
	background-color: #8179e1;
	color: #fff;
	text-transform: uppercase;
	display: inline-block;
	margin-bottom: 20px;
}
.section__h2 {
	font-size: 50px;
	font-weight: 400;
	margin-bottom: 30px;
	line-height: 1;
}
.section__desc {
	font-size: 22px;
	line-height: 25px;
	color: #666666;
	margin-bottom: 70px;
	font-weight: 300;
	line-height: 1.5;
}
/* slider__wrap */
.slider__inner .slider {
	height: 600px;
	background-image: url(../asset/img/SLIDER-TYPE01_01.jpg);
	background-size: cover;
	background-repeat: no-repeat;
	background-position: center;
	position: relative;
	z-index: 1;
}
.slider__inner .slider::after {
	content: '';
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.05);
	position: absolute;
	left: 0;
	top: 0;
	z-index: -1;
}
.slider__info {
	padding: 100px 0;
}
.slider__info .small {
	display: inline-block;
	padding: 1px 30px;
	background-color: #fff;
	color: #000;
	font-size: 16px;
	border-radius: 50px;
	text-transform: uppercase;
	margin-bottom: 10px;
}
.slider__info .title {
	font-size: 80px;
	color: #fff;
	margin-bottom: 40px;
	margin-left: -5px;
}
.slider__info .desc {
	font-size: 18px;
	line-height: 1.5;
	color: #fff;
	width: 50%;
	word-break: keep-all;
}
.slider__info .btn {
	margin-top: 100px;
}
.slider__info .btn a {
	width: 180px;
	height: 40px;
	line-height: 40px;
	background-color: #fff;
	font-size: 16px;
	display: inline-block;
	text-align: center;
	margin-right: 4px;
}
.slider__info .btn a:last-child {
	background-color: #222222;
	color: #fff;
}
.slider__arrow a {
	position: absolute;
	top: 50%;
	background-image: url(../asset/img/icon_main.svg);
	background-size: 500px;
	width: 30px;
	height: 56px;
	display: block;
	margin-top: -28px;
}
.slider__arrow a:first-child {
	left: 20px;
}
.slider__arrow a:last-child {
	right: 20px;
	background-position: -50px 0;
}
.slider__dot {
	position: absolute;
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
}
.slider__dot a {
	width: 16px;
	height: 16px;
	display: inline-block;
	background-image: url(../asset/img/icon_main.svg);
	background-size: 500px;
	background-position: -100px -1px;
	margin: 0 4px;
}
.slider__dot a.dot {
	background-position: -100px -1px;
}
.slider__dot a.active {
	background-position: -120px -1px;
}
.slider__dot a.play {
	background-position: -161px -3px;
}
.slider__dot a.stop {
	background-position: -184px -1px;
}

@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min-device-pixel-ratio: 2),
only screen and (min-resolution: 2dppx) {
	.slider__inner .slider {
		background-image: url(../asset/img/SLIDER-TYPE01_01_2x.jpg);
	}
}

CSS 정리해보기

  • slider__wrap 주석표시 전 까지는 다른 레이아웃 페이지들과 동일하게 부여되는 기본 속성 값 입니다. (앞의 레이아웃 게시물 참고)
  • 슬라이드 이미지에 적혀있는 글귀의 가독성을 더 높여주기 위해 슬라이드 이미지에 가상요소(::after)를 만들어 살짝 어두운 이미지로 덮어주었습니다.
  • 슬라이드에 들어가는 글의 줄 바꿈을 단어 기준으로 바꿔주기 위해 word-break: keep-all;의 속성을 부여했습니다.
  • 레이아웃 좌우에 들어가는 화살표와, 하단에 위치한 dot 이미지는 이미지를 한 곳에 저장하여 출력되는 크기를 정해주고 그 범위에서 배경이미지의 position 값을 조정해 출력했습니다.

 

728x90
반응형