是否可以向div元素添加多个类?我尝试添加完整和b类,但它不起作用.
#card {
/* default for card */
width: 300px;
height: 50px;
padding: 15px;
background-color: yellow;
box-shadow: 10px 10px 40px grey;
}
#card.g {
background-color: lightgreen;
box-shadow: 10px 10px 40px grey;
}
#card.b {
background-color: lightblue;
box-shadow: 10px 10px 40px grey;
}
#card.full{
width:100%;
height:100%;
padding:10px;
}Run Code Online (Sandbox Code Playgroud)
<h3 id="card" class="full" class="b">Hi!</h3>Run Code Online (Sandbox Code Playgroud)
如果这是一个糟糕的问题,我很抱歉,我是编程新手.
是的,你只需要用空格分隔多个类.如果你class=""在元素中放两次,就像你一样,它会忽略第二个元素
#card {
/* default for card */
width: 300px;
height: 50px;
padding: 15px;
background-color: yellow;
box-shadow: 10px 10px 40px grey;
}
#card.g {
background-color: lightgreen;
box-shadow: 10px 10px 40px grey;
}
#card.b {
background-color: lightblue;
box-shadow: 10px 10px 40px grey;
}
#card.full{
width:100%;
height:100%;
padding:10px;
}Run Code Online (Sandbox Code Playgroud)
<h3 id="card" class="full b">Hi!</h3>Run Code Online (Sandbox Code Playgroud)