首页 > 解决方案 > 仅当 url 为 https://mywebsite.com/my-account/return 时添加 css

问题描述

CSS我只想在窗口 url 为https://mywebsite.com/my-account/return时加载以下内容

CSS:

<style>.shop table.shop_table.my_account_orders>tbody>tr{
    display: table-row !important;}

.shop table.shop_table.my_account_orders>tbody>tr>td{
    display: table-cell !important;}

.shop table.shop_table.my_account_orders>tbody>tr>td:before{
    display: table-row !important;}</style>

标签: javascriptjquerywindow.location

解决方案


您可以将这些显示规则添加到一个类中,然后根据window.location.

你的 CSS 规则看起来像这样(注意新.mywebsite-com-my-account-return类):

<style>
    .mywebsite-com-my-account-return .shop table.shop_table.my_account_orders>tbody>tr {
        display: table-row !important;
    }

    .mywebsite-com-my-account-return .shop table.shop_table.my_account_orders>tbody>tr>td {
        display: table-cell !important;
    }

    .mywebsite-com-my-account-return .shop table.shop_table.my_account_orders>tbody>tr>td:before {
        display: table-row !important;
    }
</style>

然后您的 Javascript 将如下所示:

<script>
    if (window.location.href === "https://mywebsite.com/my-account/return") {
        document.querySelector("body").classList.add("mywebsite-com-my-account-return")
    }
</script>

推荐阅读