Objective
Currently I have the flags hardcoded. But want to optimize my code for production. So I am wondering if I have this code done clean enough to leverage CSS inheritance while maintaining support for older browsers.
I have this menu on my CodePen
whose size will vary per device (media queries not shown yet). I restructured my code from <div>
's to this <ul>
HTML
<ul class="international">
<li class="intlFlag usFlag"></li>
<li>North America</li>
<li class="intlButton">
<a href="#"> <!-- link pending -->
<i class="fa fa-globe"></i>
</a>
</li>
</ul>
On the div with the flag, I want to be able to pass its CSS rules without giving it the class of intlFlag
and for the intlButton
I want to also pass rule without giving it the class. I hesitated to use the :last-of-type
selector because it is not supported below IE8, and many users of the site will unfortunately use IE8.
Image from w3schools.com
As far as the first <li>
I want the class to be passed in based on what country they are detected to be coming from. So the script would for example detect that you are in North America. And then pass in that class which then sets your flag. In production I will be using MustacheJS templates. So I plan to do something like this
<ul class="international">
<li class="{{{flag}}}"></li>
<li>{{region}}</li>
<li class="intlButton">
<a href="/international">
<i class="fa fa-globe"></i>
</a>
</li>
</ul>
my JSON values might be something like
"flag":"usFlag",
"region":"North America"
That usFlag
class would add this class to display the respective flag
.usFlag { background-position: 0px 0px; }
the other rules passed into that <li>
are currently passed in with
.intlFlag {
background-color: #fff;
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/101702/flag-sprite.png');
height: 28px;
width: 44px;
}
Here are the complete set of my CSS rules for this element
.international {
background-color: rgba(96, 80, 80, 0.3);
font-size: 18px;
line-height: 42px;
list-style-type: none;
margin: auto;
padding-left: 0;
position: absolute;
bottom: 0; left: 0; right: 0;
width: 100%;
}
/* only on tablet */
.international { max-width: 240px; }
.international > li {
display: inline-block;
line-height: 42px;
margin-left: 6px;
vertical-align: middle;
}
.intlFlag {
background-color: #fff;
background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/101702/flag-sprite.png');
height: 28px;
width: 44px;
}
.usFlag { background-position: 0px 0px; }
.intlButton {
float: right;
font-size: 24px;
margin-right: 6px;
}
.intlButton a { color: #444; }
.intlButton i {
background-color: rgba(225, 225, 225, .7);
border-radius: 3px;
padding: 4px;
}
<i>
element for icons. \$\endgroup\$<span>
s might be more appropriate here? \$\endgroup\$