Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do you reset the CSS in React if you're doing styled components?

Tags:

reactjs

So I'm creating a footer with styled components and we don't use classes like in normal css.

If I want to replicate the same CSS trick where we do this code below

  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
   }

How would I replicate this in a styled component? Is that even the correct way to do it?

Or would I need to create an App.css file and simply add it to my project?

Here's the typical code for a styled component in react

 import styled from 'styled-components/macro';

 export const Container = styled.div`
 padding: 80px 60px;
 background: black;
 font-family: 'Nunito Sans', sans-serif;

@media (max-width: 1000px) {
  padding: 70px 30px;
}
`;

Is it possible to add that * { box-sizing} code into my styled component or what is the proper way to implement that into my project?

like image 797
Brian Avatar asked Jul 14 '20 03:07

Brian


People also ask

Can I use CSS with styled-components?

You can use standard CSS properties, and styled components will add vendor prefixes should they be needed. Styled components are independent of each other, and you do not have to worry about their names because the library handles that for you.

How do you override styled component React?

You can override an existing styled-components component by passing it to the styled() constructor/wrapper. For example, suppose you have the following styled button element: const Button = styled.

What are reset styles in CSS?

A CSS Reset style sheet is a list of rules that 'reset' all of the default browser styles. We reset the browser styles for two primary reasons: Not all browsers apply the same default rules. They may be similar, but not exact.


1 Answers

import { createGlobalStyle } from 'styled-components'

const GlobalStyle = createGlobalStyle`
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
`

// in your app root
<React.Fragment>
  <GlobalStyle />
  <Navigation /> {/* example of other top-level stuff */}
</React.Fragment>
like image 135
AryanJ-NYC Avatar answered Oct 16 '22 22:10

AryanJ-NYC