How to use css modules (react semantic ui) in create react app?












0















I am using react semantic ui and I want to add margin left and margin top for Table component (i.e align it in center) I also want to reduce the cell size inside Table but my css is not working why so ? Do I need to add any css loader or scss loader ? I am not able to understand why is my CSS code not working ?



Note: Table component has a prop called className and I want to make use of className prop and add custom styles. Link: https://react.semantic-ui.com/collections/table/#types-pagination



updatePage.js:



    import React, { Component } from 'react';
import { Icon, Label, Menu, Table } from 'semantic-ui-react';
import faker from 'faker';
import s from './updatesPage.css';

const UpdatesPage = () => (
<Table celled className={s.updateForm}>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Name</Table.HeaderCell>
<Table.HeaderCell>URN number</Table.HeaderCell>
<Table.HeaderCell>Parish</Table.HeaderCell>
<Table.HeaderCell>Last Updated</Table.HeaderCell>
<Table.HeaderCell>Notes</Table.HeaderCell>
</Table.Row>
</Table.Header>

<Table.Body>
<Table.Row>
<Table.Cell>{faker.name.findName()}</Table.Cell>
<Table.Cell>{faker.random.number()}</Table.Cell>
<Table.Cell>{faker.address.streetAddress()}</Table.Cell>
<Table.Cell>{faker.date.weekday()}</Table.Cell>
<Table.Cell>{faker.random.words()}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>{faker.name.findName()}</Table.Cell>
<Table.Cell>{faker.random.number()}</Table.Cell>
<Table.Cell>{faker.address.streetAddress()}</Table.Cell>
<Table.Cell>{faker.date.weekday()}</Table.Cell>
<Table.Cell>{faker.random.words()}</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
)

export default UpdatesPage;


updatePage.css:



.updateForm {
margin-top: 100px;
margin-left: 50px;
}


Above code is working i.e javascript is working but the CSS is not working why so ? See screenshot: https://imgur.com/a/sBEUA6J I am not able to see any margin top, left for table.










share|improve this question





























    0















    I am using react semantic ui and I want to add margin left and margin top for Table component (i.e align it in center) I also want to reduce the cell size inside Table but my css is not working why so ? Do I need to add any css loader or scss loader ? I am not able to understand why is my CSS code not working ?



    Note: Table component has a prop called className and I want to make use of className prop and add custom styles. Link: https://react.semantic-ui.com/collections/table/#types-pagination



    updatePage.js:



        import React, { Component } from 'react';
    import { Icon, Label, Menu, Table } from 'semantic-ui-react';
    import faker from 'faker';
    import s from './updatesPage.css';

    const UpdatesPage = () => (
    <Table celled className={s.updateForm}>
    <Table.Header>
    <Table.Row>
    <Table.HeaderCell>Name</Table.HeaderCell>
    <Table.HeaderCell>URN number</Table.HeaderCell>
    <Table.HeaderCell>Parish</Table.HeaderCell>
    <Table.HeaderCell>Last Updated</Table.HeaderCell>
    <Table.HeaderCell>Notes</Table.HeaderCell>
    </Table.Row>
    </Table.Header>

    <Table.Body>
    <Table.Row>
    <Table.Cell>{faker.name.findName()}</Table.Cell>
    <Table.Cell>{faker.random.number()}</Table.Cell>
    <Table.Cell>{faker.address.streetAddress()}</Table.Cell>
    <Table.Cell>{faker.date.weekday()}</Table.Cell>
    <Table.Cell>{faker.random.words()}</Table.Cell>
    </Table.Row>
    <Table.Row>
    <Table.Cell>{faker.name.findName()}</Table.Cell>
    <Table.Cell>{faker.random.number()}</Table.Cell>
    <Table.Cell>{faker.address.streetAddress()}</Table.Cell>
    <Table.Cell>{faker.date.weekday()}</Table.Cell>
    <Table.Cell>{faker.random.words()}</Table.Cell>
    </Table.Row>
    </Table.Body>
    </Table>
    )

    export default UpdatesPage;


    updatePage.css:



    .updateForm {
    margin-top: 100px;
    margin-left: 50px;
    }


    Above code is working i.e javascript is working but the CSS is not working why so ? See screenshot: https://imgur.com/a/sBEUA6J I am not able to see any margin top, left for table.










    share|improve this question



























      0












      0








      0








      I am using react semantic ui and I want to add margin left and margin top for Table component (i.e align it in center) I also want to reduce the cell size inside Table but my css is not working why so ? Do I need to add any css loader or scss loader ? I am not able to understand why is my CSS code not working ?



      Note: Table component has a prop called className and I want to make use of className prop and add custom styles. Link: https://react.semantic-ui.com/collections/table/#types-pagination



      updatePage.js:



          import React, { Component } from 'react';
      import { Icon, Label, Menu, Table } from 'semantic-ui-react';
      import faker from 'faker';
      import s from './updatesPage.css';

      const UpdatesPage = () => (
      <Table celled className={s.updateForm}>
      <Table.Header>
      <Table.Row>
      <Table.HeaderCell>Name</Table.HeaderCell>
      <Table.HeaderCell>URN number</Table.HeaderCell>
      <Table.HeaderCell>Parish</Table.HeaderCell>
      <Table.HeaderCell>Last Updated</Table.HeaderCell>
      <Table.HeaderCell>Notes</Table.HeaderCell>
      </Table.Row>
      </Table.Header>

      <Table.Body>
      <Table.Row>
      <Table.Cell>{faker.name.findName()}</Table.Cell>
      <Table.Cell>{faker.random.number()}</Table.Cell>
      <Table.Cell>{faker.address.streetAddress()}</Table.Cell>
      <Table.Cell>{faker.date.weekday()}</Table.Cell>
      <Table.Cell>{faker.random.words()}</Table.Cell>
      </Table.Row>
      <Table.Row>
      <Table.Cell>{faker.name.findName()}</Table.Cell>
      <Table.Cell>{faker.random.number()}</Table.Cell>
      <Table.Cell>{faker.address.streetAddress()}</Table.Cell>
      <Table.Cell>{faker.date.weekday()}</Table.Cell>
      <Table.Cell>{faker.random.words()}</Table.Cell>
      </Table.Row>
      </Table.Body>
      </Table>
      )

      export default UpdatesPage;


      updatePage.css:



      .updateForm {
      margin-top: 100px;
      margin-left: 50px;
      }


      Above code is working i.e javascript is working but the CSS is not working why so ? See screenshot: https://imgur.com/a/sBEUA6J I am not able to see any margin top, left for table.










      share|improve this question
















      I am using react semantic ui and I want to add margin left and margin top for Table component (i.e align it in center) I also want to reduce the cell size inside Table but my css is not working why so ? Do I need to add any css loader or scss loader ? I am not able to understand why is my CSS code not working ?



      Note: Table component has a prop called className and I want to make use of className prop and add custom styles. Link: https://react.semantic-ui.com/collections/table/#types-pagination



      updatePage.js:



          import React, { Component } from 'react';
      import { Icon, Label, Menu, Table } from 'semantic-ui-react';
      import faker from 'faker';
      import s from './updatesPage.css';

      const UpdatesPage = () => (
      <Table celled className={s.updateForm}>
      <Table.Header>
      <Table.Row>
      <Table.HeaderCell>Name</Table.HeaderCell>
      <Table.HeaderCell>URN number</Table.HeaderCell>
      <Table.HeaderCell>Parish</Table.HeaderCell>
      <Table.HeaderCell>Last Updated</Table.HeaderCell>
      <Table.HeaderCell>Notes</Table.HeaderCell>
      </Table.Row>
      </Table.Header>

      <Table.Body>
      <Table.Row>
      <Table.Cell>{faker.name.findName()}</Table.Cell>
      <Table.Cell>{faker.random.number()}</Table.Cell>
      <Table.Cell>{faker.address.streetAddress()}</Table.Cell>
      <Table.Cell>{faker.date.weekday()}</Table.Cell>
      <Table.Cell>{faker.random.words()}</Table.Cell>
      </Table.Row>
      <Table.Row>
      <Table.Cell>{faker.name.findName()}</Table.Cell>
      <Table.Cell>{faker.random.number()}</Table.Cell>
      <Table.Cell>{faker.address.streetAddress()}</Table.Cell>
      <Table.Cell>{faker.date.weekday()}</Table.Cell>
      <Table.Cell>{faker.random.words()}</Table.Cell>
      </Table.Row>
      </Table.Body>
      </Table>
      )

      export default UpdatesPage;


      updatePage.css:



      .updateForm {
      margin-top: 100px;
      margin-left: 50px;
      }


      Above code is working i.e javascript is working but the CSS is not working why so ? See screenshot: https://imgur.com/a/sBEUA6J I am not able to see any margin top, left for table.







      javascript html css reactjs






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 5:17







      fun joker

















      asked Nov 16 '18 at 4:56









      fun jokerfun joker

      604113




      604113
























          2 Answers
          2






          active

          oldest

          votes


















          1














          The issue with line import css. While import the css no need to give the module name for it. Just change the import line as below, it will work



          import './updatesPage.css';


          Also change the code for className as below



          <Table celled className='updateForm'>


          Like sematic ui take priority while setting the css. So you need to change the priority in css add !important.



          .updateForm {
          margin-top: 100px !important;
          margin-left: 50px !important;
          }





          share|improve this answer


























          • I am using CSS modules in create react app.

            – fun joker
            Nov 16 '18 at 5:14











          • it is not working. Note: I am using react semantic ui and Table component has a className prop

            – fun joker
            Nov 16 '18 at 5:16











          • Change the classname too. I have edited the answer.

            – kumar k
            Nov 16 '18 at 5:18











          • No it doesn't work. Note: I am using react semantic ui -> react.semantic-ui.com/collections/table/#types-pagination

            – fun joker
            Nov 16 '18 at 5:23











          • Please take screenshot again and upload it here.

            – kumar k
            Nov 16 '18 at 5:32



















          2














          In order to use CSS modules with create-react-app you need to rename your css file to updatesPage.module.css.



          You can find documentation for this in the “Adding a CSS Modules Stylesheet” portion of the user guide






          share|improve this answer


























          • Do I need to make any changes in webpack.config file in node modules -> react scripts ?

            – fun joker
            Nov 16 '18 at 5:06











          • No, CRA using the file naming convention of *.module.css to indicate use of css modules, otherwise it interprets it as a regular css file.

            – Ryan Cogswell
            Nov 16 '18 at 5:08











          • It is not working why so ? screenshot : imgur.com/a/e3bsCvf

            – fun joker
            Nov 16 '18 at 5:11











          • I saw your updated answer and I am doing same thing but it is not working any idea how to reduce size of table and align it ? margin left and margin top not working

            – fun joker
            Nov 16 '18 at 5:15











          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',
          autoActivateHeartbeat: false,
          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%2f53331680%2fhow-to-use-css-modules-react-semantic-ui-in-create-react-app%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









          1














          The issue with line import css. While import the css no need to give the module name for it. Just change the import line as below, it will work



          import './updatesPage.css';


          Also change the code for className as below



          <Table celled className='updateForm'>


          Like sematic ui take priority while setting the css. So you need to change the priority in css add !important.



          .updateForm {
          margin-top: 100px !important;
          margin-left: 50px !important;
          }





          share|improve this answer


























          • I am using CSS modules in create react app.

            – fun joker
            Nov 16 '18 at 5:14











          • it is not working. Note: I am using react semantic ui and Table component has a className prop

            – fun joker
            Nov 16 '18 at 5:16











          • Change the classname too. I have edited the answer.

            – kumar k
            Nov 16 '18 at 5:18











          • No it doesn't work. Note: I am using react semantic ui -> react.semantic-ui.com/collections/table/#types-pagination

            – fun joker
            Nov 16 '18 at 5:23











          • Please take screenshot again and upload it here.

            – kumar k
            Nov 16 '18 at 5:32
















          1














          The issue with line import css. While import the css no need to give the module name for it. Just change the import line as below, it will work



          import './updatesPage.css';


          Also change the code for className as below



          <Table celled className='updateForm'>


          Like sematic ui take priority while setting the css. So you need to change the priority in css add !important.



          .updateForm {
          margin-top: 100px !important;
          margin-left: 50px !important;
          }





          share|improve this answer


























          • I am using CSS modules in create react app.

            – fun joker
            Nov 16 '18 at 5:14











          • it is not working. Note: I am using react semantic ui and Table component has a className prop

            – fun joker
            Nov 16 '18 at 5:16











          • Change the classname too. I have edited the answer.

            – kumar k
            Nov 16 '18 at 5:18











          • No it doesn't work. Note: I am using react semantic ui -> react.semantic-ui.com/collections/table/#types-pagination

            – fun joker
            Nov 16 '18 at 5:23











          • Please take screenshot again and upload it here.

            – kumar k
            Nov 16 '18 at 5:32














          1












          1








          1







          The issue with line import css. While import the css no need to give the module name for it. Just change the import line as below, it will work



          import './updatesPage.css';


          Also change the code for className as below



          <Table celled className='updateForm'>


          Like sematic ui take priority while setting the css. So you need to change the priority in css add !important.



          .updateForm {
          margin-top: 100px !important;
          margin-left: 50px !important;
          }





          share|improve this answer















          The issue with line import css. While import the css no need to give the module name for it. Just change the import line as below, it will work



          import './updatesPage.css';


          Also change the code for className as below



          <Table celled className='updateForm'>


          Like sematic ui take priority while setting the css. So you need to change the priority in css add !important.



          .updateForm {
          margin-top: 100px !important;
          margin-left: 50px !important;
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 6:54

























          answered Nov 16 '18 at 5:13









          kumar kkumar k

          34417




          34417













          • I am using CSS modules in create react app.

            – fun joker
            Nov 16 '18 at 5:14











          • it is not working. Note: I am using react semantic ui and Table component has a className prop

            – fun joker
            Nov 16 '18 at 5:16











          • Change the classname too. I have edited the answer.

            – kumar k
            Nov 16 '18 at 5:18











          • No it doesn't work. Note: I am using react semantic ui -> react.semantic-ui.com/collections/table/#types-pagination

            – fun joker
            Nov 16 '18 at 5:23











          • Please take screenshot again and upload it here.

            – kumar k
            Nov 16 '18 at 5:32



















          • I am using CSS modules in create react app.

            – fun joker
            Nov 16 '18 at 5:14











          • it is not working. Note: I am using react semantic ui and Table component has a className prop

            – fun joker
            Nov 16 '18 at 5:16











          • Change the classname too. I have edited the answer.

            – kumar k
            Nov 16 '18 at 5:18











          • No it doesn't work. Note: I am using react semantic ui -> react.semantic-ui.com/collections/table/#types-pagination

            – fun joker
            Nov 16 '18 at 5:23











          • Please take screenshot again and upload it here.

            – kumar k
            Nov 16 '18 at 5:32

















          I am using CSS modules in create react app.

          – fun joker
          Nov 16 '18 at 5:14





          I am using CSS modules in create react app.

          – fun joker
          Nov 16 '18 at 5:14













          it is not working. Note: I am using react semantic ui and Table component has a className prop

          – fun joker
          Nov 16 '18 at 5:16





          it is not working. Note: I am using react semantic ui and Table component has a className prop

          – fun joker
          Nov 16 '18 at 5:16













          Change the classname too. I have edited the answer.

          – kumar k
          Nov 16 '18 at 5:18





          Change the classname too. I have edited the answer.

          – kumar k
          Nov 16 '18 at 5:18













          No it doesn't work. Note: I am using react semantic ui -> react.semantic-ui.com/collections/table/#types-pagination

          – fun joker
          Nov 16 '18 at 5:23





          No it doesn't work. Note: I am using react semantic ui -> react.semantic-ui.com/collections/table/#types-pagination

          – fun joker
          Nov 16 '18 at 5:23













          Please take screenshot again and upload it here.

          – kumar k
          Nov 16 '18 at 5:32





          Please take screenshot again and upload it here.

          – kumar k
          Nov 16 '18 at 5:32













          2














          In order to use CSS modules with create-react-app you need to rename your css file to updatesPage.module.css.



          You can find documentation for this in the “Adding a CSS Modules Stylesheet” portion of the user guide






          share|improve this answer


























          • Do I need to make any changes in webpack.config file in node modules -> react scripts ?

            – fun joker
            Nov 16 '18 at 5:06











          • No, CRA using the file naming convention of *.module.css to indicate use of css modules, otherwise it interprets it as a regular css file.

            – Ryan Cogswell
            Nov 16 '18 at 5:08











          • It is not working why so ? screenshot : imgur.com/a/e3bsCvf

            – fun joker
            Nov 16 '18 at 5:11











          • I saw your updated answer and I am doing same thing but it is not working any idea how to reduce size of table and align it ? margin left and margin top not working

            – fun joker
            Nov 16 '18 at 5:15
















          2














          In order to use CSS modules with create-react-app you need to rename your css file to updatesPage.module.css.



          You can find documentation for this in the “Adding a CSS Modules Stylesheet” portion of the user guide






          share|improve this answer


























          • Do I need to make any changes in webpack.config file in node modules -> react scripts ?

            – fun joker
            Nov 16 '18 at 5:06











          • No, CRA using the file naming convention of *.module.css to indicate use of css modules, otherwise it interprets it as a regular css file.

            – Ryan Cogswell
            Nov 16 '18 at 5:08











          • It is not working why so ? screenshot : imgur.com/a/e3bsCvf

            – fun joker
            Nov 16 '18 at 5:11











          • I saw your updated answer and I am doing same thing but it is not working any idea how to reduce size of table and align it ? margin left and margin top not working

            – fun joker
            Nov 16 '18 at 5:15














          2












          2








          2







          In order to use CSS modules with create-react-app you need to rename your css file to updatesPage.module.css.



          You can find documentation for this in the “Adding a CSS Modules Stylesheet” portion of the user guide






          share|improve this answer















          In order to use CSS modules with create-react-app you need to rename your css file to updatesPage.module.css.



          You can find documentation for this in the “Adding a CSS Modules Stylesheet” portion of the user guide







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 5:12

























          answered Nov 16 '18 at 5:05









          Ryan CogswellRyan Cogswell

          5,4611624




          5,4611624













          • Do I need to make any changes in webpack.config file in node modules -> react scripts ?

            – fun joker
            Nov 16 '18 at 5:06











          • No, CRA using the file naming convention of *.module.css to indicate use of css modules, otherwise it interprets it as a regular css file.

            – Ryan Cogswell
            Nov 16 '18 at 5:08











          • It is not working why so ? screenshot : imgur.com/a/e3bsCvf

            – fun joker
            Nov 16 '18 at 5:11











          • I saw your updated answer and I am doing same thing but it is not working any idea how to reduce size of table and align it ? margin left and margin top not working

            – fun joker
            Nov 16 '18 at 5:15



















          • Do I need to make any changes in webpack.config file in node modules -> react scripts ?

            – fun joker
            Nov 16 '18 at 5:06











          • No, CRA using the file naming convention of *.module.css to indicate use of css modules, otherwise it interprets it as a regular css file.

            – Ryan Cogswell
            Nov 16 '18 at 5:08











          • It is not working why so ? screenshot : imgur.com/a/e3bsCvf

            – fun joker
            Nov 16 '18 at 5:11











          • I saw your updated answer and I am doing same thing but it is not working any idea how to reduce size of table and align it ? margin left and margin top not working

            – fun joker
            Nov 16 '18 at 5:15

















          Do I need to make any changes in webpack.config file in node modules -> react scripts ?

          – fun joker
          Nov 16 '18 at 5:06





          Do I need to make any changes in webpack.config file in node modules -> react scripts ?

          – fun joker
          Nov 16 '18 at 5:06













          No, CRA using the file naming convention of *.module.css to indicate use of css modules, otherwise it interprets it as a regular css file.

          – Ryan Cogswell
          Nov 16 '18 at 5:08





          No, CRA using the file naming convention of *.module.css to indicate use of css modules, otherwise it interprets it as a regular css file.

          – Ryan Cogswell
          Nov 16 '18 at 5:08













          It is not working why so ? screenshot : imgur.com/a/e3bsCvf

          – fun joker
          Nov 16 '18 at 5:11





          It is not working why so ? screenshot : imgur.com/a/e3bsCvf

          – fun joker
          Nov 16 '18 at 5:11













          I saw your updated answer and I am doing same thing but it is not working any idea how to reduce size of table and align it ? margin left and margin top not working

          – fun joker
          Nov 16 '18 at 5:15





          I saw your updated answer and I am doing same thing but it is not working any idea how to reduce size of table and align it ? margin left and margin top not working

          – fun joker
          Nov 16 '18 at 5:15


















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331680%2fhow-to-use-css-modules-react-semantic-ui-in-create-react-app%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

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python