ui.Panel.style

返回微件的样式 ActiveDictionary,该对象可修改以更新微件的样式。

行为与 CSS 对应项类似的属性:

  - height、maxHeight、minHeight(例如“100px”)

  - width、maxWidth、minWidth(例如“100px”)

  - 内边距、外边距(例如“4px 4px 4px 4px”或简单的“4px”)

  - color、backgroundColor(例如“red”或“#FF0000”)

  - 边框(例如“1px solid black”)

  - borderColor(例如“red black blue #FF0000”)

  - borderRadius(例如“10px”)

  - borderStyle(例如“solid dashed none dotted”)

  - borderWidth(例如“1px 0px 1px 0px”)

  - fontSize(例如“24px”)

  - fontStyle(例如“italic”)

  - fontWeight(例如“bold”或“100”)

  - fontFamily(例如“monospace”或“serif”)

  - textAlign(例如“left”或“center”)

  - textDecoration(例如“underline”或“line-through”)

  - whiteSpace(例如“nowrap”或“pre”)

  - 显示(true 或 false)

支持的自定义布局属性(请参阅 ui.Panel.Layout 文档):

  - stretch(“horizontal”“vertical”“both”)

  - 位置('top-right'、'top-center'、'top-left'、'bottom-right'、...)

用法返回
Panel.style()ui.data.ActiveDictionary
参数类型详细信息
this:ui.widgetui.Widgetui.Widget 实例。

示例

Code Editor (JavaScript)

// Define a UI widget and add it to the map.
var widget = ui.Panel({style: {width: '400px', height: '200px'}});
Map.add(widget);

// View the UI widget's style properties; an ActiveDictionary.
print(widget.style());

// ActiveDictionaries are mutable; set a style property.
widget.style().set('backgroundColor', 'lightgray');
print(widget.style());

// Define the UI widget's style ActiveDictionary as a variable.
var widgetStyle = widget.style();
print(widgetStyle);

// Set the UI widget's style properties from the ActiveDictionary variable.
widgetStyle.set({border: '5px solid darkgray'});
print(widgetStyle);