用于锚标记的CSS样式不起作用

时间:2016-06-27 04:37:19

标签: html css

我在页面上添加了一些链接,将一个css文件添加到html文件中,但样式没有显示出来。

HTML:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Title</title>
        <link rel="stylesheet" type="text/css" href="formatter.css">
    </head>
    <body>
        <h1>Welcome</h1>
        <hr/>
        <div class="anch" style="text-align: center">
            <a href="admin_login.jsp" style="" >Admin</a>
            <a href="user_login.jsp">User</a>
        </div>
    </body>
</html>

formatter.css:

body{
    font-family: Verdana, Arial, sans-serif;
    color: #555;
    background-color: silver;
}
h1{
    text-align: center;
}
.anch a:link, a:visited{
    text-decoration: none;
    display: inline-block;
    color: black;
    background-color: white;
}
.anch a:hover, a:focus, a:active{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
}

运行上述文件时,body和h1样式可见,但锚样式未显示。它们以默认形式出现(蓝色和下划线)。 这是一个显示的图像:

enter image description here

4 个答案:

答案 0 :(得分:0)

Css伪类定义为冒号{{1}}而不是{{1}}

{{1}}

了解更多信息,请阅读this

答案 1 :(得分:0)

为锚标记创建一个单独的类,您可以在需要时使用它。

<a href="somelink" class="archorCls">SomeThing</a>

在css中

.archorCls{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
} 

答案 2 :(得分:0)

这是代码。您在css中使用带有标记的点但是:使用了。我还举了一个用css类设置锚点样式的例子。 :)

&#13;
&#13;
body{
    font-family: Verdana, Arial, sans-serif;
    color: #555;
    background-color: silver;
}
h1{
    text-align: center;
}
.anch a:link, a:visited{
    text-decoration: none;
    display: inline-block;
    color: black;
    background-color: white;
}
.anch a:hover, a:focus, a:active{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
}
/* This is the css code for anchor styling */

.anchor{    text-decoration: none;
    display: inline-block;
    color: black;
    background-color: white;}
/* When mouse hover the anchor class */
.anchor:hover{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
}
&#13;
<div class="anch" style="text-align: center">
<a href="admin_login.jsp" style="<!--You can use style here too -->" >Admin</a>
<a href="user_login.jsp">User</a>
</div>
</br> <!-- This br is for line space -->
</br> <!-- This br is for line space -->
</br> <!-- This br is for line space -->
<b> You can style your anchor tags with css class too. Here is the example</b>
</br> <!-- This br is for line space -->
</br> <!-- This br is for line space -->
</br> <!-- This br is for line space -->
<center>
<a href="admin_login.jsp" class="anchor">Admin</a>
<a href="user_login.jsp" class="anchor">User</a>
</center>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

.anch a{ text-decoration: none; display: inline-block; color: black; background-color: white; } .anch a:link, a:visited{ text-decoration: none; display: inline-block; color: black; background-color: white; } .anch a:hover, a:focus, a:active{ text-decoration: none; display: inline-block; color: white; background-color: black; } 提供样式。然后使用冒号悬停,活动和其他。

public void addRecs(String user, int Param) {
    try {
            conn.setCatalog("MyDBName");
            CallableStatement stmt = conn.prepareCall("{call sp_addRecords(?,?,?)}");
            stmt.setString(1, user);
            stmt.setInt(2, Param);
            stmt.registerOutParameter(3, Types.INTEGER);
            stmt.execute();
            int rowCount = stmt.getInt(3);
            System.out.println(rowCount + " records has added into Record Table!");
        } catch (SQLException e) {
        e.printStackTrace();
    }
}