SCSS:检查元素是否具有属性

问题描述 投票:0回答:1

我需要检查元素是否具有要在移动设备上(或在响应模式下)应用的样式的属性。例如:

<tr>
    <td>Some text here</td>
    <td data-content="Hello there">Other text here</td>
    <td data-content="Hi there">Final text here</td>
</tr>

浏览器:

------------------------------------------------------
| Some text here | Other text here | Final text here |
------------------------------------------------------

移动设备(必填输出):

--------------------------------
| Some text here               |
| Hello there: Other text here | 
| Hi there: Final text here    |
--------------------------------

SCSS:

tr {
    td {
        ...

        @if (&[data-content]) {
            &:before {
                content: attr(data-content) ":";
                float: left;
                font-size: 12px;
                font-weight: bold;
                margin: 0 5px 0 0;
                text-transform: uppercase;
            }
        }
    }
}

移动设备(当前输出):

--------------------------------
| : Some text here             |
| Hello there: Other text here | 
| Hi there: Final text here    |
--------------------------------
if-statement sass attributes exists
1个回答
0
投票

我找到了解决方案。显然,这很容易...

SCSS:

tr {
    td {
        ...

        &[data-content] {
            &:before {
                content: attr(data-content) ":";
                float: left;
                font-size: 12px;
                font-weight: bold;
                margin: 0 5px 0 0;
                text-transform: uppercase;
            }
        }
    }
}

当前输出:

--------------------------------
| Some text here               |
| Hello there: Other text here | 
| Hi there: Final text here    |
--------------------------------
© www.soinside.com 2019 - 2024. All rights reserved.