【问题标题】:Several table formatting issues with CSSCSS 的几个表格格式问题
【发布时间】:2015-02-14 05:55:44
【问题描述】:

我几乎完成了我正在尝试创建的比较表的第一个大纲。我遇到了一些我无法解决的问题。而且我尝试了不同的类、id 和属性,但最终要么什么都不做,要么改变了一些非预期的东西。不过有些问题我自己解决了。

不要一一发布几个问题,而是发送垃圾邮件。我控制住自己,把我的问题组合在一起。就这样吧:

我的目标:

在最左边,我想创建一个首先为空白的列,然后包含每行的所有标题。 然后我希望包含产品的每一行都遵循以下下降顺序:
1. 产品图片
2. 公司名称
3.产品名称
4. 价格
5. 按钮
6. 这是一个空白行:带有类别标题(例如功能或兼容性)。
7. 左侧 td 中的第一个标题(例如音频、视频)。然后在每个单元格中使用复选标记或 x 标记继续下降序列,具体取决于该产品包括命名规范(音频..视频..等)

我的问题是:

如何让所有内容都居中?除了应该左对齐的左列标题。
如何在没有悬停效果的情况下使类别标题行上方的所有行?
如何使“类别标题”停留在 2px 纯灰色边框上?
如何让 Category Title 上方的所有行都变成白色?
有没有更好的方法以更有效的方式制作此边框?

/* thick border for the top row */
#borderbottom{
    border-bottom: 2px solid gray;
}

我认为我应该为每个表创建两个单独的表 CSS,但是当我尝试时,这两个表没有相互对齐。

这是我的 HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Compare Table</title>
    <link rel="stylesheet" href="index.css">
</head>
<body>
    <br/>
  <br/>

<table class="hoverTable">
  <tr>
    <td class="blankcell"></td>
    <td>IMAGE</td>
    <td>IMAGE</td>
    <td>IMAGE</td>
  </tr>
  <tr>
    <td class="blankcell"></td>
    <td>Company Name<br/>Product Name</td>
    <td>content</td>
    <td>content</td>
  </tr> 
  <tr>
    <td class="blankcell"></td>
    <td>content</td>
    <td>content</td>
    <td>content</td>
  </tr> 
</table> 


<table class="hoverTable">
  <tr id="notop">
  <td class="blankcell" id="borderbottom"><h3>Category Title</h3></td>
    <td id="borderbottom"></td>
    <td id="borderbottom"></td> 
    <td id="borderbottom"></td>
  </tr>
  <tr>
   <td class="rowTitle" colspan="4">TITLE</td>
  </tr>
  <tr>
  <td class="rowTitle">TITLE</td>
    <td id="check">&#x2714</td>
    <td>&#x2714</td> 
    <td>&#x2714</td>
  </tr>
  <tr>
  <td class="rowTitle">TITLE</td>
    <td id="x01">&#x2716</td>
    <td>&#x2716</td> 
    <td>&#x2716</td>
  </tr>
  <tr id="nolast">
  <td class="rowTitle">TITLE</td>
    <td>&#x2714</td>
    <td>&#x2714</td> 
    <td>&#x2714</td>
  </tr>
</table>



</body>
</html>

这是我的 CSS:

th,td {
    padding: 15px;
    text-align: center;
}
/* Row coloring */
.hoverTable tr:nth-child(even) {
    background-color: #FAFAFA;
}
.hoverTable tr:nth-child(odd) {
    background-color:#ffffff;
}
/* Upper left cell*/
.blankcell {
    background: none!important; 
    text-align: left;
}
/*top and bottom border*/
#notop{
    border:0px;
}
#nolast{
    border-bottom:0px;
}

/* HOVER FUNCTION */
.hoverTable{
        width:100%; 
        border-collapse:collapse;
    }
    .hoverTable td{ 
        padding:4px; 
        border: #000000 0px solid;
    }
    /* Define the default color for all the table rows */
    .hoverTable tr{
        background: #ffffff;
        border-bottom:1px solid #B5B3B3;
        border-top:1px solid #B5B3B3;
    }
    /* Define the hover highlight color for the table row */
    .hoverTable tr:not(:nth-child(1)):hover {
        background-color: #FFF0E6;
        border-left:5px solid #ff6600;
    }
/* Check and X-Mark Coloring*/
#check {
    color: #1CF200;
}
#x01 {
    color: #ff6969;
}
/* Left-hand title */
.rowTitle {
    font-weight: bold;
    text-align: left;
}
/* thick border for the top row */
#borderbottom{
    border-bottom: 2px solid gray;
}

JSFiddle

感谢您提供的任何帮助!

【问题讨论】:

    标签: html css


    【解决方案1】:

    如何让所有内容都居中?除了应该左对齐的左列标题。

    所有内容都已居中。您已经有了左对齐文本的代码。它在第一列的底部表格中使用。

    .rowTitle {
        font-weight: bold;
        text-align: left !important;
    }
    

    如何让“Category Title”停留在2px的实心灰色边框上?在h3标签中添加class category

    h3.category {
      margin-bottom: -8px;
    }
    

    如何使类别标题行上方的所有行都没有悬停效果?

    您可以使用不使用悬停代码的单独代码。基本上用“.hoverTable tr:not(:nth-child(1)):hover”复制悬停表并将新类称为toptable。 (可能有更有效的方法。

    如何让 Category Title 上方的所有行都变成白色?

    如果您使用具有基本相同值的单独代码,请不要复制

    .hoverTable tr:nth-child(even) {
        background-color: #FAFAFA;
    }
    .hoverTable tr:nth-child(odd) {
        background-color:#ffffff;
    }
    

    有没有更好的方法以更有效的方式制作此边框?我会为类别使用标签。 colspan 将跨越它下面的 4 列。

    CSS

    th {
      border-bottom: 2px solid grey;
    }
    

    HTML

    <thead>
      <tr>
         <th colspan="4">Category Title</th>
      </tr>
    </thead>
    

    查看其中一些应用于此 jsfiddle http://jsfiddle.net/x6co362t/

    是的,您应该制作 2 组不同的代码,因为这将解决您的大部分问题。他们怎么不对齐?你能把应该对齐的东西对齐吗?

    【讨论】:

    • 你真的超越了 OP...+1 兄弟...我希望每个人都为应得的人 +1...
    猜你喜欢
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多