简体   繁体   English

如何让表格填满整个屏幕?

[英]How can I make a table fill the whole screen?

When I set the width of a table to 100% using in-line CSS, it fills the entire page, but when trying to set the table width to 100% inside a media query in the style.css file it doesn't fill the page.当我使用内联 CSS 将表格宽度设置为 100% 时,它会填满整个页面,但是当我尝试在 style.css 文件中的媒体查询中将表格宽度设置为 100% 时,它不会填充页。 I am testing the website on a phone with a less than 600px width.我正在宽度小于 600 像素的手机上测试该网站。

Works In-line.在线工作。 <table style="width: 100%">

Doesn't Work in style.css file.不适用于 style.css 文件。 @media only screen and (max-width: 600px) {table {width: 100%;}}

How can I make it work in the style.css file?我怎样才能让它在 style.css 文件中工作?

You can achieve that by setting css on the table: table{min-width:100%}您可以通过在桌子上设置 css 来实现: table{min-width:100%}

Check this out:看一下这个:

https://jsfiddle.net/sa0Ldbe1/ https://jsfiddle.net/sa0Ldbe1/

@media only screen and (max-width: 600px) {table {width: 100%;}}

Will only work on devices less than 600px wide.仅适用于宽度小于 600 像素的设备。

<table style="width: 100%">

Will work on any device size.适用于任何设备尺寸。 Make sure the device you are using is smaller than 600px.确保您使用的设备小于 600 像素。

If you need it to work on devices larger than 600px wide, use table {width: 100%;} or @media only screen and (min-width: 600px) {table {width: 100%;}}如果您需要它在大于 600px 宽的设备上工作,请使用table {width: 100%;}@media only screen and (min-width: 600px) {table {width: 100%;}}

Good night xman, Avoid placing your CSS inline.晚安 xman,避免将 CSS 内联。 It is good practice to place your styles in a CSS file.最好将 styles 放在 CSS 文件中。

Look:看:

 table { width: 50%; } td, th { border: 1px solid black; text-align: left; } @media (max-width: 600px){ table { width: 100%; } }
 <table> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> </tr> </table>

As long as the width was in the tag, your media querie would never work, because in CSS Specificity Hierarchy, inline styles will always be above the styles you put in your style.css. As long as the width was in the tag, your media querie would never work, because in CSS Specificity Hierarchy, inline styles will always be above the styles you put in your style.css.

More about: CSS Specificity Hierarchy更多关于: CSS 特异性层次结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM