방법 - 영웅 이미지
CSS로 영웅 이미지를 만드는 방법을 알아보세요.
영웅 이미지는 텍스트가 포함된 큰 이미지로, 종종 웹페이지 상단에 배치됩니다.
영웅 이미지를 만드는 방법
1단계) HTML 추가:
예시
<div class="hero-image">
<div class="hero-text">
<h1>I am John Doe</h1>
<p>And I'm
a Photographer</p>
<button>Hire me</button>
</div>
</div>
2단계) CSS 추가:
예시
body, html {
height: 100%;
}
/* The hero image
*/
.hero-image {
/* Use "linear-gradient" to add a darken background effect
to the image (photographer.jpg). This will make the text
easier to read */
background-image: linear-gradient(rgba(0, 0, 0, 0.5),
rgba(0, 0, 0, 0.5)), url("photographer.jpg");
/* Set a specific height
*/
height:
50%;
/* Position and center the image to scale
nicely on all screens */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
/* Place text in the middle of the image */
.hero-text {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform:
translate(-50%, -50%);
color: white;
}