On minimizing the screen, the table should shrink

北慕城南 提交于 2019-12-23 23:07:28

问题


I have a table like

<form id="form1">
    <table style="width:75%;font-size:15px;" align="center" id="info" >
...
</table>
</form>

On shrinking the browser, I want to fit the table accordingly. I tried by keeping the position: relative. Still that doesn't work. Any leads ?


回答1:


you have to give width of table directly.

<form id="form1">
   
    <table width="500" border="1" align="left" id="info" >

    <tr>
        <td>1</td>
        <td>2</td>
    </tr>
    <tr>
      <td>3</td>
      <td>4</td>
    </tr>
</table>
</form>



回答2:


The design you are trying to use is referred as responsive designs. There are lots of libraries out there for creating a responsive web page design.Whereas below mentioned might be different ways to make your web page responsive across various devices, e.g. Desktop, Tablets, Mobile devices.

1) Jquery mobile - Jquery mobile library documentation

http://code.jquery.com/mobile/git/jquery.mobile-git.js
http://code.jquery.com/mobile/git/jquery.mobile-git.css

2) Bootstrap Css and Js -Bootstrap library documentation

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Basic Table</h2>
  <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>            
  <table class="table">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
      <tr>
        <td>Mary</td>
        <td>Moe</td>
        <td>mary@example.com</td>
      </tr>
      <tr>
        <td>July</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
    </tbody>
  </table>
</div>

</body>
</html>

3) CSS media queries- Reference link to use CSS media queries

 /* For desktop: */
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}

@media only screen and (max-width: 768px) {
    /* For mobile phones: */
    [class*="col-"] {
        width: 100%;
    }
}


来源:https://stackoverflow.com/questions/35169499/on-minimizing-the-screen-the-table-should-shrink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!