简体   繁体   English

填充到列表项?

[英]Padding to list item?

Trying to make a small navigation here.试图在这里做一个小导航。 jsfiddle below.下面的jsfiddle。

http://jsfiddle.net/s3king93/yjKdR/ http://jsfiddle.net/s3king93/yjKdR/

Is there any way to add padding to the link items without having the text get larger or move?有没有办法在不让文本变大或移动的情况下向链接项添加填充?

I'd like it to ideal look like this http://i.imgur.com/0zDt0vR.png我希望它看起来像这样http://i.imgur.com/0zDt0vR.png

Any ideas?有任何想法吗?

HTML HTML

<div class="list-1">
    <ul class="list-style-1">
        <li><a href="">HOME</a></li>
        <li><a href="">INFLUENCES</a></li>
        <li><a href="">ABOUT ME</a></li>
        <li><a href="">CLASSES</a></li>
        <li><a href="">ANDREWS VIDEO BLOG</a></li>
        <li><a href="">PHOTOGRAPHY</a></li>
    </ul>
</div>

CSS CSS

.list-1 {
    padding:none;
    float: right;
    clear:right;
    padding-right: 27px;
}

.list-style-1 {
    padding-top: 26px;
    list-style-type: none;
    font-family: "Bell Gothic Std Light";
    font-size: 20px;
}

a:link {
    text-decoration:none;
    color: #2A2A2A;
}

a:visited {
    text-decoration:none;
    color: #2A2A2A;
}

a:hover {
    text-decoration:none;
    color: #69E0F6;
    background-color: #2A2A2A;
    padding-left: 5px;
    padding-right: 70px;
}

a:active {
    text-decoration:none;
    color: #69E0F6;
    background-color: #2A2A2A
}

<ul> is already a block-element by default so you don't need a div around it. <ul>默认情况下已经是块元素,因此您不需要在它周围添加 div。

Plus, on a:hover you have padding-right set to 70px .另外,在a:hover你有padding-right设置为70px That's why your list is moving when you're hovering.这就是为什么当您悬停时您的列表会移动的原因。 I don't understand though why you have that padding on hover.我不明白为什么你在悬停时有那个填充。 If you remove the paddings on hover your list will remain where it is.如果您在悬停时删除填充,您的列表将保留在原处。

Is this what you want?这是你想要的吗?

You're putting on the padding when you hover over the links, and that extra padding is making the link go past the end of the DIV.当您将鼠标悬停在链接上时,您正在添加内边距,而额外的内边距使链接越过 DIV 的末尾。 FOr this reason, the browser pushes it back so it all fits in the DIV.出于这个原因,浏览器将其推回,使其全部适合 DIV。

You should assign it before hover (on a:link instead of a:hover), and the link won't move.您应该在悬停之前分配它(在 a:link 而不是 a:hover),并且链接不会移动。

This CSS should do what you want:这个 CSS 应该做你想做的:

.list-1 {
    padding:none;
    float: right;
    clear:right;


}


.list-style-1 {
    padding-top: 26px;
    list-style-type: none;
    font-family: "Bell Gothic Std Light";
    font-size: 20px;
}


a:link {
    text-decoration:none;
    color: #2A2A2A;
    padding-right: 70px;
    padding-left: 5px;
}

 a:visited {
    text-decoration:none;
    color: #2A2A2A;
}

a:hover {
    text-decoration:none;
    color: #69E0F6;
    background-color: #2A2A2A;
}

a:active {
    text-decoration:none;
    color: #69E0F6;
    background-color: #2A2A2A
}

See it working here:看到它在这里工作:

http://jsfiddle.net/yjKdR/4/ http://jsfiddle.net/yjKdR/4/

You need to keep the padding consistent when hovered.悬停时,您需要保持填充一致。

Move the padding from a:hover to a:link .将填充从a:hover移动到a:link I'd also suggest qualifying those styles so they don't apply to every link on the page:我还建议对这些样式进行限定,以便它们不适用于页面上的每个链接:

.list-style-1 a:link {
  text-decoration:none;
  color: #2A2A2A;
  padding-left: 5px;
  padding-right: 70px;
}

.list-style-1 a:visited {
  text-decoration:none;
  color: #2A2A2A;
}

.list-style-1 a:hover {
  text-decoration:none;
  color: #69E0F6;
  background-color: #2A2A2A;
}

Remove the padding properties and set the a tag to display block.删除填充属性并将 a 标记设置为显示块。

.list-1 {
    padding:none;
    float: right;
    clear:right;
 }

.list-style-1 a{
    width:100%;
    display:block;
}

jsFiddle js小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM