简体   繁体   English

应用于`ul li`时,如何使我的背景颜色填充div的整个宽度?

[英]How do I make my background-color fill entire width of div when applied to a `ul li`?

I'm using jQuery-UI-Layout plugin that creates a pane on the east side of the screen.我正在使用 jQuery-UI-Layout 插件在屏幕的东侧创建一个窗格。 When I create a list in it and apply a background-color to each <li> element, it doesn't span the width of the entire pane.当我在其中创建一个列表并将背景颜色应用于每个<li>元素时,它不会跨越整个窗格的宽度。

I would like it so that there is no white space on either side of the <li> , even if it has a bullet or number next to it (meaning if I decide to include a bullet or number, it should also be covered by the color).我希望<li>两侧没有空白,即使它旁边有一个项目符号或数字(这意味着如果我决定包含一个项目符号或数字,它也应该被颜色)。 How can I do this?我怎样才能做到这一点?

Fiddle: http://jsfiddle.net/5EECD/497/小提琴: http : //jsfiddle.net/5EECD/497/

HTML: HTML:

<div class="ui-layout-center">Center</div>

<div class="ui-layout-east">
    <ol id="someList">
        <li class="not-selected">step 1</li>
        <li class="selected">step 2</li>
        <li class="not-selected">step 3</li>
        <li class="not-selected">step 4</li>
    </ol>

</div>

CSS : CSS :

.selected {
    background-color: #e90902;
    padding-top: 10px;
    border-bottom: 1px solid #808080;
    padding-bottom: 10px;
}

.not-selected {
    padding-top: 10px;
    padding-bottom: 10px;
    background-color: #e9e9e9;
    border-bottom: 1px solid #808080;
}

Add this to your CSS file:将此添加到您的 CSS 文件中:

.ui-layout-pane-east {
    padding: 0 !important;
}

Don't do this from the browser's inspector.不要从浏览器的检查器中执行此操作。 jQuery UI's inner workings are supposed to calculate widths on page load. jQuery UI 的内部工作应该在页面加载时计算宽度。

Try Removing the尝试删除

padding: 10px

from the following in css来自以下css

body > div.ui-layout-east.ui-layout-pane.ui-layout-pane-east

It might not be the best way of doing it, though you can expand the margins of the <li> to fill the pane.这可能不是最好的方法,尽管您可以扩展<li>的边距以填充窗格。

li{
    margin: 0px -10px 0px -10px;    
}

JSFiddle JSFiddle

Here is your edited working Fiddle , with a List Style Disc "inside" the actual list item, by using the list-style-position style.这是您编辑的工作 Fiddle ,通过使用 list-style-position 样式,在实际列表项“内部”有一个 List Style Disc。 To remove the Disc icon, simple use the style "none" instead.要删除光盘图标,只需使用样式“无”即可。

If you set the font-size to 0px and that will remove all white space from list items, as long as the list item has a given font size which is shown in the example.如果您将 font-size 设置为 0px 并且这将删除列表项中的所有空白,只要列表项具有示例中显示的给定字体大小。

I just added a little CSS to your working CSS:我只是在您的工作 CSS 中添加了一些 CSS:

ol#someList {
  font-size:0px;
  padding-left:0px;
  list-style:disc;
  list-style-position: inside;
}

ol#someList li {
  font-size:14px
}

I also added a body style to remove the default margin of 8px to show you that there is no white space to left or right of the list items.我还添加了一个 body 样式来删除 8px 的默认边距,以向您显示列表项的左侧或右侧没有空白。

Hope that helps!希望有帮助! Michael G迈克尔·G

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

相关问题 如何使用 CSS 为文本宽度而不是整个元素的宽度设置背景颜色? - How do I set a background-color for the width of text, not the width of the entire element, using CSS? 如何使background-color超过父div的宽度? - How to make background-color go over the width of parent div? 如何使背景色填充li标签的整个元素 - how to make the background color fill the entire element of a li tag 即使使用水平滚动,如何使我的背景颜色填充所有内容? - How can I make my background-color fill all my content, even with horizontal scrolling? 我如何在具有黑色背景颜色的div上创建具有透明背景颜色的特定div - How can I make a specific div with transparent background-color over a div with black background-color 如何更改最后一个li和ul之间的背景颜色? - How can I change the background-color in between last li and ul? 如何设置div的背景颜色宽度? - How to set the width of background-color of a div? 当盘旋时,如何使菜单项的整个宽度改变背景颜色? - How do I make the entire width of a menu item change background color when hovered over? 如何让我的背景颜色覆盖我的整个DIV不仅仅是在它的文本? - How do I make the background color cover my entire DIV and not just the text in it? 如何在div标签上制作背景色 - how to make a background-color on a div tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM