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

SCSS: Check if the element has the attribute

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

<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    |
--------------------------------

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

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    |
--------------------------------