Answer the question
In order to leave comments, you need to log in
Bug or feature in css?
Good afternoon, people, I just stumbled upon one interesting feature, and since I myself am not the best layout designer, I want to ask why it happens like this?
<html>
<head>
<style type="text/css">
form input[type=text]{
width:100px;
}
.test input{
width:200px;
}
</style>
</head>
<body>
<form>
<input type="text" />
<div class="test"><input type="text" /></div>
</form>
</body>
</html>
<html>
<head>
<style type="text/css">
form input[type=text]{
width:100px;
}
.test{
width:200px;
}
</style>
</head>
<body>
<form>
<input type="text" />
<div><input type="text" class="test" /></div>
</form>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
The most specific selector plays.
Try like this
form .test input{
width:200px;
}
!important
It's like the last bullet. You have to take care of yourself...
This code also works unexpectedly (for me)
<html>
<head>
<style type="text/css">
form input[type=text]{
width:100px;
}
.test{
width:200px;
}
</style>
</head>
<body>
<form>
<input type="text" />
<div><input type="text" class="test" /></div>
</form>
</body>
</html>
want even more magic?
<html> <head> <style type="text/css"> input[type=text]{ width:100px; } .test input{ width:200px; } </style> </head> <body> <form> <input type="text" /> <div class="test"><input type="text" /></div> </form> </body> </html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question