What would be the best way to change the style of a control when the mouse is over ?
I didn't saw this feature with the TWebCSSClass component.
I can do this using TWebCSSClass components, but then I have to use the MouseEnter / MouseLeave events of the control. For example here, I use 2 TWebCSSClass components, and I change the ElementClassName of my control from my-btn-style to my-btn-style-hover using 2 differents TWebCSSClass
procedure TForm1.WebButton1MouseEnter(Sender: TObject);
begin
webbutton1.ElementClassName := 'my-btn-style-hover';
end;
procedure TForm1.WebButton1MouseLeave(Sender: TObject);
begin
webbutton1.ElementClassName := 'my-btn-style';
end;
it works, but then I will have to manage each control's mouse events individually, witch is not convenient if I want to do this for several similar controls.
I suppose there is a better way to manage this.
thanks
Use two
TWebCSSClasscomponents.For the first, use
CSSClassName "my-btn-style". For the second, useCSSClassName "my-btn-style:hover". Just append:hoverto the css class name.Now set the
ElementClassNameof your button or other control to"my-btn-style".CSS properties in the second
TWebCSSClasscomponent will automatically override those in the first component when the mouse is over the button control.The DFM of a sample form:
Properties in the Object inspector: