Reputation: 2876
I want to add an image within a <li>
without interfering with the size of <li>
. I want the image to be in the top-left side with 0 margin from the top, bottom and left as shown below:
I used this HTML code:
<li><img src="image.jpg">text</li>
and this CSS:
ul li
{
max-height:52px;
}
ul li img
{
max-width:52px;
max-height:52px;
margin-top:-15px;
margin-left:-15px;
float:left;
}
to make it look like that:
which looks fine for all the screen sizes. But the way of doing it is not professional.
What is the best practice to add the image and have a 0 margin from the top, right and left within a <li>
?
In this case I added a max-height for the <li>
to make it work. Is there a way to do it with a parent-child relationship and make the image interactive depending on the <li>
height?
Upvotes: 0
Views: 2035
Reputation: 50
try this
ul {
list-style-image: url('image.png');
}
in your css class
Upvotes: 1
Reputation: 632
I would put images in its own tag (let it be img, div) and style its CSS.
Try using either
"float: left;"
"position: relative;"
to work with positioning.
Upvotes: 0