Styles are not working in through styled components
up vote
-1
down vote
favorite
I am trying to add background-color through styled component.
If add the styles through style={} attribute it is working as expected but If I add the same style in my styled component file it is not working.
//this is working
<MyStyle style={{backgroundColor: '#fff' }}>
//some component here
</MyStyle>
//This is not working.
export const MyStyle = styled.div`
background-color: ‘#fff’;
`;
Can somebody point me here what I am missing here?
reactjs styled-components
add a comment |
up vote
-1
down vote
favorite
I am trying to add background-color through styled component.
If add the styles through style={} attribute it is working as expected but If I add the same style in my styled component file it is not working.
//this is working
<MyStyle style={{backgroundColor: '#fff' }}>
//some component here
</MyStyle>
//This is not working.
export const MyStyle = styled.div`
background-color: ‘#fff’;
`;
Can somebody point me here what I am missing here?
reactjs styled-components
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am trying to add background-color through styled component.
If add the styles through style={} attribute it is working as expected but If I add the same style in my styled component file it is not working.
//this is working
<MyStyle style={{backgroundColor: '#fff' }}>
//some component here
</MyStyle>
//This is not working.
export const MyStyle = styled.div`
background-color: ‘#fff’;
`;
Can somebody point me here what I am missing here?
reactjs styled-components
I am trying to add background-color through styled component.
If add the styles through style={} attribute it is working as expected but If I add the same style in my styled component file it is not working.
//this is working
<MyStyle style={{backgroundColor: '#fff' }}>
//some component here
</MyStyle>
//This is not working.
export const MyStyle = styled.div`
background-color: ‘#fff’;
`;
Can somebody point me here what I am missing here?
reactjs styled-components
reactjs styled-components
asked Nov 19 at 8:27
brig
1,40693251
1,40693251
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
The first example is simply using the react style builtin, you don't need styled components to do this.
The code in the second example, you need to remove the quotes around the color, like this:
//This is not working.
export const MyStyle = styled.div`
background-color: #fff;
`;
Styled components takes css syntax, which unlike json syntax, does not have quotes around option names, color names, etc.
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
Do you have the babel plugin? (edit, never mind, that shouldn't break it)
– neonfuz
Nov 19 at 8:44
add a comment |
up vote
0
down vote
You don't have to put single quote around #fff
export const MyStyle = styled.div`
background-color: #fff;
`;
EDITED:
If there are overriding CSS styles that make your div's background not white just yet, and you can't find them, just add !important
to this style
export const MyStyle = styled.div`
background-color: #fff !important;
`;
Regarding the issue about finding existing CSS styles that might be overriding your preferred style, take a look at this: https://www.styled-components.com/docs/advanced#existing-css
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
If it's still not working, you might have CSS styles somewhere that overrides this style. If you are familiar with the "point system" in CSS, you should have known the problem.
– Sandy Brutas
Nov 19 at 8:36
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The first example is simply using the react style builtin, you don't need styled components to do this.
The code in the second example, you need to remove the quotes around the color, like this:
//This is not working.
export const MyStyle = styled.div`
background-color: #fff;
`;
Styled components takes css syntax, which unlike json syntax, does not have quotes around option names, color names, etc.
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
Do you have the babel plugin? (edit, never mind, that shouldn't break it)
– neonfuz
Nov 19 at 8:44
add a comment |
up vote
0
down vote
The first example is simply using the react style builtin, you don't need styled components to do this.
The code in the second example, you need to remove the quotes around the color, like this:
//This is not working.
export const MyStyle = styled.div`
background-color: #fff;
`;
Styled components takes css syntax, which unlike json syntax, does not have quotes around option names, color names, etc.
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
Do you have the babel plugin? (edit, never mind, that shouldn't break it)
– neonfuz
Nov 19 at 8:44
add a comment |
up vote
0
down vote
up vote
0
down vote
The first example is simply using the react style builtin, you don't need styled components to do this.
The code in the second example, you need to remove the quotes around the color, like this:
//This is not working.
export const MyStyle = styled.div`
background-color: #fff;
`;
Styled components takes css syntax, which unlike json syntax, does not have quotes around option names, color names, etc.
The first example is simply using the react style builtin, you don't need styled components to do this.
The code in the second example, you need to remove the quotes around the color, like this:
//This is not working.
export const MyStyle = styled.div`
background-color: #fff;
`;
Styled components takes css syntax, which unlike json syntax, does not have quotes around option names, color names, etc.
answered Nov 19 at 8:30
neonfuz
1694
1694
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
Do you have the babel plugin? (edit, never mind, that shouldn't break it)
– neonfuz
Nov 19 at 8:44
add a comment |
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
Do you have the babel plugin? (edit, never mind, that shouldn't break it)
– neonfuz
Nov 19 at 8:44
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
Do you have the babel plugin? (edit, never mind, that shouldn't break it)
– neonfuz
Nov 19 at 8:44
Do you have the babel plugin? (edit, never mind, that shouldn't break it)
– neonfuz
Nov 19 at 8:44
add a comment |
up vote
0
down vote
You don't have to put single quote around #fff
export const MyStyle = styled.div`
background-color: #fff;
`;
EDITED:
If there are overriding CSS styles that make your div's background not white just yet, and you can't find them, just add !important
to this style
export const MyStyle = styled.div`
background-color: #fff !important;
`;
Regarding the issue about finding existing CSS styles that might be overriding your preferred style, take a look at this: https://www.styled-components.com/docs/advanced#existing-css
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
If it's still not working, you might have CSS styles somewhere that overrides this style. If you are familiar with the "point system" in CSS, you should have known the problem.
– Sandy Brutas
Nov 19 at 8:36
add a comment |
up vote
0
down vote
You don't have to put single quote around #fff
export const MyStyle = styled.div`
background-color: #fff;
`;
EDITED:
If there are overriding CSS styles that make your div's background not white just yet, and you can't find them, just add !important
to this style
export const MyStyle = styled.div`
background-color: #fff !important;
`;
Regarding the issue about finding existing CSS styles that might be overriding your preferred style, take a look at this: https://www.styled-components.com/docs/advanced#existing-css
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
If it's still not working, you might have CSS styles somewhere that overrides this style. If you are familiar with the "point system" in CSS, you should have known the problem.
– Sandy Brutas
Nov 19 at 8:36
add a comment |
up vote
0
down vote
up vote
0
down vote
You don't have to put single quote around #fff
export const MyStyle = styled.div`
background-color: #fff;
`;
EDITED:
If there are overriding CSS styles that make your div's background not white just yet, and you can't find them, just add !important
to this style
export const MyStyle = styled.div`
background-color: #fff !important;
`;
Regarding the issue about finding existing CSS styles that might be overriding your preferred style, take a look at this: https://www.styled-components.com/docs/advanced#existing-css
You don't have to put single quote around #fff
export const MyStyle = styled.div`
background-color: #fff;
`;
EDITED:
If there are overriding CSS styles that make your div's background not white just yet, and you can't find them, just add !important
to this style
export const MyStyle = styled.div`
background-color: #fff !important;
`;
Regarding the issue about finding existing CSS styles that might be overriding your preferred style, take a look at this: https://www.styled-components.com/docs/advanced#existing-css
edited Nov 19 at 8:48
answered Nov 19 at 8:29
Sandy Brutas
454312
454312
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
If it's still not working, you might have CSS styles somewhere that overrides this style. If you are familiar with the "point system" in CSS, you should have known the problem.
– Sandy Brutas
Nov 19 at 8:36
add a comment |
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
If it's still not working, you might have CSS styles somewhere that overrides this style. If you are familiar with the "point system" in CSS, you should have known the problem.
– Sandy Brutas
Nov 19 at 8:36
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
Thanks. Removed single quotes around the color name. Still, it's not working.
– brig
Nov 19 at 8:33
If it's still not working, you might have CSS styles somewhere that overrides this style. If you are familiar with the "point system" in CSS, you should have known the problem.
– Sandy Brutas
Nov 19 at 8:36
If it's still not working, you might have CSS styles somewhere that overrides this style. If you are familiar with the "point system" in CSS, you should have known the problem.
– Sandy Brutas
Nov 19 at 8:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370816%2fstyles-are-not-working-in-through-styled-components%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown