+ 3
# or .
For CSS, I am unsure when to use . and #. Could someone explain the difference please?
2 Respostas
+ 4
Sure
# = id
. = class
We generally use id for single, unique items on our page (titles for example)
class however is used for multiple items. Here's an example:
<style>
/* this will target your ID myTitle */
#myTitle {
color: blue;
font-size: 20px;
text-align: center;
}
.redbox{
/* this will target your classes */
width: 250px;
height: 100px;
background-color: red;
}
</style>
<body>
<h1 id="myTitle">
Hello SoloLearn
</h1>
<p>List of boxes below</p>
<div class="redbox"> box 1 </div>
<div class="redbox"> box 2 </div>
<div class="redbox"> box 3 </div>
</body>
+ 1
Thanks!