如何使用 css 避免特定 div 元素的显示块

How to avoid display block for a particular div element using css

在我的媒体查询中,我设置了要显示的表:块。所以现在 display: block 现在适用于网站的所有元素。如何避免 display: 阻塞,使其不适用于一个特定的 div 元素。

{    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th, tr{
    border: 1px solid #dddddd;
    text-align: left;
    padding: 10px;
}


@media only screen and (max-width: 460px) {


 /* Force table to not be like tables anymore  */
 table, th, tbody, td, thead { 
  display: block; 
  width: 100%;
 }
  
#content {
 

 }
  
 }
<div id="content">
  <h1>Article Question is</h1>
  <p>Below I have table inside the article. How to avoid display block for the table below on mobile screens?</p>
<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
  <tr>
    <td>Island Trading</td>
    <td>Helen Bennett</td>
    <td>UK</td>
  </tr>
  <tr>
    <td>Laughing Bacchus Winecellars</td>
    <td>Yoshi Tannamuri</td>
    <td>Canada</td>
  </tr>
  <tr>
    <td>Magazzini Alimentari Riuniti</td>
    <td>Giovanni Rovelli</td>
    <td>Italy</td>
  </tr>
</table>
</div>  

也许是这样的?

@media only screen and (max-width: 460px) {

 /* Force table to not be like tables anymore  */
    table, th, tbody, td, thead { 
        display: block; 
        width: 100%;
    }

    #content table, #content th, #content tbody, #content td, #content thead {
        display: initial;
    }

}

您也可以使用 :not 来避免 #content table。

@media only screen and (max-width: 460px) {


 /* Force table to not be like tables anymore  */
    table:not(#content table),
    th:not(#content th),
    tbody:not(#content tbody),
    td:not(#content td),
    thead:not(#content thead) { 
        display: block; 
        width: 100%;
    }

#content {


    }

 }

这个或@KodieGrantham 的解决方案应该 有效;哪一个可能是偏好问题。