What is the best practice for dynamic CSS sizing according screen do you have information on less-CSS

What is the best practice for dynamic CSS sizing according screen do you have information on less-CSS

Hi,

Here I gave some code I did that is running BUT
I imaginated it and I believe this solution is not very practical to use.

MY PURPOSE IS TO GENERATE DYNAMIC CSS.

I have used media query in the begining but I cannont size for every screen so many
they become now a days.



  1. @media screen and (max-width: 485px) {
  2.  body {
  3. text-align:center;
  4. font:0.9em "trebuchet ms", helvetica, arial, sans-serif;
  5. background-color:blue;
  6. word-wrap: break-word;

  7. .mytable
  8. {
  9. width:400px;
  10. }

  11. }

so I created a JQUERY script to detect the size odf the screen and change CSS properties

  1. $(document).ready( function() {
  2. var str=parseInt($(window).width())-parseInt(100);
  3. $(".mytable").css("width", str );
  4. });
  5. $( window ).resize(function() {
  6. var str=parseInt($(window).width())-parseInt(100);
  7. $(".mytable").css("width", str );
  8. });

Personnaly I doubt this solution is the best one and I have a lot of CSS in my website
that insist on picture digital art sizing 
I imagine not so much to encode dynamic JQUERY CSS for every element.

I have heard of less-css a little but haven't managed to make it work.

Can some one tell me the best practice and were I can find links that are OK to implement a solution not too much difficult ( ex php not python and yalm...)

Thanks a lot 
Best reagards

David

  1. <!DOCTYPE html>
  2. <html>
  3.   <head>

  4.     <title>HOW to do CSS adapting to smartphone browser ...</title>
  5.  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

  6. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>

  7. <!--Problem should adapt dynamically so I use a solution with JQUERY -->

  8. <style type="text/css">



  9. table,td,th
  10. {
  11. border:1px solid black;
  12. }
  13. td
  14. {
  15. text-align:right;
  16. }


  17. @media screen and (max-width: 485px) {
  18.  body {
  19. text-align:center;
  20. font:0.9em "trebuchet ms", helvetica, arial, sans-serif;
  21. background-color:blue;
  22. word-wrap: break-word;


  23. .mytable
  24. {
  25. width:400px;
  26. }


  27. }

  28. @media screen and (min-width: 485px) and (max-width: 1100px) {
  29.  body {
  30. text-align:center;
  31. font:0.9em "trebuchet ms", helvetica, arial, sans-serif;
  32. background-color:red;
  33. word-wrap: break-word;


  34. .mytable
  35. {
  36. width:500px;
  37. }


  38. }



  39. @media screen and (min-width: 1100px) {
  40.  body {
  41. text-align:center;
  42. font:0.9em "trebuchet ms", helvetica, arial, sans-serif;
  43. background-color:green;
  44. word-wrap: break-word;


  45. .mytable
  46. {
  47. width:1000px;
  48. }


  49. }


  50. .th1
  51. {
  52. width:20%;
  53. }
  54. .th2
  55. {
  56. width:50%;
  57. }
  58. .th3
  59. {
  60. width:30%;
  61. }

  62. </style>


  63.  
  64.  </head>
  65.   <body>
  66. <span id="msg">my message: </span>
  67.  
  68.  
  69.  <div id="mytable">
  70. <table class="mytable">
  71. <tr>
  72. <th class="th1">Firstname</th>
  73. <th class="th2">Lastname</th>
  74. <th class="th3">Savings</th>
  75. </tr>
  76. <tr>
  77. <td>Peter</td>
  78. <td>Griffin</td>
  79. <td>$100</td>
  80. </tr>
  81. <tr>
  82. <td>Lois</td>
  83. <td>Griffin</td>
  84. <td>$150</td>
  85. </tr>
  86. <tr>
  87. <td>Joe</td>
  88. <td>Swanson</td>
  89. <td>$300</td>
  90. </tr>
  91. <tr>
  92. <td>Cleveland</td>
  93. <td>Brown</td>
  94. <td>$250</td>
  95. </tr>
  96. </table>
  97.  </div>
  98.     <script>
  99.       $(function() {
  100. $(document).ready( function() {
  101. var str=parseInt($(window).width())-parseInt(100);
  102. $(".mytable").css("width", str );
  103. });
  104. $( window ).resize(function() {
  105. var str=parseInt($(window).width())-parseInt(100);
  106. $(".mytable").css("width", str );
  107. });



  108. });
  109.     
  110.     </script>
  111.   </body>
  112. </html>

David  ( @webtecgeek   www.thecacaocafe.com )