1

I'm building a website that is using gatsby/react/react-bootstrap/framer-motion. I'm having an issue of framer-motion override my react-bootstrap css? I'd rather not re-style all the responsiveness back into these elements and am wondering if there is a way to get these two libraries to play nice with eachother?? It seems like a headache trying to get framer-motion to be responsive...I might just design for different viewports but idk.

heres my code:

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

Heres my 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;
}

Any help is super appreciated!!!!

2 Answers2

1

Try referencing the motion tag as a prop and use regular html tags:

<img as={motion.img}>
Julien Aubert
  • 184
  • 1
  • 4
0

Framer doesn't override css styles.

you need to npm i framer-motion and npm i react-bootstrap.

None of these libs doesn't override global styles. The problem hides in your custom css

Make attention which component you are using in import.

Example: why you import { Image, Container, Row } from react bootstrap, if you can use "container" css class? You need just to import bootstrap.css from 'react-bootstrap' and use css instead of constants.

P.S. Some elements from 'react-bootstrap' are not working properly, for example take a look at this example.

ChilTest
  • 461
  • 5
  • 18