使用CSS禁用了`div`的内容。

huangapple go评论66阅读模式
英文:

Disabled div content using css

问题

以下是已经翻译好的内容:

<div class="children"> Sachin </div>
<div class="children"> Moron</div>
<div class="children"> Peter </div>

是否可能根据div的特定内容应用颜色,如下所示?

如果div内容为Sachin,则我需要将其禁用,否则将启用。

.children sachin {
    cursor: not-allowed;
    opacity: 0.5;
}
英文:
<div class="children"> Sachin </div>
<div class="children"> Moron</div>
<div class="children"> Peter </div>

is it possible to apply color to div with specfic content like below

If div content is sachin then i need to disabled it, other wise it will enable

.children sachin {
	cursor: not-allowed;
  opacity: 0.5;
  
  }

答案1

得分: 1

你可以使用data attributes来实现这一点。

<!-- 开始片段: js 隐藏: false 控制台: true babel: false -->

<!-- 语言: lang-css -->

.children[data-name="Sachin"] {
opacity: 0.5;
cursor: not-allowed;
}

<!-- 语言: lang-html -->

Sachin
Moron
Peter

<!-- 结束片段 -->

英文:

You can do it if you are able to use data attributes.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.children[data-name=&quot;Sachin&quot;] {
  opacity: 0.5;
  cursor: not-allowed;
}

<!-- language: lang-html -->

&lt;div class=&quot;children&quot; data-name=&quot;Sachin&quot;&gt;Sachin&lt;/div&gt;
&lt;div class=&quot;children&quot; data-name=&quot;Moron&quot;&gt;Moron&lt;/div&gt;
&lt;div class=&quot;children&quot; data-name=&quot;Peter&quot;&gt;Peter&lt;/div&gt;

<!-- end snippet -->

答案2

得分: 1

你可以将 disabled 类添加到要禁用的 div 元素中。

&lt;div class=&quot;children disabled&quot;&gt; Sachin &lt;/div&gt;
&lt;div class=&quot;children&quot;&gt; Moron &lt;/div&gt;
&lt;div class=&quot;children&quot;&gt; Peter &lt;/div&gt;
.children.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

也可以使用 disabled HTML 属性:

&lt;div class=&quot;children&quot; disabled&gt; Sachin &lt;/div&gt;
&lt;div class=&quot;children&quot;&gt; Moron &lt;/div&gt;
&lt;div class=&quot;children&quot;&gt; Peter &lt;/div&gt;
英文:

You can add a disabled class to the divs you want to disable.

&lt;div class=&quot;children disabled&quot;&gt; Sachin &lt;/div&gt;
&lt;div class=&quot;children&quot;&gt; Moron &lt;/div&gt;
&lt;div class=&quot;children&quot;&gt; Peter &lt;/div&gt;
.children.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

Using the disabled html attibute is also possible:

&lt;div class=&quot;children&quot; disabled&gt; Sachin &lt;/div&gt;
&lt;div class=&quot;children&quot;&gt; Moron &lt;/div&gt;
&lt;div class=&quot;children&quot;&gt; Peter &lt;/div&gt;

huangapple
  • 本文由 发表于 2023年3月3日 20:01:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75626803.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定