简体   繁体   English

background-color不适用于div

[英]background-color is not working with div

I am trying to set background-color for div element "High Tatras" "High Tatras 2"...elements to yellow with css. 我正在尝试将div元素“ High Tatras”,“ High Tatras 2” ... elements的背景色设置为带有CSS的黄色。

gallery li {background-color: yellow;}

jsfiddle demo http://jsfiddle.net/pragnesh/CjDDB/ jsfiddle演示http://jsfiddle.net/pragnesh/CjDDB/

But background-color yellow only applied to top and bottom part of element. 但是背景色黄色仅应用于元素的顶部和底部。

What could be problem with this code? 此代码可能有什么问题?

jquery-ui seems to have a weird multiple background css rule (lol it's not a multiple background... just the comments threw me off... it's late). jquery-ui似乎有一个 奇怪的多个背景css规则 (大声笑不是多重背景...只是评论使我失望...太晚了)。 Try using just the background attribute instead: 尝试仅使用background属性代替:

.gallery li {
    background: yellow;
}

Demo: http://jsfiddle.net/j2TtX/ 演示: http//jsfiddle.net/j2TtX/

The rule that is causing the background is this one: 导致背景的规则是这样的:

.ui-widget-content { 
    border: 1px solid #aaaaaa/*{borderColorContent}*/;
    background: #ffffff/*{bgColorContent}*/ url(images/ui-bg_flat_75_ffffff_40x100.png)/*{bgImgUrlContent}*/ 50%/*{bgContentXPos}*/ 50%/*{bgContentYPos}*/ repeat-x/*{bgContentRepeat}*/;
    color: #222222/*{fcContent}*/;
}

jQuery UI库中有白色背景图像,请在CSS中添加此行以覆盖css规则。

.gallery li.ui-widget-content{background-image:none;}​

Overrating this background that is the issue , You should remove background property in this class ".ui-widget-content" 高估这个问题的背景,您应该在此类“ .ui-widget-content”中删除背景属性

.ui-widget-content {
    background: url("images/ui-bg_flat_75_ffffff_40x100.png") repeat-x scroll 50% 50% #FFFFFF;
    border: 1px solid #AAAAAA;
    color: #222222;
}

It comes from jquery-ui.css (line 243) 它来自jquery-ui.css(第243行)

Here is Working Code 这是工作代码

Problem is once you set the background-image for a div then you can not override it via background-color because it only set only color property(which has low priority than image) while background property will reset all background related properties ie, 问题是,一旦为div设置了background-image ,便无法通过background-color覆盖它,因为它仅设置了color属性(其优先级低于image),而background属性将重置所有与背景相关的属性,即,

  1. background-color 背景颜色
  2. background-image 背景图
  3. background-position 背景位置
  4. background-repeat 背景重复
  5. background-attachment 背景附加

and set the color. 并设置颜色。 So use: 因此使用:

 background: yellow;

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

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