2
\$\begingroup\$

I will design a list with a Font-Awesome design arrows. My code already works fine, but I will improve it.

ul.long_arrow_right_red,ul.long_arrow_right_gold {list-style: none;}
ul.long_arrow_right_gold li:before {content:"\f178"; font-family: FontAwesome;display: block;float: left;width: 1.5em;color:gold;}
ul.long_arrow_right_red li:before {content:"\f178"; font-family: FontAwesome;display: block;float: left;width: 1.5em;color:red;}
<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
<ul class="long_arrow_right_gold">
		<li>Title
			<ul class="long_arrow_right_red">
				<li>Lorem</li> 
				<li>Epsum</li> 
			</ul>				
		</li>
		<li>Title</li>
	</ul>

Questions:

  1. How to use an extra class which define only the color for the li icon? The text inside shouldn't change the color.

    Existing other css code, which I use for text coloring:

    .red{color:red;}
    .gold{color:gold;}
    
  2. I think it would be better not do have duplicate following statements:

    font-family: FontAwesome;display: block;float: left;width: 1.5em;
    

    How to combine them with a different content: definition?

  3. If you have other improvement ideas, please tell me them.

asked Mar 12, 2016 at 17:06
\$\endgroup\$
5
  • \$\begingroup\$ What determines whether a list should be red or gold? \$\endgroup\$ Commented Mar 12, 2016 at 18:33
  • \$\begingroup\$ @200_success It is the unicode for a long arrow right. You can see it here. \$\endgroup\$ Commented Mar 12, 2016 at 18:43
  • \$\begingroup\$ I have updated my question. I have put the css-source file to the snippet. The css class should determine the color I think. Something like class="long_arrow_right red" \$\endgroup\$ Commented Mar 12, 2016 at 18:51
  • \$\begingroup\$ What I mean to ask is, why would you choose red or gold? Does it alternate, or is there some meaning to the color code? \$\endgroup\$ Commented Mar 12, 2016 at 18:54
  • \$\begingroup\$ @200_success I would propose another color for a child <ul>, but I want maybe later use other colors, too. \$\endgroup\$ Commented Mar 12, 2016 at 19:02

2 Answers 2

1
\$\begingroup\$

Properly formatted CSS can make your styles vastly more readable, helping you find bugs as well as making it easier to work with.

This:

ul.long_arrow_right_red,ul.long_arrow_right_gold {list-style: none;}
ul.long_arrow_right_gold li:before {content:"\f178"; font-family: FontAwesome;display: block;float: left;width: 1.5em;color:gold;}
ul.long_arrow_right_red li:before {content:"\f178"; font-family: FontAwesome;display: block;float: left;width: 1.5em;color:red;}

Should instead be something like this:

ul.long_arrow_right_red,
ul.long_arrow_right_gold {
 list-style: none;
}
ul.long_arrow_right_gold li:before {
 content: "\f178"; 
 font-family: FontAwesome;
 display: block;
 float: left;
 width: 1.5em;
 color: gold;
}
ul.long_arrow_right_red li:before {
 content: "\f178"; 
 font-family: FontAwesome;
 display: block;
 float: left;
 width: 1.5em;
 color: red;
}

If you want to have the code "minified" then do that before you deploy it, source code should aim for readability and maintainability, rather than length / character count.

Jack Wilsdon
1,6613 gold badges21 silver badges37 bronze badges
answered Mar 12, 2016 at 18:11
\$\endgroup\$
1
  • \$\begingroup\$ Thank you. I have forgot to unminify my css code. Do you also could answer Question 1 and 2? \$\endgroup\$ Commented Mar 12, 2016 at 20:40
1
\$\begingroup\$

I have a solution for my question one and two: using one class to make the arrows, and a second class for choosing the color.

ul.long_arrow_right {list-style: none;}
ul.long_arrow_right li:before {content:"\f178"; font-family: FontAwesome;display: block;float: left;width: 1.5em;color:green;}
ul.gold li:before 	{color:gold;}
ul.red li:before 	{color:red;}
<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" />
<ul class="long_arrow_right gold">
		<li>Title
			<ul class="long_arrow_right red">
				<li>Lorem</li> 
				<li>Epsum</li> 
			</ul>				
		</li>
		<li>Title</li>
	</ul>

200_success
146k22 gold badges191 silver badges481 bronze badges
answered Mar 18, 2016 at 20:10
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.