REACT
React Website 만들기) 2.Home.js만들고 Herosection 만들기
dodop
2021. 1. 29. 20:41
1. Home.js
components 안에 pages 폴더를 만들고 home.js 파일을 만든다.
import React from 'react'
import '../../App.css';
import HeroSection from '../HeroSection';
import Cards from'../Cards';
import Footer from '../Footer';
function Home() {
return (
<>
<HeroSection />
<Cards />
<Footer />
</>
)
}
export default Home;
2. HeroSection.js
components 폴더 안에 HeroSection.js파일을 만든다.
홈페이지 안에 버튼과 제일 먼저 보이는 문구를 적용한다.
import React from 'react'
import '../App.css';
import { Button } from './Button'
import './HeroSection.css';
function HeroSection() {
return (
<div className = 'hero-container'>
<video src="/videos/video-2.mp4" autoPlay loop muted />
<h1>ADVENTURE AWAITS</h1>
<p>What are you waiting for?</p>
<div className="hero-btns">
<Button className = 'btns' buttonStyle = 'btn--outline'
buttonSize = 'btn--large'>GET STARTED</Button>
<Button className = 'btns' buttonStyle = 'btn--primary'
buttonSize = 'btn--large'>WATCH TRAILER <i className = 'far fa-play-circle'/></Button>
</div>
</div>
)
}
export default HeroSection
3. HeroSection.css
HeroSection.js와 같은 공간에 css 파일을 만든다.
(HeroSectio.js 의 css를 만든다)
비디오를 배경화면으로 정해놓고, 만약 사진으로 하고 싶다면 주석으로 처리해준 공간을 풀고 사진파일을 정해주면 된다.
video {
object-fit: cover;
width: 100%;
height: 100%;
position: fixed;
z-index: -1;
}
.hero-container {
/* background: url('/src/images/img-home.jpg') center center/cover no-repeat; */
height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-shadow: inset 0 0 0 1000px rgba(0, 0, 0, 0.2);
object-fit: contain;
}
.hero-container > h1{
color: white;
font-size: 100px;
margin-top: -100px;
}
.hero-container > p {
margin-top: 8px;
color: white;
font-size: 32px;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}
.hero-btns {
margin-top: 32px;
}
.hero-btns .btn {
margin: 6px;
}
.fa-play-circle {
margin-left: 4px;
}
@media screen and (max-width : 960px){
.hero-container > h1{
font-size: 70px;
margin-top: -1500px;
}
}
@media screen and (max-width: 768px){
.hero-container > h1{
font-size: 50px;
margin-top: -100px;
}
.hero-container >p {
font-size: 30px;
}
.btn-mobile {
display: block;
text-decoration: none;
}
.btn {
width: 100%;
}
}
사진으로 보면,