I'm working with 20 spans representing movie genres, each accompanied by another span that "closes" the genre when selected. The closing span has an .active
class, similar to this example:
https://i.sstatic.net/7CuuX.png
My version currently looks like this: https://i.sstatic.net/aFoE6.png
To achieve this, I have placed the "close" span inside the span containing the genre name, resulting in a larger span size. Is there a way to replicate the functionality in the image without adding excessive code?
Below is the HTML code snippet:
<div class="genres">
<span>action<span class="close active">x</span></span>
<span>adventure</span>
<span>animation</span>
<span>comedy</span>
<span>crime</span>
<span>documentary</span>
<span>drama</span>
<span>family</span>
<span>fantasy</span>
<span>history</span>
<span>horror</span>
<span>music</span>
<span>mystery</span>
<span>romance</span>
<span>science fiction</span>
<span>TV movie</span>
<span>thriller</span>
<span>war</span>
<span>western</span>
</div>
I initially considered adding the "close" span to every genre span individually, but this would increase span sizes significantly. Alternatively, placing these spans in separate divs would lead to bloated code.
Here are the CSS styles applied:
.genres span{
color: rgba(0, 0, 0, 0.87);
display: flex;
text-transform: capitalize;
cursor: pointer;
background-color: #fff;
line-height: 3px;
border-radius: 10px;
padding:10px;
font-size: 0.850rem;
margin:2px;
font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.genres span.close{
display: inline;
text-transform: none;
padding: 10px;
margin:0;
border-radius: 10px;
font-size: 0.8rem;
color: #3f51b5;
background-color: rgba(172, 157, 157, 0.7);;
}