Responsive Layout is not working for my Vaadin application.
In the main init() method of the main program, I set “my-responsive-layout” as the style name for the main CSSLayout being used in the application.
@Theme(“mytheme”)
public class HomePage extends UI {
protected void init(VaadinRequest request) {
CssLayout mainCssLayout = new CssLayout();
mainCssLayout.setImmediate(true);
mainCssLayout.setWidth("100%");
mainCssLayout.setHeight("100%");
mainCssLayout.setStyleName("my-responsive-layout");
setContent(mainCssLayout);
setSizeUndefined();
_mainLayout = new VerticalLayout();
_mainLayout.setSpacing(true);
_mainLayout.setStyleName(Reindeer.LAYOUT_BLUE);
new Responsive(mainCssLayout);
_lblTitle = new Label("Home");
_lblTitle.setContentMode(ContentMode.HTML);
HorizontalLayout horizLayoutForTitle = new HorizontalLayout();
horizLayoutForTitle.setPrimaryStyleName("titlepanel");
horizLayoutForTitle.addComponent(_lblTitle);
horizLayoutForTitle.setComponentAlignment(_lblTitle, Alignment.MIDDLE_CENTER);
horizLayoutForTitle.setHeight("30px");
horizLayoutForTitle.setWidth("100%");
Panel panel = new Panel();
panel.setContent(horizLayoutForTitle);
panel.setStyleName(Reindeer.LAYOUT_BLACK);
panel.setPrimaryStyleName("titlepanel");
_mainLayout.addComponent(panel);
btnLogin = new Button("Login");
btnLogin.setDescription("Click this to login and view your notifications.");
btnLogin.setPrimaryStyleName("mybutton");
btnLogin.setWidth(125, Unit.PIXELS);
btnLogin.addClickListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
if (null != validateUser()){
viewNotificationsWindow(loggedInUser);
}
}
});
...........
...........
...........
...........
...........
I defined the responsive-layout in styles.scss for widths ranging from: 0-320, 320-480, 480-600, 600-768, 800-900, 900-1200.
First of all I’m trying to change only the background colors for the titlepanel and mybutton across different widths.
But the background colors are not changing as per the widths.
Given below are the styles used for the title panel and button.
@import “mytheme.scss”;
.mytheme {
@include mytheme;
}
@import “…/reindeer/reindeer.scss”;
.my-responsive-layout[width-range~=“0-320px”]
{
// Styles for 0-320px width
@include base-panel($primaryStyleName: titlepanel);
.titlepanel {
background:steelblue;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 15px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
@include base-button($primaryStyleName: mybutton);
.mybutton {
background: steelblue;
zoom: 1;
display: inline-block;
text-align: center;
text-decoration: none;
cursor: pointer;
white-space: nowrap;
margin: 0;
padding: .2em 1em;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 12px;
font-weight: bold;
}
}
.my-responsive-layout[width-range~=“320-480px”]
{
// Styles for 320-480px width
@include base-panel($primaryStyleName: titlepanel);
.titlepanel {
background:pink;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 15px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
@include base-button($primaryStyleName: mybutton);
.mybutton {
background: blue;
zoom: 1;
display: inline-block;
text-align: center;
text-decoration: none;
cursor: pointer;
white-space: nowrap;
margin: 0;
padding: .2em 1em;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 12px;
font-weight: bold;
}
}
.my-responsive-layout[width-range~=“480-600px”]
{
@include base-panel($primaryStyleName: titlepanel);
.titlepanel {
background:red;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 15px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
@include base-button($primaryStyleName: mybutton);
.mybutton {
background: pink;
zoom: 1;
display: inline-block;
text-align: center;
text-decoration: none;
cursor: pointer;
white-space: nowrap;
margin: 0;
padding: .2em 1em;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 12px;
font-weight: bold;
}
}
.my-responsive-layout[width-range~=“600-768px”]
{
@include base-panel($primaryStyleName: titlepanel);
.titlepanel {
background:yellow;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 15px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
@include base-button($primaryStyleName: mybutton);
.mybutton {
background:red;
zoom: 1;
display: inline-block;
text-align: center;
text-decoration: none;
cursor: pointer;
white-space: nowrap;
margin: 0;
padding: .2em 1em;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 12px;
font-weight: bold;
}
}
.my-responsive-layout[width-range~=“800-900px”]
{
// Styles for 0-900px width
@include base-panel($primaryStyleName: titlepanel);
.titlepanel {
background:green;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 15px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
@include base-button($primaryStyleName: mybutton);
.mybutton {
background:yellow;
zoom: 1;
display: inline-block;
text-align: center;
text-decoration: none;
cursor: pointer;
white-space: nowrap;
margin: 0;
padding: .2em 1em;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 12px;
font-weight: bold;
}
}
.my-responsive-layout[width-range~=“900-1200px”]
{
// Styles for 0-1200px width
@include base-panel($primaryStyleName: titlepanel);
.titlepanel {
background:blue;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 15px;
font-weight: bold;
text-align: center;
text-decoration: none;
}
@include base-button($primaryStyleName: mybutton);
.mybutton {
background:green;
zoom: 1;
display: inline-block;
text-align: center;
text-decoration: none;
cursor: pointer;
white-space: nowrap;
margin: 0;
padding: .2em 1em;
color: #FFFFFF;
font: #FFFFFF;
line-height: normal;
border-radius: 4px;
font-family: arial;
font-size: 12px;
font-weight: bold;
}
}
Will be grateful for any valuable suggestions.