[英]How to select html element that seems to another in css
I have two elements that are very seems to each other.我有两个非常相似的元素。
<td class="order_table_cell" data-title="status">Processing</td>
And I have another one element has same class and data title name:我还有另一个元素具有相同的 class 和数据标题名称:
<td class="order_table_cell" data-title="status">Complete</td>
I have no access on HTML.我无法访问 HTML。 and I want to add css on only "Complete" cell.
我想在“完成”单元格上添加 css 。
I tried to use this css code but it changes both on my page.我尝试使用此 css 代码,但它在我的页面上都发生了变化。
.order_table_cell[data-title="status"]{color: green;}
Is there anyway to implement that?反正有实现吗?
My full html code:我的完整 html 代码:
<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
<thead>
<tr>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-number"><span class="nobr">الطلب</span></th>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-date"><span class="nobr">التاريخ</span></th>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-status"><span class="nobr">الحالة</span></th>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-total"><span class="nobr">الإجمالي</span></th>
<th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-actions"><span class="nobr">إجراءات</span></th>
</tr>
</thead>
<tbody>
<tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-completed order">
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-number" data-title="الطلب">
<a href="https://tasawwq.com/my-account/view-order/7468/">
#7468 </a>
</td>
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-date" data-title="التاريخ">
<time datetime="2020-12-10T17:09:15+00:00">2020-12-10</time>
</td>
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-status" data-title="الحالة">
مُكتمل
</td>
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-total" data-title="الإجمالي">
<span class="woocommerce-Price-amount amount">3,299.0 <span class="woocommerce-Price-currencySymbol">ج.م</span></span> لـ 3 عناصر
</td>
<td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-actions" data-title="إجراءات">
<a href="https://tasawwq.com/my-account/view-order/7468/" class="woocommerce-button button view">عرض</a> </td>
</tr>
</tbody>
</table>
There isn't CSS selector for text content文本内容没有CSS 选择器
You can't do it with pure CSS你不能用纯 CSS
You can do it if you can change HTML (server or client side)如果您可以更改 HTML (服务器或客户端),您可以这样做
eg with JavaScript like this to change the HTML例如用 JavaScript 像这样改变 HTML
Array.from(document.querySelectorAll('.order_table_cell[data-title="status"]'))
.filter(element => element.textContent === "Complete")
.forEach(element => element.classList.add("completed"))
.completed{color: green;}
you can see in the code when order completed then .woocommerce-orders-table__row--status-completed
class added in <tr>
so you can use this class to change color for order status td
您可以在订单完成时在代码中看到
.woocommerce-orders-table__row--status-completed
class 添加在<tr>
中,因此您可以使用此 class 更改订单状态的颜色td
tr.woocommerce-orders-table__row--status-completed td.woocommerce-orders-table__cell-order-status{
color:green;
}
tr.woocommerce-orders-table__row--status-completed td.woocommerce-orders-table__cell-order-status{ color:green; }
<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table"> <thead> <tr> <th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-number"><span class="nobr">الطلب</span></th> <th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-date"><span class="nobr">التاريخ</span></th> <th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-status"><span class="nobr">الحالة</span></th> <th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-total"><span class="nobr">الإجمالي</span></th> <th class="woocommerce-orders-table__header woocommerce-orders-table__header-order-actions"><span class="nobr">إجراءات</span></th> </tr> </thead> <tbody> <tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-completed order"> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-number" data-title="الطلب"> <a href="https://tasawwq.com/my-account/view-order/7468/"> #7468 </a> </td> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-date" data-title="التاريخ"> <time datetime="2020-12-10T17:09:15+00:00">2020-12-10</time> </td> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-status" data-title="الحالة"> مُكتمل </td> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-total" data-title="الإجمالي"> <span class="woocommerce-Price-amount amount">3,299.0 <span class="woocommerce-Price-currencySymbol">ج.م</span></span> لـ 3 عناصر </td> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-actions" data-title="إجراءات"> <a href="https://tasawwq.com/my-account/view-order/7468/" class="woocommerce-button button view">عرض</a> </td> </tr> <tr class="woocommerce-orders-table__row woocommerce-orders-table__row--status-processing order"> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-number" data-title="الطلب"> <a href="https://tasawwq.com/my-account/view-order/7468/"> #7468 </a> </td> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-date" data-title="التاريخ"> <time datetime="2020-12-10T17:09:15+00:00">2020-12-10</time> </td> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-status" data-title="الحالة"> مُكتمل </td> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-total" data-title="الإجمالي"> <span class="woocommerce-Price-amount amount">3,299.0 <span class="woocommerce-Price-currencySymbol">ج.م</span></span> لـ 3 عناصر </td> <td class="woocommerce-orders-table__cell woocommerce-orders-table__cell-order-actions" data-title="إجراءات"> <a href="https://tasawwq.com/my-account/view-order/7468/" class="woocommerce-button button view">عرض</a> </td> </tr> </tbody> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.