Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to raise the margin of text only on desktop version?

I’m new to Javascript. I’m trying to raise the margin of the text only on the desktop version, not on mobile. Could you help me find the problem.

<p id="myID">Lorem ipsum dolor sit amet, prima harum elitr te pri. Vix partiendo sententiae ad. Duo at amet dicam tempor. Numquam ceteros concludaturque in eum, id nec adhuc aliquando scriptorem, has ea consetetur cotidieque consectetuer. In verear neglegentur eam.</p>   

  <script>
    
      let screenwidth=window.innerWidth;
      
    
          if (screenwidth > "768px")
              {
            document.getElementById("myID").style.marginLeft = "150px";
      }
             
      else {
          document.getElementById("myID").style.marginLeft= "0px";
      }
      </script> 

Unfortunately I couldnt find the problem by myself

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Replace "768px" by 768. Must be a number and not a string 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading