0

它在 ie 和 chrome 上运行良好。我尝试了一些简单的修复,但不确定为什么我尝试过的没有任何效果。

    table {
    *border-collapse: collapse; /* IE7 and lower */
    border-spacing: 0;
    width: auto;
    margin-left:auto; 
    margin-right:auto;
    margin-top: 1%;    
}

.bordered {
    border: solid #ccc 0px;
    -moz-border-radius: 6px;
    -webkit-border-radius: 6px;
    border-radius: 6px;
    -webkit-box-shadow: 0 1px 1px #ccc; 
    -moz-box-shadow: 0 1px 1px #ccc; 
    box-shadow: 0 1px 1px #ccc;
    background-color:#ffffff;         
}

.bordered tr:hover {
    background: #fbf8e9;
    -o-transition: all 0.1s ease-in-out;
    -webkit-transition: all 0.1s ease-in-out;
    -moz-transition: all 0.1s ease-in-out;
    -ms-transition: all 0.1s ease-in-out;
    transition: all 0.1s ease-in-out;     
}    

.bordered td, .bordered th {
    border-left: 0px solid #ccc;
    border-top: 0px solid #ccc;
    padding: 10px;
    text-align: left;    
}

.bordered th {
    background-color: #dce9f9;
    background-image: -webkit-gradient(linear, left top, left bottom, from(#ebf3fc), to(#dce9f9));
    background-image: -webkit-linear-gradient(top, #ebf3fc, #dce9f9);
    background-image:    -moz-linear-gradient(top, #ebf3fc, #dce9f9);
    background-image:     -ms-linear-gradient(top, #ebf3fc, #dce9f9);
    background-image:      -o-linear-gradient(top, #ebf3fc, #dce9f9);
    background-image:         linear-gradient(top, #ebf3fc, #dce9f9);
    -webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset; 
    -moz-box-shadow:0 1px 0 rgba(255,255,255,.8) inset;  
    box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;        
    border-top: none;
    text-shadow: 0 1px 0 rgba(255,255,255,.5);
    font-weight:900;
}

.bordered td:first-child, .bordered th:first-child {
    border-left: none;
}

.bordered th:first-child {
    -moz-border-radius: 6px 0 0 0;
    -webkit-border-radius: 6px 0 0 0;
    border-radius: 6px 0 0 0;
}

.bordered th:last-child {
    -moz-border-radius: 0 6px 0 0;
    -webkit-border-radius: 0 6px 0 0;
    border-radius: 0 6px 0 0;
}

.bordered th:only-child{
    -moz-border-radius: 6px 6px 0 0;
    -webkit-border-radius: 6px 6px 0 0;
    border-radius: 6px 6px 0 0;
}

.bordered tr:last-child td:first-child {
    -moz-border-radius: 0 0 0 6px;
    -webkit-border-radius: 0 0 0 6px;
    border-radius: 0 0 0 6px;
}

.bordered tr:last-child td:last-child {
    -moz-border-radius: 0 0 6px 0;
    -webkit-border-radius: 0 0 6px 0;
    border-radius: 0 0 6px 0;
}



/*----------------------*/

.zebra td, .zebra th {
    padding: 10px;
    border-bottom: 1px solid #f2f2f2;  
}

.zebra tbody tr:nth-child(even) {
    background: #f5f5f5;
    -webkit-box-shadow: 0 1px 0 rgba(255,255,255,.8) inset; 
    -moz-box-shadow:0 1px 0 rgba(255,255,255,.8) inset;  
    box-shadow: 0 1px 0 rgba(255,255,255,.8) inset;        
}

.zebra th {
    text-align: left;
    text-shadow: 0 1px 0 rgba(255,255,255,.5); 
    border-bottom: 1px solid #ccc;
    background-color: #eee;
    background-image: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#eee));
    background-image: -webkit-linear-gradient(top, #f5f5f5, #eee);
    background-image:    -moz-linear-gradient(top, #f5f5f5, #eee);
    background-image:     -ms-linear-gradient(top, #f5f5f5, #eee);
    background-image:      -o-linear-gradient(top, #f5f5f5, #eee); 
    background-image:         linear-gradient(top, #f5f5f5, #eee);
}

.zebra th:first-child {
    -moz-border-radius: 6px 0 0 0;
    -webkit-border-radius: 6px 0 0 0;
    border-radius: 6px 0 0 0;  
}

.zebra th:last-child {
    -moz-border-radius: 0 6px 0 0;
    -webkit-border-radius: 0 6px 0 0;
    border-radius: 0 6px 0 0;
}

.zebra th:only-child{
    -moz-border-radius: 6px 6px 0 0;
    -webkit-border-radius: 6px 6px 0 0;
    border-radius: 6px 6px 0 0;
}

.zebra tfoot td {
    border-bottom: 0;
    border-top: 1px solid #fff;
    background-color: #f1f1f1;  
}

.zebra tfoot td:first-child {
    -moz-border-radius: 0 0 0 6px;
    -webkit-border-radius: 0 0 0 6px;
    border-radius: 0 0 0 6px;
}

.zebra tfoot td:last-child {
    -moz-border-radius: 0 0 6px 0;
    -webkit-border-radius: 0 0 6px 0;
    border-radius: 0 0 6px 0;
}

.zebra tfoot td:only-child{
    -moz-border-radius: 0 0 6px 6px;
    -webkit-border-radius: 0 0 6px 6px
    border-radius: 0 0 6px 6px
} 

表格示例

<table class="bordered">

                <thead>
                    <tr>               
                        <th>Create Database</th>
                        <th>
                        <?php                           
                        if ($_SESSION['dbcreatecode'] == 1){
                            echo 'Added database successfully!';
                            $_SESSION['dbcreatecode'] = 0;
                        }
                        elseif (($_SESSION['dbcreatecode'] == 2)){
                            echo 'Failed to add database!';
                            $_SESSION['dbcreatecode'] = 0;
                        }                                          
                        ?>
                        </th>
                    </tr>
                </thead>

                <tr>
                    <td>DB Nickname</td>
                    <td><input name="dbnick" placeholder="Name" type="text2" id="dbnick"></td>
                </tr>
                <tr id="checkdb" style="display: none">
                        <td></td>
                        <td><div id="dbnick_availability_result"></div></td>                            
                </tr>
                <tr>
                    <td>DB Name</td>
                    <td><input name="dbname" placeholder="Name" type="text2" id="dbname"></td>
                </tr>
                <tr>
                    <td>IP Address</td>
                    <td><input name="dbip" placeholder="IP Address" type="text2" id="dbip"></td>
                </tr>
                <tr>
                    <td>DB User</td>
                    <td><input name="dbuser" placeholder="Username" type="text2" id="dbuser"></td>
                </tr>
                <tr>
                    <td>DB Pass</td>
                    <td><input name="dbpass" placeholder="Password" type="text2" id="dbpass"></td>
                </tr>
                <tr>
                    <td>DB SQLPort</td>
                    <td><input name="dbport" placeholder="SQL Port" type="text2" id="dbport"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>  
                        <button class ="createbutton" type="submit" name="Create" value="Create"></button>
                    </td>
                </tr>

                </table>

我也很好奇是否没有在文本上指定标签什么是 CSS 中考虑的文本? 在此处输入图像描述

4

1 回答 1

2

他们没有居中,因为你有

.bordered td, .bordered th {
     text-align: left;
}

将其更改为text-align: center;(或text-align: right;......不清楚您在问什么,将每个文本对齐到 的中间,将每个文本对齐<td>到 的中间<table>,或其他东西)以使其工作。

编辑

现在您编辑了您的帖子,很明显您的意思是垂直对齐。

好吧,在这个答案的开头打开小提琴(您未修改的代码),它们是垂直对齐的。如果你设置

.bordered td, .bordered th {
     height: 50px;
}

它们仍然对齐。

问题在于您没有向我们展示的 CSS,而不是您展示的 CSS。

如果我不得不猜测,我会责怪自定义文本框。

于 2013-09-20T16:18:41.603 回答