Access HTML by id through SASS












0















Is there a possibility to access an HTML element by id through SASS? I use SASS in combination with React in TSX files. Normally for styling I would define a SASS entry and add that entry to the list of classes, as shown in the following example:



Report.sass:



.city {
color: red;
}


Report.tsx:



import * as React from "react";
import * as Style from "./Report.scss";

export class Report extends React.Component<{}, {}> {
public render() {
return <div className={Style.city}>Test text for cities</div>;
}
}


This example works perfectly fine. But if I now gave the div tag an id, I would need to also change the SASS file accordingly. This through fails, as shown here:



Report.sass:



#city {
color: red;
}


Report.tsx:



import * as React from "react";
import * as Style from "./Report.scss";

export class Report extends React.Component<{}, {}> {
public render() {
return <div id="city">Test text for cities</div>;
}
}


I believe that the SASS file forgets about the #city entry as there is no pointer in the Report.tsx to it. Am I right with this assumption? How could I make the SASS command work with the city id?










share|improve this question



























    0















    Is there a possibility to access an HTML element by id through SASS? I use SASS in combination with React in TSX files. Normally for styling I would define a SASS entry and add that entry to the list of classes, as shown in the following example:



    Report.sass:



    .city {
    color: red;
    }


    Report.tsx:



    import * as React from "react";
    import * as Style from "./Report.scss";

    export class Report extends React.Component<{}, {}> {
    public render() {
    return <div className={Style.city}>Test text for cities</div>;
    }
    }


    This example works perfectly fine. But if I now gave the div tag an id, I would need to also change the SASS file accordingly. This through fails, as shown here:



    Report.sass:



    #city {
    color: red;
    }


    Report.tsx:



    import * as React from "react";
    import * as Style from "./Report.scss";

    export class Report extends React.Component<{}, {}> {
    public render() {
    return <div id="city">Test text for cities</div>;
    }
    }


    I believe that the SASS file forgets about the #city entry as there is no pointer in the Report.tsx to it. Am I right with this assumption? How could I make the SASS command work with the city id?










    share|improve this question

























      0












      0








      0








      Is there a possibility to access an HTML element by id through SASS? I use SASS in combination with React in TSX files. Normally for styling I would define a SASS entry and add that entry to the list of classes, as shown in the following example:



      Report.sass:



      .city {
      color: red;
      }


      Report.tsx:



      import * as React from "react";
      import * as Style from "./Report.scss";

      export class Report extends React.Component<{}, {}> {
      public render() {
      return <div className={Style.city}>Test text for cities</div>;
      }
      }


      This example works perfectly fine. But if I now gave the div tag an id, I would need to also change the SASS file accordingly. This through fails, as shown here:



      Report.sass:



      #city {
      color: red;
      }


      Report.tsx:



      import * as React from "react";
      import * as Style from "./Report.scss";

      export class Report extends React.Component<{}, {}> {
      public render() {
      return <div id="city">Test text for cities</div>;
      }
      }


      I believe that the SASS file forgets about the #city entry as there is no pointer in the Report.tsx to it. Am I right with this assumption? How could I make the SASS command work with the city id?










      share|improve this question














      Is there a possibility to access an HTML element by id through SASS? I use SASS in combination with React in TSX files. Normally for styling I would define a SASS entry and add that entry to the list of classes, as shown in the following example:



      Report.sass:



      .city {
      color: red;
      }


      Report.tsx:



      import * as React from "react";
      import * as Style from "./Report.scss";

      export class Report extends React.Component<{}, {}> {
      public render() {
      return <div className={Style.city}>Test text for cities</div>;
      }
      }


      This example works perfectly fine. But if I now gave the div tag an id, I would need to also change the SASS file accordingly. This through fails, as shown here:



      Report.sass:



      #city {
      color: red;
      }


      Report.tsx:



      import * as React from "react";
      import * as Style from "./Report.scss";

      export class Report extends React.Component<{}, {}> {
      public render() {
      return <div id="city">Test text for cities</div>;
      }
      }


      I believe that the SASS file forgets about the #city entry as there is no pointer in the Report.tsx to it. Am I right with this assumption? How could I make the SASS command work with the city id?







      css reactjs sass jsx tsx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 1:41









      SocratesSocrates

      1,71382547




      1,71382547
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I think theres some misunderstandings about css and html.



          You can have both a class and id tag for each html element.



          Therefore it will compile fine if you have the following:



          <div id="NewYork" className={Style.city}>


          This is an unorthodox way to apply styles in React though. The easier way is to import the stylesheet via



          import './Report.scss';


          then you can use your styles more freely like so:



          <div id="NewYork" className="city">





          share|improve this answer
























          • Your second example does not work with my settings. If I change from import * as Style from "./Report.scss"; to import './Report.scss'; and from <div className={Style.city}>Test text for cities</div> to <div className="city">Test text for cities</div> the CSS properties vanish and have no effect the result. Is there any special project setting necessary for this to work?

            – Socrates
            Nov 26 '18 at 13:32











          • You could try require('./Report.scss') but the import way should work if its not giving you an error. The .city { ... } would apply to className="city"

            – Shawn Andrews
            Nov 26 '18 at 17:26











          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%2f53473762%2faccess-html-by-id-through-sass%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I think theres some misunderstandings about css and html.



          You can have both a class and id tag for each html element.



          Therefore it will compile fine if you have the following:



          <div id="NewYork" className={Style.city}>


          This is an unorthodox way to apply styles in React though. The easier way is to import the stylesheet via



          import './Report.scss';


          then you can use your styles more freely like so:



          <div id="NewYork" className="city">





          share|improve this answer
























          • Your second example does not work with my settings. If I change from import * as Style from "./Report.scss"; to import './Report.scss'; and from <div className={Style.city}>Test text for cities</div> to <div className="city">Test text for cities</div> the CSS properties vanish and have no effect the result. Is there any special project setting necessary for this to work?

            – Socrates
            Nov 26 '18 at 13:32











          • You could try require('./Report.scss') but the import way should work if its not giving you an error. The .city { ... } would apply to className="city"

            – Shawn Andrews
            Nov 26 '18 at 17:26
















          0














          I think theres some misunderstandings about css and html.



          You can have both a class and id tag for each html element.



          Therefore it will compile fine if you have the following:



          <div id="NewYork" className={Style.city}>


          This is an unorthodox way to apply styles in React though. The easier way is to import the stylesheet via



          import './Report.scss';


          then you can use your styles more freely like so:



          <div id="NewYork" className="city">





          share|improve this answer
























          • Your second example does not work with my settings. If I change from import * as Style from "./Report.scss"; to import './Report.scss'; and from <div className={Style.city}>Test text for cities</div> to <div className="city">Test text for cities</div> the CSS properties vanish and have no effect the result. Is there any special project setting necessary for this to work?

            – Socrates
            Nov 26 '18 at 13:32











          • You could try require('./Report.scss') but the import way should work if its not giving you an error. The .city { ... } would apply to className="city"

            – Shawn Andrews
            Nov 26 '18 at 17:26














          0












          0








          0







          I think theres some misunderstandings about css and html.



          You can have both a class and id tag for each html element.



          Therefore it will compile fine if you have the following:



          <div id="NewYork" className={Style.city}>


          This is an unorthodox way to apply styles in React though. The easier way is to import the stylesheet via



          import './Report.scss';


          then you can use your styles more freely like so:



          <div id="NewYork" className="city">





          share|improve this answer













          I think theres some misunderstandings about css and html.



          You can have both a class and id tag for each html element.



          Therefore it will compile fine if you have the following:



          <div id="NewYork" className={Style.city}>


          This is an unorthodox way to apply styles in React though. The easier way is to import the stylesheet via



          import './Report.scss';


          then you can use your styles more freely like so:



          <div id="NewYork" className="city">






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 '18 at 2:22









          Shawn AndrewsShawn Andrews

          965718




          965718













          • Your second example does not work with my settings. If I change from import * as Style from "./Report.scss"; to import './Report.scss'; and from <div className={Style.city}>Test text for cities</div> to <div className="city">Test text for cities</div> the CSS properties vanish and have no effect the result. Is there any special project setting necessary for this to work?

            – Socrates
            Nov 26 '18 at 13:32











          • You could try require('./Report.scss') but the import way should work if its not giving you an error. The .city { ... } would apply to className="city"

            – Shawn Andrews
            Nov 26 '18 at 17:26



















          • Your second example does not work with my settings. If I change from import * as Style from "./Report.scss"; to import './Report.scss'; and from <div className={Style.city}>Test text for cities</div> to <div className="city">Test text for cities</div> the CSS properties vanish and have no effect the result. Is there any special project setting necessary for this to work?

            – Socrates
            Nov 26 '18 at 13:32











          • You could try require('./Report.scss') but the import way should work if its not giving you an error. The .city { ... } would apply to className="city"

            – Shawn Andrews
            Nov 26 '18 at 17:26

















          Your second example does not work with my settings. If I change from import * as Style from "./Report.scss"; to import './Report.scss'; and from <div className={Style.city}>Test text for cities</div> to <div className="city">Test text for cities</div> the CSS properties vanish and have no effect the result. Is there any special project setting necessary for this to work?

          – Socrates
          Nov 26 '18 at 13:32





          Your second example does not work with my settings. If I change from import * as Style from "./Report.scss"; to import './Report.scss'; and from <div className={Style.city}>Test text for cities</div> to <div className="city">Test text for cities</div> the CSS properties vanish and have no effect the result. Is there any special project setting necessary for this to work?

          – Socrates
          Nov 26 '18 at 13:32













          You could try require('./Report.scss') but the import way should work if its not giving you an error. The .city { ... } would apply to className="city"

          – Shawn Andrews
          Nov 26 '18 at 17:26





          You could try require('./Report.scss') but the import way should work if its not giving you an error. The .city { ... } would apply to className="city"

          – Shawn Andrews
          Nov 26 '18 at 17:26




















          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%2f53473762%2faccess-html-by-id-through-sass%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

          Costa Masnaga

          Fotorealismo

          Create new schema in PostgreSQL using DBeaver