简体   繁体   English

填写框的CSS背景文本

[英]CSS background text filling the box

I'm trying to make a copy of a website as my first CSS/HTML exercise. 我正在尝试将网站的副本作为我的第一个CSS / HTML练习。 I can't figure out how to make the menu list so it has its background filling the box (extending until the right border). 我无法弄清楚如何制作菜单列表,因此它的背景填充框(延伸到右边框)。

Picture of what I have now (right side of the picture, red lines show where the background should go) and what I want to get (left side). 我现在拥有的图片( 图片的右侧,红线表示背景应该去的地方)和我想要的东西(左侧)。

My code . 我的代码

I've tried so far to achieve it eg with 'width' and 'display' parameters, but eg display: block; 到目前为止,我已尝试使用'width'和'display'参数实现它,例如display: block; remove the lines between text. 删除文本之间的行。 I'm out of ideas. 我没有想法。

        display: block;
        width: 100%;
        margin-bottom: 2px;

to the #menu #menu

spans are inline elements so they cannot have width or height . spans是内联元素,因此它们不能具有widthheight You should put a background-color to your li elements instead of your spans . 你应该为你的li元素而不是你的spans background-color

.menu{
   background-color: grey; //Change it to your custom colour.
}

Also, you cannot have more than one element with the same ID . 此外, 您不能拥有多个具有相同ID元素 You have to put them as a class. 你必须将它们作为一个类。

Updated JSFiddle . 更新了JSFiddle

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

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