在最小化屏幕时,表格应该缩小 [英] On minimizing the screen, the table should shrink

查看:91
本文介绍了在最小化屏幕时,表格应该缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,如

 < form id =form1> 
...
< / table>
< / form>

在缩小浏览器时,我想相应地调整表格。我试着保持立场:相对。仍然没有用。任何线索?

解决方案

您尝试使用的设计被称为响应式设计。
为创建响应式网页设计,有许多图书馆可供使用。以下提到的方式可能会使您的网页在各种设备上响应,例如不同的方式。桌面,平板电脑,移动设备。

<1> Jquery mobile - Jquery移动库文档 p>

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



2)Bootstrap Css和Js - Bootstrap库文档

 <!DOCTYPE html> 
< html lang =en>
< head>
< title>引导程序示例< / title>
< meta charset =utf-8>
< meta name =viewportcontent =width = device-width,initial-scale = 1>
< link rel =stylesheethref =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>基本表< / h2>
< p> .table类将基本样式(轻填充和仅水平分隔符)添加到表中:< / p>
< table class =table>
< thead>
< tr>
< th>名字< / th>
< th>姓氏< / th>
< th>电子邮件< / 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>七月< / td>
< td> Dooley< / td>
< td> july@example.com< / td>
< / tr>
< / tbody>
< / table>
< / div>

< / body>
< / html>



<3> CSS媒体查询 - 使用CSS媒体查询的参考链接

  / * For桌面:* / 
.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仅屏幕和(max-宽度:768px){
/ *对于手机:* /
[class * =col-] {
width:100%;
}
}


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 ?

解决方案

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%;
    }
}

这篇关于在最小化屏幕时,表格应该缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆