开发者

How to target element which have spaces in it's class name css?

开发者 https://www.devze.com 2023-03-13 19:34 出处:网络
I have body tag\'s class like this <body class=\"cms-page-view cms-home\"> This body tag have a div with class col-main something like

I have body tag's class like this

<body class="cms-page-view cms-home">

This body tag have a div with class col-main something like

<div class="col-main">
</div>

I am trying to target this div through css if the body tag have class = cms-page-view cms-home

I tried this

.cms-page-view c开发者_如何学Cms-home .col-main
{
 width:610px;
}

But this does not set width of div to 610px;

How can I target this div only when body tag have class = cms-page-view cms-home ?


The same like the ones with a single space

<body class="cms-page-view cms-home">

the css

 .cms-page-view.cms-home
    {
     width:610px;
    }

a space simply means multiple classes to the same element.

so in this case body has the class "cms-page-view" and "cms-home"


Just use, no need to point both classes.


<style>
.cms-page-view .col-main or (.cms-home .col-main)
{
 width:610px;
 border: 1px solid red;
}

</style>
<body class="cms-page-view cms-home">

<div class="col-main">Test
</div>

</body>
0

精彩评论

暂无评论...
验证码 换一张
取 消