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.
- @media screen and (max-width: 485px) {
- body {
- text-align:center;
- font:0.9em "trebuchet ms", helvetica, arial, sans-serif;
- background-color:blue;
- word-wrap: break-word;
- }
- .mytable
- {
- width:400px;
- }
- }
so I created a JQUERY script to detect the size odf the screen and change CSS properties
- $(document).ready( function() {
- var str=parseInt($(window).width())-parseInt(100);
- $(".mytable").css("width", str );
- });
-
- $( window ).resize(function() {
- var str=parseInt($(window).width())-parseInt(100);
- $(".mytable").css("width", str );
- });
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
- <!DOCTYPE html>
- <html>
- <head>
- <title>HOW to do CSS adapting to smartphone browser ...</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
- <!--Problem should adapt dynamically so I use a solution with JQUERY -->
- <style type="text/css">
- table,td,th
- {
- border:1px solid black;
- }
- td
- {
- text-align:right;
- }
- @media screen and (max-width: 485px) {
- body {
- text-align:center;
- font:0.9em "trebuchet ms", helvetica, arial, sans-serif;
- background-color:blue;
- word-wrap: break-word;
- }
- .mytable
- {
- width:400px;
- }
- }
- @media screen and (min-width: 485px) and (max-width: 1100px) {
- body {
- text-align:center;
- font:0.9em "trebuchet ms", helvetica, arial, sans-serif;
- background-color:red;
- word-wrap: break-word;
- }
- .mytable
- {
- width:500px;
- }
- }
- @media screen and (min-width: 1100px) {
- body {
- text-align:center;
- font:0.9em "trebuchet ms", helvetica, arial, sans-serif;
- background-color:green;
- word-wrap: break-word;
- }
- .mytable
- {
- width:1000px;
- }
- }
- .th1
- {
- width:20%;
- }
- .th2
- {
- width:50%;
- }
- .th3
- {
- width:30%;
- }
- </style>
-
- </head>
- <body>
- <span id="msg">my message: </span>
-
-
- <div id="mytable">
- <table class="mytable">
- <tr>
- <th class="th1">Firstname</th>
- <th class="th2">Lastname</th>
- <th class="th3">Savings</th>
- </tr>
- <tr>
- <td>Peter</td>
- <td>Griffin</td>
- <td>$100</td>
- </tr>
- <tr>
- <td>Lois</td>
- <td>Griffin</td>
- <td>$150</td>
- </tr>
- <tr>
- <td>Joe</td>
- <td>Swanson</td>
- <td>$300</td>
- </tr>
- <tr>
- <td>Cleveland</td>
- <td>Brown</td>
- <td>$250</td>
- </tr>
- </table>
- </div>
- <script>
- $(function() {
-
- $(document).ready( function() {
- var str=parseInt($(window).width())-parseInt(100);
- $(".mytable").css("width", str );
- });
-
- $( window ).resize(function() {
- var str=parseInt($(window).width())-parseInt(100);
- $(".mytable").css("width", str );
- });
- });
-
- </script>
- </body>
- </html>
David ( @webtecgeek www.thecacaocafe.com )