I have a set of links with background images on this CodePen.
I am seeking feedback to see if I did this the most optimal way. For example, I made a sprite so that I can just load one image. And I leveraged inheritance so that I did not have to assign every containing div a class. Just used a child selector and for the individual buttons, I used :nth-of-type
to pass the background image.
Tell me your thoughts if this could use improvement.
HTML
<div class="introSelect">
<div>
<a href="#"> <!-- Link Pending -->
<span>Dentist</span>
</a>
</div>
<div>
<a href="#"> <!-- Link Pending -->
<span>Patient</span>
</a>
</div>
<div>
<a href="#"> <!-- Link Pending -->
<span>Lab</span>
</a>
</div>
</div>
CSS
.introSelect { text-align:center; }
.introSelect div {
display:inline-block;
position: relative;
text-align: center;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/101702/bruxzir-user-sprites_1.png') no-repeat;
width: 90px;
height: 90px;
}
.introSelect div:nth-of-type(1) {
background-position: 0 -180px ;
}
.introSelect div:nth-of-type(2) {
background-position: -90px -180px;
}
.introSelect div:nth-of-type(3) {
background-position: -180px -180px;
}
.introSelect a {
display:block;
text-decoration: none;
}
.introSelect span {
background-color: rgba(152, 216, 242, 0.7);
color: #444;
font-weight: bold;
letter-spacing: 1px;
position: absolute; bottom: 0; left: 0; right: 0;
}
.introSelect .lab
etc. I agreed that using classes like that would reduce having to change CSS and HTML later. \$\endgroup\$