CSS2样式表(属性·背景)

1、background
 

语法:
background : background-color || background-image || background-repeat || background-attachment || background-position
取值:
该属性是复合属性。请参阅各参数对应的属性。
默认值为:transparent none repeat scroll 0% 0%。

说明:
设置对象的背景样式。
如使用该复合属性定义其单个参数,则其他参数的默认值将无条件覆盖各自对应的单个属性设置。
例如:设置 background : white 等于设置 background : white none repeat scroll 0% 0% 。如果在此之前设置了 background-image 属性,则其设置将被 background-image 的默认值 none 覆盖。
背景样式属性的作用区域为对象的内容区域与内补丁( padding )区域。不包括边框( border )与外补丁( margin )区域。尽管该属性不可继承,但如果未指定,其父对象的背景颜色和背景图将在对象下面显示。
对应的脚本特性为 background 。

示例:

div { background: red no-repeat scroll 5% 60%; }
body { background: url("images/aardvark.gif") repeat-y; }
pre { background: url("images/aardvark.gif") top; }
caption { background: fuchsia; }

2、background-attachment
 

语法:
background-attachment : scroll | fixed
取值:
scroll : 默认值。背景图像是随对象内容滚动
fixed : 背景图像固定

说明:
设置或检索背景图像是随对象内容滚动还是固定的。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
请参阅 bgProperties 属性(特性)。对应的脚本特性为 backgroundAttachment 。


示例:

html { background-image: url("anasazi.tif"); background-attachment: fixed; }
body { background-attachment: scroll; }

 

3、background-color
 

语法:
background-color : transparent | color
取值:
transparent : 默认值。背景色透明
color : 指定颜色。请参阅 颜色单位 和 附录:颜色表

说明:
设置或检索对象的背景颜色。
当背景颜色与背景图像( background-image )都被设定了时,背景图片将覆盖于背景颜色之上。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundColor 。

示例:

p { background-color: silver }
div { background-color: rgb(223,71,177) }
body { background-color: #98AB6F }
pre { background-color: transparent; }

4、background-image
 

语法:
background-image : none | url ( url )
取值:
none : 默认值。无背景图
url ( url ) : 使用绝对或相对 url 地址指定背景图像

说明:
设置或检索对象的背景图像。
当背景图像与背景颜色( background-color )都被设定了时,背景图片将覆盖于背景颜色之上。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundImage 。


示例:

code { background-image: url("comet.jpg"); }
blockquote { background-image: url("c:/InetPub/MyPixs/comet.jpg"); }
br { background-image: url(http://Fred.com/ImageFile/Q.gif); }
body { background-image: none; }

5、background-position
 

语法:
background-position : length || length
background-position : position || position
取值:
length : 百分数 | 由浮点数字和单位标识符组成的长度值。请参阅 长度单位
position : top | center | bottom | left | center | right

说明:
设置或检索对象的背景图像位置。必须先指定 background-image 属性。
该属性定位不受对象的补丁属性( padding )设置影响。
默认值为: 0% 0% 。此时背景图片将被定位于对象不包括补丁( padding )的内容区域的左上角。
如果只指定了一个值,该值将用于横坐标。纵坐标将默认为 50% 。如果指定了两个值,第二个值将用于纵坐标。
如果设置值为 right center ,因为 right 作为横坐标值将会覆盖 center 值,所以背景图片将被居右定位。
对应的脚本特性为 backgroundPosition 。



示例:

div { background: url("images/aardvark.gif"); background-position: 35% 80%; }
menu { background: url("images/aardvark.gif"); background-position: 35% 2.5cm; }
a { background: url("images/aardvark.gif"); background-position: 3.25in; }
body { background: url("images/aardvark.gif"); background-position: top right; }

6、background-position-x
 

语法:
background-position-x : length | left | center | right
取值:
length : 百分数 | 由浮点数字和单位标识符组成的长度值。请参阅 长度单位
left : 居左
center : 居中
right : 居右

说明:
设置或检索对象的背景图像横坐标位置。必须先指定 background-image 属性。
该属性定位不受对象的补丁属性( padding )设置影响。
默认值为: 0% 。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundPositionX 。



示例:

p { background-image: url("images/aardvark.gif"); background-position-x: 35%; background-repeat:no-repeat; }

7、background-position-y
 

语法:
background-position-y : length | top | center | bottom
取值:
length : 百分数 | 由浮点数字和单位标识符组成的长度值。请参阅 长度单位
top : 居顶
center : 居中
bottom : 居底

说明:
设置或检索对象的背景图像纵坐标位置。必须先指定 background-image 属性。
该属性定位不受对象的补丁属性( padding )设置影响。
默认值为: 0% 。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundPositionY 。


示例:

div { background-image: url("images/aardvark.gif"); background-position-y: 35%; background-repeat:no-repeat; }

8、background-repeat
 

语法:
background-repeat : repeat | no-repeat | repeat-x | repeat-y
取值:
repeat : 默认值。背景图像在纵向和横向上平铺
no-repeat : 背景图像不平铺
repeat-x : 背景图像仅在横向上平铺
repeat-y : 背景图像仅在纵向上平铺

说明:
设置或检索对象的背景图像是否及如何铺排。必须先指定对象的背景图像( background-image )。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundRepeat 。



示例:

menu { background: url("images/aardvark.gif"); background-repeat: repeat-y; }
p { background: url("images/aardvark.gif"); background-repeat: no-repeat; }

9、layer-background-color
 

语法:
layer-background-color : transparent | color
取值:
transparent : 默认值。背景色透明
color : 指定颜色。请参阅 颜色单位 和 附录:颜色表

说明:
设置或检索对象整个区域的背景颜色。



示例:

div { layer-background-color: transparent; }

10、layer-background-image
 

语法:
layer-background-image : none | url ( url )
取值:
none : 默认值。无背景图
url ( url ) : 使用绝对或相对 url 地址指定背景图像

说明:
设置或检索对象整个区域的背景图像。



示例:

code { position: absolute; top: 100px; left: 300px; width: 200px; border: thin solid black; background-image: url("comet.jpg"); layer-background-image: url("bb_comet.jpg"); }

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Tkinter是Python的一个标准GUI库,用于创建图形用户界面。它提供了一组丰富的控件和布局管理器,可以用于构建各种类型的应用程序。 CSS(层叠样式表)是一种用于描述网页样式的语言,它可以控制网页的布局、字体、颜色、背景等方面的样式。在Tkinter中,可以使用CSS样式表来美化应用程序的界面。 要在Tkinter中使用CSS样式表,需要借助第三方库tkinter-css,它提供了对CSS样式表的解析和应用功能。你可以通过pip安装该库: ``` pip install tkinter-css ``` 安装完成后,可以按照以下步骤来使用CSS样式表: 1. 创建一个Tkinter应用程序的主窗口对象。 2. 导入tkinter_css模块,并使用`set_style`函数加载CSS样式表文件。 3. 使用`get_style`函数获取指定控件的样式。 4. 使用`configure`方法将样式应用到控件上。 下面是一个简单的示例代码,演示了如何使用CSS样式表来设置按钮的样式: ```python import tkinter as tk import tkinter_css as tkcss root = tk.Tk() # 加载CSS样式表 tkcss.set_style("style.css") # 创建按钮 button = tk.Button(root, text="Click me") # 获取按钮的样式 style = tkcss.get_style(button) # 将样式应用到按钮上 button.configure(**style) button.pack() root.mainloop() ``` 在上面的示例中,我们创建了一个名为"style.css"的CSS样式表文件,其中定义了按钮的样式。然后通过`set_style`函数加载该样式表,并使用`get_style`函数获取按钮的样式,最后使用`configure`方法将样式应用到按钮上。 需要注意的是,tkinter-css库目前只支持部分CSS属性和选择器,具体可以参考它的文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值