0

I have created a custom widget, basically an Image and a text label. What must I do so that I can now set the position of the text ( top/left/bottom of the image for example ) using nothing only CSS? I mean what methods would my class need so that the CSS styling can be applied to it?

ie Can I have a css class like so

.ImageAndLabel 
{
     imagePosition: top;
}

Heres my gwt class

    public class ImageAndLabel extends Composite
    {
        private Label label = new Label();
        private Image img = new Image("/images/pinkBackground.png");
        protected final FlexTable contentTable;

        public ImageAndLabel()
        {
            contentTable = new FlexTable();
            initWidget(contentTable);
            label.getElement().getStyle().setFontSize(40, Unit.PX);
            contentTable.setWidget(0,0,img);
            img.setHeight("200px");
            contentTable.setWidget(0,1,label);
            label.getElement().getStyle().setLeft(0, Unit.PX);
            img.getElement().setId("popupImg");
            label.getElement().setId("popupLabel");
        }

        public void setText(String text)
        {
            label.setText(text);
        }
    }

I guess what I'm after is can I create my own Custom CSS codes?

MayoMan
  • 4,757
  • 10
  • 53
  • 85
  • 1
    u can use setStyleName(style) – swamy Mar 14 '13 at 09:39
  • contentTable.setStyleName()?? – Suresh Atta Mar 14 '13 at 09:49
  • contentTable.setWidget(0, 0, label); contentTable.setWidget(1,1,img); – swamy Mar 14 '13 at 09:56
  • I don't mean how do I associate a style class with this class. I mean can I have a style attribute declared as follows { myOwnAttribute: top; } Is this possible? if So how is the value I put in the attribute applied to my widget? – MayoMan Mar 14 '13 at 10:17
  • I'm not sure it is possible - implement your own css propertys. But may be this will help you http://stackoverflow.com/questions/2926326/can-i-access-the-value-of-invalid-custom-css-properties-from-javascript – A1exandr Belan Mar 14 '13 at 13:55

1 Answers1

1

You can use flextable method for alignment. example :

  flexTable.getFlexCellFormatter().setAlignment(0, 0, 
      HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
Vikash Rajpurohit
  • 1,525
  • 2
  • 13
  • 13
  • Suppose I want to have a CSS rule that has the attribute { position: imageOnTop; OR position: textOnTop; } what would I have to do to my class so that the above css would make sense or can I not create custon CSS tags? – MayoMan Mar 14 '13 at 10:35
  • MayoMan , ImageAndLabel is in flextable , wherever you add your ImageAndLabel it is added inside flextable so you have to apply css to the widget where you are going to add your ImageAndLabel ex: horizontalPanel.add(new ImageandLabel) than apply css to horizomtalPanel – Vikash Rajpurohit Mar 14 '13 at 10:58