Questions tagged [styled-components]

styled-components is a JavaScript library for styling React applications. It removes the mapping between styles and components, and lets you write actual CSS augmented with JavaScript.

styled-components is an open source project developed by Glen Maddern and Max Stoiber that aims to make styling component-based systems, right now solely focussed on React, easier.


This is what using styled-components looks like:

import React from 'react';
import styled from 'styled-components';

// Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em
const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

// Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background
const Wrapper = styled.section`
  padding: 4em;
  background: papayawhip;
`;

These two variables, Title and Wrapper, are now a React components you can render like any other React component:

<Wrapper>
  <Title>Hello World, this is my first styled component!</Title>
</Wrapper>

The above code rendered in the browser(Live demo)

For more information and examples see the official documentation!

4586 questions
1
vote
2 answers

can attribute selectors be used with styled-components?

after doing a bit of research, I could not find information regarding the usage of attribute selectors (that is, [attr=value]) in styled-components. however, I still imagine it is highly possible for styled-components to support attribute…
KnowsCount
  • 187
  • 1
  • 11
1
vote
0 answers

How can I pass own props in React Table usePagination hook

I have global Pagination component where I want to pass custom props with padding, specific only to the component where it's rendered. I want to pass padding props ( last prop ), this is how I pass it:
marcinb1986
  • 708
  • 1
  • 11
  • 30
1
vote
1 answer

How can I load google fonts before the document

So this is what I'm currently working on: https://sipkin-portfolio-v2.netlify.app/ When I open this website it shows the default sans-serif font for a split second and then it loads Bebas Neue. I would like to know if I could load the font from…
Aleksa
  • 73
  • 1
  • 4
1
vote
1 answer

I can't structure React Routes properly

I'm working on a Twitter clone using the MERN stack, and couldn't wrap my head around routes, let me explain a bit more, I want the design of the login page to be separated from the entire app, so I'm using styled-components and wrapped the login…
1
vote
1 answer

Having problems rendering the footer for a google clone

So I basically have 2 problems. I used position: absolute and bottom: 0 to but the footer at the bottom but it's not widened even when I use the width property. Text elements are cutoff when browser window is shortened. I'll attach pictures & a…
Oscill
  • 11
  • 3
1
vote
0 answers

I'm using CDN links of intro.js, I want to implement "don't show again checkbox on Intro.js pop-up", how can we do that?

We have a requirement where I have to add a checkbox on the intro.js pop-up, so I have used intro.js min and CSS files CDN links to use the Intro.js, currently, I'm getting intro.js pop-up with the intro and checkbox, Issues I am facing are: If…
1
vote
1 answer

Reverse a transition on props change with styled-components

I am animation two elements on a props change: a container div slides in/out with max-height, and the contents of the div fades in/out with opacity. Trouble is, I want the container to animate after the contents on the "out" animation, but I want it…
crevulus
  • 1,658
  • 12
  • 42
1
vote
0 answers

Using the color picker in a styled component gives really long HSL values

I started using React and Styled Components to build a new app and am running into a weird issue with HSL colors. When I try to use the color picker to pick a color in HSL it gives really long values like 'hsl(128.4375, 28.82882882882883%,…
Valstorm
  • 31
  • 3
1
vote
1 answer

In typescript, can I pass JSX.Element as props to styled-components?

note: Please note that my English is poor. Here is a component that takes a parent element as props and displays a callout when it is hovered: const Explanation = styled.span` // Detailed implementation is omitted. ${(props) =>…
tom yam
  • 117
  • 7
1
vote
2 answers

dynamic template strings sharing between styled components

I'm working on sharing code between a React and a React Native application (as much as possible). For that I'm using styled-components. I'm trying something like this for the template strings const BUTTON_STYLE = ` display: flex; …
Javier Manzano
  • 4,761
  • 16
  • 56
  • 86
1
vote
1 answer

styled(Component) does not apply styles on functional component

1. I have a component that is written with styled-components 2. Calling that component inside of new Styled component 3. Attach styles Result: Styles are not applied export const WarningBox = styled(InfoBox)` ${({ theme }) => css` display: flex; …
Mark James
  • 338
  • 4
  • 15
  • 43
1
vote
2 answers

How can I target a child class from the parent class in styled-components?

This is pretty straight forward question in CSS so I kind of surprised it's proving to be difficult in styled-components. I would like to apply styles to MultiWrapper, but only when it's a child of FormWrapper. According to the documentation. All I…
London804
  • 1,072
  • 1
  • 22
  • 47
1
vote
1 answer

Is it bad practice to export all components into an index.js file?

I export all components to an index.js file. This means that I can import components into any other file by doing the bellow. This is simple and cleaner. import { RocketCard, Container, Navbar, Button01 } from './Components/index'; This is what my…
1
vote
3 answers

Apply CSS transition to styled-component when React state changes

I have some state that changes after button click. The state changes the size of a sidebar. Here is my CSS made with styled-components and conditional rendering: const SidebarStyled = styled.div` width: ${this.state.sidebarOpen ? '200px' :…
user18170841
1
vote
0 answers

I got a hovering div with text in it, when I hover on the actual div it works, but when I hover on the text inside of it the hover stops

When I hover on LayerOne, its opacity changes from 0 to 1, but when I hover on ProjectName or ProjectDate the hover stops and all LayerOne disappears with the text. I want the opacity to be 0 only when I make mouseLeave on LayerOne. There is other…
Jonathan
  • 27
  • 4