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?










share|improve this question


























    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?










    share|improve this question
























      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 at 8:27









      brig

      1,40693251




      1,40693251
























          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.






          share|improve this answer





















          • 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




















          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






          share|improve this answer























          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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.






          share|improve this answer





















          • 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

















          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.






          share|improve this answer





















          • 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















          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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




















          • 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














          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






          share|improve this answer























          • 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















          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






          share|improve this answer























          • 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













          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






          share|improve this answer














          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







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]