此简单代码无法在Chrome或Safari中使用...
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<style>
:required {box-shadow:0 0 5px red;}
</style>
<body>
<form>
<textarea required></textarea>
</form>
</body>
</html>
它在Firefox和Opera中运行良好。此外,border:1px solid red
在webkit浏览器中运行良好。这是怎么回事?我甚至试过textarea {display:block;}
认为这可能是一个内联问题。
答案 0 :(得分:16)
答案 1 :(得分:2)
如果你给textarea一个背景声明 none (或某个背景颜色声明,因为某些原因,除了白色之外的任何东西)阴影会工作的。
<style>
:required {
background: none;
box-shadow:0 0 5px red;
}
</style>
答案 2 :(得分:2)
试试这个
textarea:required {
box-shadow: 0 0 5px red;
-webkit-box-shadow: 0 0 5px red;
-moz-box-shadow: 0 0 5px red;
border: solid 0px transparent; // or border: none;
}
答案 3 :(得分:0)
尝试通过类或ID而不是Textarea
选择器
:required