[英]Framer-motion overriding react-bootstrap
我正在構建一個使用 gatsby/react/react-bootstrap/framer-motion 的網站。 我遇到了 framer-motion 覆蓋我的 react-bootstrap css 的問題? 我寧願不將所有響應性重新設計回這些元素中,並且想知道是否有辦法讓這兩個庫相互配合得很好? 試圖讓 framer-motion 響應起來似乎很頭疼……我可能只是為不同的視口設計,但 idk。
這是我的代碼:
import React from "react";
import 'bootstrap/dist/css/bootstrap.min.css';
import './styles.scss';
import { Image, Container, Row } from 'react-bootstrap';
import CamcoNavbar from '../components/camconavbar.js';
import BackgroundImage from '../../static/Untitled-1.jpg';
import CClogo from '../../static/CamCo(white).png'
import { motion } from 'framer-motion';
const Home = () => {
return (
<div>
<CamcoNavbar />
<Container>
<motion.img className="cclogo" key={CClogo} src={CClogo} initial={{opacity: 0}} animate={{opacity: 1}} transition={{duration: 3}}/>
</Container>
<motion.img className="header-image" key={BackgroundImage} src={BackgroundImage} initial={{x: -250}} animate={{x: 1000}} transition={{duration: 60, repeat: Infinity}}/>
</div>
)
}
export default Home
這是我的 css:
@import "~bootstrap/scss/bootstrap";
body {
background-color: black;
}
.nav-item {
padding-left: 20px;
padding-right: 20px;
}
.nav-item a {
text-decoration: none;
letter-spacing: 5px;
font-weight: 300;
font-size: 12px;
color: white;
}
.nav-item a:hover {
text-decoration: none;
color: #64a0c2;
}
.carousel-item {
background-color: blue;
width: 400px;
height: 400px;
}
button.navbar-toggler {
justify-content: center;
}
.header-image {
object-fit: cover;
display: inline-block;
min-width: 100%;
min-height: 100%;
width: 120%;
height: 120%;
position: fixed;
top: 0;
z-index: -4;
}
.cclogo {
position: relative;
top: 50%;
left: 50%;
z-index: 2;
}
p, h1, h2, h3, h4, li {
color: white;
}
非常感謝任何幫助!!!!
嘗試引用 motion 標簽作為道具並使用常規 html 標簽:
<img as={motion.img}>
Framer 不會覆蓋 css styles。
你需要npm i framer-motion
和npm i react-bootstrap
。
這些庫都不會覆蓋全局 styles。問題隱藏在您的自定義css
請注意您在import
中使用的是哪個組件。
示例:如果可以使用“container”css class,為什么要從 react bootstrap 導入 {Image, Container, Row}? 您只需要從“react-bootstrap”導入 bootstrap.css 並使用 css 而不是常量。
PS 來自“react-bootstrap”的一些元素不能正常工作,例如看看這個例子。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.