如何使用CSS忽略href的规则

时间:2016-02-05 17:36:29

标签: html css

我的所有<?php //calling connection to database include "connection.php"; @session_start(); //session //if user posts for called login if(isset($_POST['login'])){ //declaring variables for user input and using escape string to protect php scripts $user = mysqli_real_escape_string($dbconn,$_POST['user']); $pass = mysqli_real_escape_string($dbconn,$_POST['pass']); //select from users table where user input matches un and pw $sel_user = "SELECT * from users where un='$user' AND pw='$pass'"; //put content held in sel_user into variable run_user $run_user = mysqli_query($dbconn, $sel_user); //use run_user counting rows and save in check_user $check_user = mysqli_num_rows($run_user); //if content row numbers greater than 0 if($check_user>0){ //session where un is equal to user input stored in $user $_SESSION['username']=$user; //display admin main page header('Location: ../adminmain.php'); } else { //display log in error page header('Location: ../loginerror.php'); } } //close database connection mysqli_close($dbconn); ?> ##### file verify.php ##### <?php @session_start(); if (@$_SESSION['username']!=$user) { header ("location: index.php"); exit; } ?> 都有简单的规则格式:

<a>

但我不希望这适用于a:link { text-decoration: none; } a:visited { text-decoration: none; } a:hover { text-decoration: underline; } a:active { text-decoration: underline; } 内的<img>

<a>

我怎么能忽略这个?

5 个答案:

答案 0 :(得分:0)

您需要在第一组之后添加另一组类,目标是img,img:hover等。但是,img元素不支持文本修饰。你试图用图像避免什么?

答案 1 :(得分:0)

将你的href放在div中并为该div分配一个类;然后你可以设置类的样式,然后是:

<div class="stylin">
   <a href="link">
       <img class="myClass" src="smile.png" alt="this is image link example">
   </a>
</div>

然后在样式表中。

.stylin a:link {

}

答案 2 :(得分:0)

不幸的是,没有办法查看img是否有链接作为父(父选择器),然后根据它更改链接元素。您需要使用Javascript或JQuery来执行此操作,或者您只需添加一个&#39; link-img&#39;包含图像的任何链接元素的类,并相应地设置它的CSS属性。

HTML:

<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
<a class="link-img" href="#">
    <img src="smile.png"/>
</a>

CSS:

a:link {
    text-decoration: none;
}
a:visited {
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}
a:active {
  text-decoration: underline;
}
.link-img {
    text-decoration:none;
}

答案 3 :(得分:0)

您可以在<a>标记中添加一个类。

例如

<a href="link" class="image">
 <img class="myClass" src="smile.png" alt="this is image link example">
</a>

然后用css:

a.image{

}

在此示例中,您必须专门设置规则以对抗所有<a>标记的先前设置规则

另一种方法是将额外的类与:not选择器

结合使用
a:link:not(.image) {
    text-decoration: none;
}

a:visited:not(.image) {
    text-decoration: none;
}

a:hover:not(.image) {
    text-decoration: underline;
}

a:active:not(.image) {
    text-decoration: underline;
}

答案 4 :(得分:-2)

a:link .myClass,
a:visited .myClass,
a:hover .myClass,
a:focus .myClass,
a:active .myClass {
   text-decoration: none;
}