Advanced Component Styling in React
Let's assume we have a React component Block
and we created in it components Button
and Container
styled using Styled Components:
const Container = styled.div`
display: flex;
flex-direction: column;
width: 150px;
`;
const Button = styled.input`
background-color: orange;
font-size: 18px;
margin: 5px;
`;
Now let's imagine we want another Button
component, but with white button text and a green background.
To do this, we just need to create a new component Button
based on our component Button
and register in it only those properties that we want to change:
const MdButton = styled(Button)`
color: white;
background-color: green;
`;
Let's place all our styled components in Block
:
function Block() {
return (
<Container>
<Button>btn0</Button>
<MdButton>btn1</MdButton>
</Container>
);
}
Create an empty React component Block1
. Using Styled Components, create a styled div in it with a width and height of 150px
, a yellow background, and a border width of 2px
, and name it DIVA
.
Based on the div from the previous task, create the same div DIVB
, only with a green background and a border width of 3px
.
In Block1
, create a Container
div. Place two DIVA
components in it, and between them one DIVB
, which you created in the previous tasks of this lesson.