我已經(jīng)在背景圖像上放置了文本,但是當(dāng)我改變屏幕尺寸時(shí),背景位置保持不變,但是文本離開了背景圖像。
我希望當(dāng)我改變屏幕尺寸時(shí),外翻仍然和原來的屏幕一樣。 下面是上面組件的CSS。我想發(fā)生的是,當(dāng)我改變屏幕尺寸時(shí),圖像上的文本只出現(xiàn)在圖像上,這是在圖像之外
@import url('https://fonts.googleapis.com/css?family=Montserrat:600&display=swap');
.Intro_image {
width: 100%;
height: auto;
background-size: cover;
background-position: center;
object-fit: cover;
position: relative;
}
.hero {
height: 100%;
width: 100%;
}
.hero .content {
position: absolute;
transform: translate(-50%,-50%);
top: 50%;
left: 50%;
text-align: center;
}
.hero .content h1 {
font-size: 4rem;
padding: 0.6rem 0 1.5rem;\
}
.hero .content p {
font-size: 3rem;
font-weight: 200;
text-transform: uppercase;
}
.content .btn {
margin: 1rem 1rem;
}
@media screen and (max-width:640px) {
.hero .content h1 {
font-size: 1.5rem;
}
.hero .content p {
font-size: 1.4rem;
}
.Intro_image {
width: 100%;
height: 100%;
background-size: cover;
background-position: center;
object-fit: fill;
}
}
.hero h1 {
position: relative;
font-family: sans-serif;
text-transform: uppercase;
font-size: 2em;
letter-spacing: 4px;
overflow: hidden;
background: linear-gradient(90deg, #000, #fff, #000);
background-repeat: no-repeat;
background-size: 80%;
animation: animate 5s linear infinite;
-webkit-background-clip: text;
-webkit-text-fill-color: rgba(231, 40, 40, 0);
}
@keyframes animate {
0% {
background-position: -500%;
}
100% {
background-position: 500%;
}
}
#foot {
position: absolute;
left: 30px;
bottom: 50px;
margin: auto;
border: none;
padding: 15px;
border-radius: 15px;
box-shadow: 0 0 8px #d9d4e7;
width: 200px;
height: 65px;
background-color: #d9d4e7;
animation-duration: 5s;
}
.btn {
background-color: #000;
color: white;
text-decoration: solid;
font-weight: bold;
}
import "./HeroImgStyles.css";
import React from "react";
import IntroImage from "../assets/nasa.jpg";
import { Link } from "react-router-dom";
import Fade from "react-reveal/Fade";
const HeroImg = () => {
return (
<div className="hero">
<img className="Intro_image" src={IntroImage} />
<div className="content">
<Fade bottom>
<p className="top"> PASSION. POSSIBILITIES. INNOVATIONS! </p>
</Fade>
<h1></h1>
<div>
<Link to="/projects" className="btn">
Products
</Link>
<Link to="/contact" className="btn">
Contact Us
</Link>
</div>
</div>
</div>
);
};
export default HeroImg;