【问题标题】:CSS styling targeting elements in Xamarin FormsXamarin Forms 中的 CSS 样式定位元素
【发布时间】:2021-05-28 13:37:39
【问题描述】:

我的表单应用正在读取提要,内容提供者想要使用 HTML

这样做的首选方法是利用 CSS,但我无法确定如何定位元素

例如,像这样设置文本颜色没有问题:

.newsPageBody {
color: pink;
}

工作正常。然而,这不是:

.newsPageBody h1 {
    color: green;
}

除了标记整个传入的提要之外,有没有办法实现这一点?

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    有几种方法可以使用 css 选择元素。

    您可以查看Selecting elements and applying properties。和Styling Xamarin.Forms Apps with CSS

    1. 按类型选择元素

      stacklayout {
      
         margin: 20;
       }
      
    2. 按基类选择元素

      ^Entry {
        font-size: 30;
        background-color: white;
        margin: 10 0;
        color: #0A100D;
       }
      
    3. 按名称选择元素

      #listView {
        background-color: lightgray;
      }
      
      <ListView x:Name="listView" ...>
          ...
      </ListView>
      
    4. 选择具有特定类属性的元素

      .detailPageTitle {
         font-style: bold;
         font-size: medium;
         text-align: center;
       }
      
      .detailPageSubtitle {
         text-align: center;
         font-style: italic;
       }
      
      <Label ... StyleClass="detailPageTitle" />
      <Label ... StyleClass="detailPageSubtitle"/>
      

    等等。

    【讨论】:

    • 请原谅我的愚蠢,但我没有看到这些示例中的任何一个显示了如何解决我上面强调的问题,即针对特定的 HTML 标记,如 H1?
    猜你喜欢
    • 2020-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多