简体   繁体   English

如何 select html 元素在 css 中似乎是另一个元素

[英]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&nbsp;<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&nbsp;<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&nbsp;<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.

相关问题 CSS 根据 HTML 选择选项值选择另一个元素 - CSS to select another Element based on a HTML Select Option Value 如何使用CSS 3自定义“选择”HTML表单元素? - How to customize a “select” HTML form element with CSS 3? 如何使用 HTML 和 CSS 的兄弟组合器 select 一个 div 中的元素来更改另一个 div 的比例? - How to select an element within a div to change the scale of another div using sibling combinators using HTML and CSS? 根据另一个元素设置元素 position(似乎是 JS/CSS 错误) - Setting an element position according to another element (seems JS/CSS bug) 如何用HTML + CSS中的另一个元素选择器更改元素的属性值? - How to change the attribute value of an element with by another element Selector in HTML + CSS? HTML / CSS如何使元素对一个元素透明但对另一个元素覆盖 - HTML/CSS How to make element transparent for one element but overlay another xpath-如何选择html元素,然后再选择另一个(相对)嵌套元素? - xpath - how to select html element then another (relative) nested element? 是否可以使用纯 CSS 选择出现在另一个 HTML 元素之后的任何地方的 HTML 元素? - Is it possible to select HTML elements which appear anywhere after another HTML element using pure CSS? 如何在HTML代码中使用CSS选择Back&Next元素 - How Select Back & Next element with CSS in html Code 如何将css类放入html:jsp中的select元素 - How to put css class in to html:select element in jsp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM