I’m trying to recreate this image to HTML/CSS/JS: (Using HTML5 semantics)
This is the question that was asked to me:
Here’s my implementation. However, I am not sure how do I get/update Numbers “30”, “19” etc Dynamically? I’m stuck there, please help.
.endorsements {
background: #f0f0f0;
border-left: 20px solid #49a9e1;
display: block;
margin: 10px;
}
.endorsements::after {
content: '+'
}
<article>
<section id="endo">
<button aria-label="css" class="endorsements"> CSS </button>
<button aria-label="web" class="endorsements"> Web Development </button>
<button aria-label="SEO" class="endorsements"> SEO </button>
<button aria-label="HTML" class="endorsements"> HTML </button>
</section>
</article>
Can someone help me to recreate this spec? I’m not sure using ::after would be a good idea?
2
Answers
I would build the whole thing up in a
for-loop
, and with “the whole thing”, I mean each row.Add the value to a
data-attribute
, and useconcent: attr(data-attribute)
to display the number.If you’re not creating the HTML structure row by row, do a
document.querySelectAll('.endorsement')
[edit] after you got your data from a server, loop through the response and add eachdata-attribute
selectively.[edit] Also, remove
border-left: 20px solid #49a9e1
from.endorsement
;So as I said in my comment, I’d recommend using something like an object which can be looped over to build your html (Actually, if you were more experienced, I’d recommend something like Angular – it’s amazing for stuff like this).
Also note that I wouldn’t use a
before::
pseudo element for the number, just put it in a div. See below;