开发者

Applying a style to "everything"

I'm using CSS to style my webpage. I want to apply the following CSS to every element on my form without having to set is individually for开发者_运维百科 each element.

I was hoping there was some kind of wild card character that I could apply here.

Here is the CSS that I am trying to make global:

.noSelect 
    {
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -o-user-select: none;
        user-select: none;
        cursor: default;
        margin:0px;
        padding:0px;
    }


See the universal selector


Yes, use the universal selector

html * { ... }


What kind of tags are you using in your form? You could try starting with this:

.noSelect, input, textarea, select, label
{
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -o-user-select: none;
    user-select: none;
    cursor: default;
    margin:0px;
    padding:0px;
}


You need to change your selector. Instead of .noSelect, you want something like:

#formID *
{
  /* your css */
}

If you're doing it dynamically through jquery or something, just add/remove a class from the root:

#formID.inactive *


How about:

.noSelect * {
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -o-user-select: none;
  user-select: none;
  cursor: default;
  margin:0px;
  padding:0px;
}

With the following form code:

<form class="noSelect">
  <!-- stuff here -->
</form>

Unfortunately the disabled attribute cannot be applied to a form (officially). But perhaps it's better to do something like this

<form>
  <label for="i1">Label 1</label>
  <input type="text" id="i1" disabled>
  <label for="i2">Label 2</label>
  <input type="checkbox" value="1" id="i2" disabled>
  <!-- More inputs and stuff. -->
</form>

If you're using jQuery you can apply the disabled attribute with the following in a <script> block:

// pre jQuery 1.6 (eg 1.5.x, 1.4.x, 1.3.x, ...)
$('form :input').attr('disabled', true);
// jQuery 1.6+
$('form :input').prop('disabled', true);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜