DRUPAL7 Formapi to add CSS styles to elements

Source: Internet
Author: User

For example, I define a FORM element called the Package library start date,

$form [' Starttime_baoyue ']=array(    ' #type ' = ' TextField ',    ' #title ' =>t (' package libraries start date '),    TRUE,  );

As shown in the code, there are no styles, except for some CSS styles that Drupal adds by default, such as:

So, the actual work, the front-end to a style sheet, there is a fixed style, then how to add to this element?

It's really simple: just add a line of code:

' #attributes ' = =Array(' class ' = =array(' My_class_name ')),

The complete code for the entire element becomes

$form [' Starttime_baoyue ']=array(    ' #type ' = ' TextField ',    ' #title ' =>t (' package libraries start date '),    TRUE,    ' #attributes ' = =Array(' class ' = =array(' My_class ')),   );

Refresh the page and look at the final HTML of the element:

How, the style ' My_class ', has been added bar ~

DRUPAL7 Formapi to add CSS styles to elements

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.