简体   繁体   English

简单的CSS模板上的填充和边距问题

[英]Padding and margin issue on a simple css template

This is my code: 这是我的代码:

http://jsfiddle.net/spadez/rAQYL/1/ http://jsfiddle.net/spadez/rAQYL/1/

I am trying to achieve three things but I am a bit stuck. 我正在努力实现三件事,但我有些困惑。

  1. Remove padding below "admin" (where you see the green behind) 删除“管理员”下方的填充(您会在其中看到绿色)
  2. Remove padding above list (where you see the green behind) 删除列表上方的填充(您会在后面看到绿色)
  3. Add a 1px space on the left of each list item (so you can see the green behind). 在每个列表项的左侧添加一个1px的空格(以便您可以看到后面的绿色)。

Since I used this code I dont know where the space is coming from: 由于我使用了这段代码,所以我不知道空间来自哪里:

* {
    padding: 0px;
    margin: 0px;
    border: 0px;
}

Then to get the 1px space between each list item I used this code but it doesnt seem to work: 然后为了获得每个列表项之间的1px间隔,我使用了这段代码,但它似乎不起作用:

#header ul li {
padding-left: 1px;
}

Can someone who me where I am going wrong please? 有人能帮我解决我的问题吗?

Your additional space is coming from this rule 您的额外空间来自此规则

#header h1, #header ul, #header ul li {
    ...
    background: white;
    padding: 5px 12px;
}

See how you're applying padding to ul and then to li s within ul s too? 看看您是如何对ul然后在ul内的li应用填充的吗? It's adding up. 它加起来。

The same rule is responsible for no green background showing, you're setting the entire ul s background to white. 相同的规则导致没有绿色背景显示,您将整个ul背景设置为白色。

Also try chaning padding-left on li s to margin-left : 还可以尝试将lipadding-left更改为margin-left

#header li{
    margin-left: 10px
}

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

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