html - 为两个表分配单独的 css 样式

标签 html css

为什么当我将一种样式应用到一个表时它会影响另一个表,即使我已经为它们分配了单独的类。表二被表二填充推低。看看我创建的这个演示。我怎样才能避免这种情况?

<table id="one">
    <tr>
      <td>Hello</td>
    </tr>
  </table>

  <table id="two">
    <tr>
      <td>Goodbye</td>
    </tr>
  </table>

CSS:

table{
  display: inline-block;
}

#one{
  background-color: blue;
  padding-top: 50px;
}

#two{
  background-color: orange;
}

https://jsfiddle.net/b7qdcub1/

最佳答案

您可以对表 Jsfiddle 使用垂直对齐

table{
 display: inline-block;
 vertical-align:top;
}
#one{
  background-color: blue;
  padding-top: 50px;
}

#two{
  background-color: orange; 
}

  
  <table id="one">
<tr>
  <td>Hello</td>
</tr>
  </table>
  
  <table id="two">
<tr>
  <td>Goodbye</td>
</tr>
  </table>

关于html - 为两个表分配单独的 css 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43115595/

相关文章:

php - 如何在彼此的前面显示动态文本框

html - 使用 transform rotate CSS 属性时,如何防止 hover transition 的振动边框问题?

javascript - jQuery从另一个div获取数据到li

CSS 选定/事件属性

html - Webpack:使用组件特定的 css 在 html 中呈现不同?

javascript - 我如何使用 javascript/jquery 实现悬停效果?

javascript - 谷歌地图没有在 div 中完全呈现?

javascript - 如何更改 div 部分滚动条的 CSS 样式?

html - 应用于具有特定文件名的 SVG 的内联 CSS 样式

javascript - JQuery 将两个图像设置为与另一个图像相同的位置