I have this code:
<ul>
<li><a>my link 1</a></li>
<li><a>my link 2</a></li>
<li><a>my link 3</a></li>
</ul>
When I apply padding to <a>
like so:
ul {
list-style: none;
margin: 30px 0 0 2.6em;
}
ul li {
height: 41px;
width: 196px;
background: url(images/image.png) no-repeat;
position: relative;
}
ul li a {
padding-top: 5px;
}
The padding works but it collapses and goes through the top edge of <li>
instead of pushing the <a>
down. How ca I resolve this?
Complete HTML/CSS Course 2022 Left padding padding-left is to be added to <ul> tag list item i.e. <li> tag. Through this, padding gets added, which will create space between list bullets and text in HTML.
You can add padding: 0 to the ul element to force it to stick to the left border of the parent nav element.
To make a right-aligned version of the list, only three changes need to occur. First, set the "UL" "text-align" to "right". Second, change the left "background-position" from "0" to "100%" - which makes the image align up with the right edge. And finally change "padding-left" to "padding-right".
The amount varies on each browser. Some browsers use padding (Mozilla, Netscape, Safari) and others use margins (Internet Explorer, Opera) to set the amount of indentation. To remove this left-indentation consistently across all browsers, set both padding and margins to "0" for the "UL".
you should give your "a" display:inline-block
anchors are "inline" by default and won't show padding properly.
jsFiddler demo: http://jsfiddle.net/PqajF/3/
ul li a
{
padding-top: 5px;
display: inline-block;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With