gpt4 book ai didi

css - 属性 nth-child 似乎在 JSP CSS 中不起作用

转载 作者:行者123 更新时间:2023-11-28 17:03:16 24 4
gpt4 key购买 nike

我创建了一个程序,用名为 usuarios 的表的数据填充一个表,但属性 nth-child 似乎不起作用所有行都有相同的颜色,即绿黄色;.我正在使用 Netbeans 和 Glassfish

    <%-- 
Document : basededatos
Created on : 14/06/2015, 01:23:57
Author : fernando
--%>

<%@page import="java.sql.*"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style type="text/css">
.TFtable{
width:100%;
border-collapse:collapse;
}
.TFtable td{
padding:7px; border:#4e95f4 1px solid;
}
/* provide some minimal visual accomodation for IE8 and below */
.TFtable tr{
background: red;
}
/* Define the background color for all the ODD background rows */
.TFtable tr:nth-child(odd){
background: yellow;
}
/* Define the background color for all the EVEN background rows */
.TFtable tr:nth-child(even){
background: greenyellow;
}
</style>

</head>
<body>
<%
Connection conn = null;
ResultSet result = null;
Statement stmt = null;
ResultSetMetaData rsmd = null;
try {
Class.forName("com.mysql.jdbc.Driver");
out.println("driver registrado");
conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/administracion", "root", "strlen12");
out.println("conexion exitosa");
stmt = conn.createStatement();
result = stmt.executeQuery("select * from usuarios");
%>
<table border="1" class="TFtable">
<caption>Lista de Usuarios</caption>
<tr style="background-color: grey">
<td>Nombre</td>
<td>Codigo</td>
</tr>
<%
while (result.next()) {
%>
<tr>
<td>
<% out.print(result.getString(1)); %>
</td>
<td>
<% out.print(result.getString(2)); %>
</td>
<tr>
<%
}
%>
</table>
<%
} catch (Exception e) {
out.print(e);
}
%>

</body>
</html>

This is a screenhot

最佳答案

问题是你没有关闭 tr 标签

改变这个:

         <tr>
<td>
<% out.print(result.getString(1)); %>
</td>
<td>
<% out.print(result.getString(2)); %>
</td>
<tr>

到:

         <tr>
<td>
<% out.print(result.getString(1)); %>
</td>
<td>
<% out.print(result.getString(2)); %>
</td>
</tr>

关于css - 属性 nth-child 似乎在 JSP CSS 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30821329/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com