How to put CSS in more than one LI (list/html)

Asked

Viewed 33 times

-2

good afternoon. I am participating in a course where our challenge is to make a simple "visit" card. Well, I almost finished, but I can’t put the logos next to the sites. First I made the UL list and took the balls out in CSS and then added links with target Blank for the person to click and direct. The question, how do I put the logos separately ? I tried to create a class in the <a></a> e até no <li></li> to put but the css didn’t work.

<div class="corpo">
        <h1>Mateus Malvezzi</h1>
        <img src="m².jpg" alt="foto mateus">
        <ul>
            <a href="https://www.instagram.com/"  target="_blank"><li>Instagram</li></a>
            <a href="https://www.linkedin.com/in/mateus-malvezzi-1a0913181/" target="_blank"><li>LinkedIn</li></a>
            <a href="https://github.com/MateusMalvezzi" target="_blank"><li>GitHub</li></a>
        </ul>
    </div>

The HTML is like this. And the "finished" card looks like this.

inserir a descrição da imagem aqui

  • 1

    The only direct child of a ul can only be one li. You can’t put a a as the direct son of a ul as you are doing. You must put everything inside the li. Type: <li><a href="">link</a> Instagram</li>.

  • Mm, I get it!

  • That’s probably why I’m not getting success in logos, right?

1 answer

-2

You can customize this way also in css by inserting the image for each li an image:

li{
   list-style: none;
}
ul li:nth-child(1)::before{
   content: '';
   display: inline-block;
   height: 25px;
   width: 25px;
   background-image: url('suaimagem');
   background-size: contain;
}
ul li:nth-child(2)::before{
   content: '';
   display: inline-block;
   height: 25px;
   width: 25px;
   background-image: url('suaimagem');
   background-size: contain;
}

  • Boy, very good! I was unaware of some concepts that are there, thank you very much. :)

  • I liked the intention, but the way you did it’s not very good because it inflates the code too much. The ideal would be to create a generic class with the common properties and other 3 where only changes the icon image for each link. Besides, if the guy decides to change the order of the links, he’ll have to change the indexes on nth-child.

  • Interesting @Sam. I will check the applicability of the two tips in my code. !

  • For sure @Sam this css is just a static possibility, but dynamically it would give to do also via javascript.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.