← Back toCSS Layout

Box selector

Written byPhuoc Nguyen
Category
Input
Created
24 Sep, 2022

HTML

index.html
<div class="box-selector">...</div>

<!-- The selected variant -->
<div class="box-selector box-selector--selected">...</div>

CSS

styles.css
.box-selector {
border: 1px solid #d1d5db;
border-radius: 0.25rem;
padding: 0.5rem;
}

.box-selector--selected {
/* Change the border color */
border: 2px solid #3b82f6;

/* Used to position the tick */
position: relative;
}

/* The tick */
.box-selector--selected:before {
/* Absolute position */
content: '';
left: 0.25rem;
position: absolute;
top: 0.25rem;

/* Size */
height: 1rem;
width: 1rem;

/* Background */
background-image: url("data:image/svg+xml,%3Csvg fill='%233b82f6' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' %3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z'%3E%3C/path%3E%3C/svg%3E");
background-position: center center;
background-repeat: no-repeat;
}

See also

Questions? 🙋

Do you have any questions? Not just about this specific post, but about any topic in front-end development that you'd like to learn more about? If so, feel free to send me a message on Twitter or send me an email. You can find them at the bottom of this page.
I have a long list of upcoming posts, but your questions or ideas for the next one will be my top priority. Let's learn together! Sharing knowledge is the best way to grow 🥷.

Recent posts ⚡

Newsletter 🔔

If you're into front-end technologies and you want to see more of the content I'm creating, then you might want to consider subscribing to my newsletter.
By subscribing, you'll be the first to know about new articles, products, and exclusive promotions.
Don't worry, I won't spam you. And if you ever change your mind, you can unsubscribe at any time.
Phước Nguyễn