是否可以使用ID标记来更改css内容

Dan*_*bio 2 html css html5 css3

有没有办法从HTML获取ID

例如:

 id="title1"
Run Code Online (Sandbox Code Playgroud)

所以它需要显示在css中的content:部分.

    <table class="layout display responsive-table">
        <thead>
            <tr>
                <th class="th" id="title1">Title12</th>
                <th class="th">Title2</th>
                <th class="th">Title3</th>
                <th class="th">Title4</th>
            </tr>
        </thead>


table.responsive-table td:nth-child(1):before {
        content: use id here;
    }
    table.responsive-table td:nth-child(2):before {
        content: 'Title 2';
    }
Run Code Online (Sandbox Code Playgroud)

Zaq*_*aqx 6

是的,使用attr()函数.

table.responsive-table td:nth-child(1):before {
  content: attr(id);
}
Run Code Online (Sandbox Code Playgroud)

https://developer.mozilla.org/en-US/docs/Web/CSS/attr