Skip to Content Skip to Menu

[SOLVED] Change field color using class

  • dotcom22
  • dotcom22
  • OFFLINE
  • Posts: 522
  • Thanks: 14
  • Karma: 4
9 years 10 months ago - 9 years 10 months ago #255626 by dotcom22
[SOLVED] Change field color using class was created by dotcom22
Cb 2.0 allow now to input our own class inside any field. However I don't see how to do for change edit field appearance with that.

For example I have this field:

Code:
<div id="cbfr_331" class="myclass"> <label id="cblabcb_weblinktitle" class="control-label col-sm-3" for="cb_weblinktitle"></label> <div class="cb_field col-sm-9"> <div id="cbfv_331"> <input id="cb_weblinktitle" class="required form-control" type="text" size="25" name="cb_weblinktitle" aria-required="true"></input> <span class="cbFieldIcons"></span> </div> </div> </div>


The "myclass" is the class value I filled inside CB field. But this class is apply to the full row and not to the field itself. I tried for hours without find how to target field. Of course I can target by input ID or globally all input but is not what I want.

Here a Fiddle:

jsfiddle.net/L2nht9kn/3/

I use Joomla 3.3.6 - CB 2.0.4 - CBSubs 4 - Several Incubator plugins
Last edit: 9 years 10 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • heyai
  • heyai
  • OFFLINE
  • Posts: 324
  • Thanks: 79
  • Karma: 24
9 years 10 months ago #255629 by heyai
Replied by heyai on topic Change field color using class
In my experience you can add your styles to your class (myclass in this case) and define the fields within this class, like "myclass label" or "myclass > label" etc.
I don't speak CSS, but using the firebug plugin for firefox it was possible to see changes immediately and figure it out. We ended up putting the user defined styles at the end of the template's css file (protostar in this case), so they're easy to find.

hey-ai - the community for asian guys and non-asian girls

The search bar is your friend, not just decoration!

Please Log in or Create an account to join the conversation.

  • dotcom22
  • dotcom22
  • OFFLINE
  • Posts: 522
  • Thanks: 14
  • Karma: 4
9 years 10 months ago #255633 by dotcom22
Replied by dotcom22 on topic Change field color using class
yes I use Firebug too but I'm not a css guru and I don't see how to target my input. I tried a bunch of code such
Code:
.myclass > input[type=text] { background-color: red !important; }


OR

Code:
myclass.input[type=text] { background-color: red !important; }

I use Joomla 3.3.6 - CB 2.0.4 - CBSubs 4 - Several Incubator plugins

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48482
  • Thanks: 8283
  • Karma: 1443
9 years 10 months ago #255679 by krileon
Replied by krileon on topic Change field color using class
The class always applies to the row. This gives significantly better control over the styling as you can style the entire field row however you like. Adding to your selector to target the input is relatively easy using some additional selectors. Example as follows.

Code:
.myclass input, .myclass select, .myclass textarea { background-color: red; }

The above usage covers all basic input types. Please do not use important tags. It overrides inline style. Use it only if it's a last resort. Increase your selector weight as needed instead of using important tags if possible.

To explain why your two above examples do not work the first one you're targeting the immediate text input child. Problem is it's not a direct child of .myclass so that won't work. Your second selector doesn't work because first you're missing a period so it's not being considered a class and second the input isn't on the myclass element (selector doesn't make sense in this context).

Also note every field CB outputs is always given a unique ID. You can style elements using the ID. It's not exactly recommended as the selector weight is very high, but it's doable. Using your example you could do the following.

Code:
#cb_weblinktitle { background-color: red; }


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • dotcom22
  • dotcom22
  • OFFLINE
  • Posts: 522
  • Thanks: 14
  • Karma: 4
9 years 10 months ago - 9 years 10 months ago #255693 by dotcom22
Replied by dotcom22 on topic Change field color using class
Sorry in fact I totally missed out this on my console:


Code:
.cb_template select, .cb_template textarea, .cb_template input[type="text"], .cb_template input[type="password"] { margin: 0px; }


I simply added background color and that work but only on input fields. All others fields remain unaffected. However if I use !important all fields become well coloured. This solution is the best for me because I can control globally all CB fields without the use of additional custom class.


Yes targeting by ID is what I made often with 1.9.1 but is annoying especially when is matter to style many same elements such fields.

I use Joomla 3.3.6 - CB 2.0.4 - CBSubs 4 - Several Incubator plugins
Last edit: 9 years 10 months ago by dotcom22.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48482
  • Thanks: 8283
  • Karma: 1443
9 years 10 months ago #255707 by krileon
Replied by krileon on topic Change field color using class

I simply added background color and that work but only on input fields. All others fields remain unaffected. However if I use !important all fields become well coloured. This solution is the best for me because I can control globally all CB fields without the use of additional custom class.

You don't need to use !important. Your selector just needs more weight. Example as follows.

Code:
.cb_template .myclass input, .cb_template .myclass select, .cb_template .myclass textarea { background-color: red; }

The Bootstrap selector that's adding the background is .cb_template .form-control. So the above should have no issues overriding it. If it does have issues you can go as far as the following and should not no problems.

Code:
.cb_template .myclass input.form-control, .cb_template .myclass select.form-control, .cb_template .myclass textarea.form-control { background-color: red; }

Which the above could even be shortened to.

Code:
.cb_template .myclass .form-control { background-color: red; }


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum