2

I need to create a CSS class that will allow me to list all the ingredients in a recipe. Here are the specifications for the unordered list:

  • Left indent
  • No bullet or other icon
  • No space between heading (H2) and first item in list
  • No space between items in list
  • Space after last item in list

I need to do this without effecting the regular paragraphs, regular unordered lists, or other settings.

Good at HTML; poor at CSS, so explicit directions would be helpful.

2 Answers 2

3

CSS works by priority and identifiers. To target all H2 elements on a page, you would declare

h2 {
 color: #00FF00;
}

However, you can also get more specific and target only H2 elements within a DIV for instance:

div h2 {
 color: #00FF00;
}

Along with targeting just the elements, you can use either an ID or CLASS name to help the targeting. Use the # symbols to target IDs and the . to target CLASSES

HTML

<div id="ingredients">
<h2>Heading</h2>
<ul>
<li class="selected">Item 1</li>
<li>Item 2</li>
</ul>
</div>

CSS

    #ingredients {
    margin: 0em;
    margin-left: 1em;
    }    

    #ingredients h2 {
         color: #00FF00;
    margin-bottom: 0em;
        }

   #ingredients ul {
    margin-bottom: 2em;
   }
    #ingredients ul li {
     list-style: none;
     margin: 0em .5em;
     color: #00FFFF;
    }
    #ingredients ul li .selected {
     color: #FFFF00;
    }

Finally, CSS also has importance in the order of declaration, consider the following

h1 {
font-size: 2em;
font-color: #000000;
}

h1 {
font-color: #FF0000;
}

In this case, the H1 color will be red due to the fact the second H1 declaration overwrites the previous one. Just s note to remember. }

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the help and detailed explanation. Helped me understand what's going on here. :)
0
h2 {
    margin-bottom: 0;   // eliminate distance from headline, applies to all h2s though
}
ul {
    padding: 0 0 0 1em; // left indent, no other padding
    margin: 0 0 1em 0;  // space on bottom, maybe use a bottom-padding instead
}
ul li {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.