Responsive CSS whilst maintaining set widths - css

Amateur with both CSS and vaadin here, trying to implement a responsive UI in Vaadin, but having issues with setting widths of UI objects; everything seems to break responsive CSS. Heres an example of what I'm describing:
CssLayout filterTypeLOptimiseBLayout = new CssLayout();
filterTypeLOptimiseBLayout.setResponsive(true);
filterTypeLOptimiseBLayout.addStyleName("flexwrap");
filterTypeLOptimiseBLayout.setSizeFull();
Label filtTypeLabel = new Label("Filter Type Filler");
filtTypeLabel.addStyleName("filtTypeLabel");
filtTypeLabel.setSizeFull();
filtTypeLabel.setResponsive(true);
filterTypeLOptimiseBLayout.addComponent(filtTypeLabel);
And the corresponding responsive CSS block applied to filtTypeLabel:
/* ---- Filter Type Filler Label ------*/
//Basic inherited CSS
.filtTypeLabel {
padding: 5px;
}
//Mobile
.filtTypeLabel[width-range~="0-300px"] {
font-size: 12pt;
margin: 5px;
}
//Small Browser
.filtTypeLabel[width-range~="301px-600px"] {
font-size: 14pt;
margin: 10px;
}
//Big Browser
.filtTypeLabel[width-range~="601px-"] {
font-size: 16pt;
margin: 20px;
}
With the previous code, I achieve scaling of the button font and margin as expected, but I'd like control over the width of the label as well. Using filtTypeLabel.setSizeFull(); causes anything on the same line as the label to wrap around to the next line as the label occupies all space horizontally. Calling filtTypeLabel.setWidthUndefined(); instead breaks the responsive scaling, and filtTypeLabel.setWidth("5%"); breaks it too. Setting max-width and min-width in the CSS also breaks it.
Is there any way to apply a set width to a Responsive CSS enabled object?

Width-range check works for specific component, not for your window size. So if your component always has the same size, this check will show the same result all the time. You need to create such component, responsive and with width-range styles, which will change its size depending on window size. And all your responsive children must have child styles.
CssLayout filterTypeLOptimiseBLayout = new CssLayout();
filterTypeLOptimiseBLayout.setResponsive(true);
filterTypeLOptimiseBLayout.addStyleName("flexwrap");
filterTypeLOptimiseBLayout.setSizeFull();
filterTypeLOptimiseBLayout.setResponsive(true);
.flexwrap {
.filtTypeLabel {
padding: 5px;
}
}
//Mobile
.flexwrap[width-range~="0-300px"] {
.filtTypeLabel {
font-size: 12pt;
margin: 5px;
}
}
//Small Browser
.flexwrap[width-range~="301px-600px"] {
.filtTypeLabel {
font-size: 14pt;
margin: 10px;
}
}
//Big Browser
.flexwrap[width-range~="601px-"] {
.filtTypeLabel {
font-size: 16pt;
margin: 20px;
}
}

Related

wrong row height for grid pro editor

I use vaadin 14.6.1 and the grid.
I have already made the row heights smaller / denser with the following css via #CssImport:
[part~="cell"] {
font-size: 12px;
min-height: 20px;
padding: 0px;
margin: 0px;
}
:host(.kalkulation-material-grid) [part="row"] {
min-height: 20px;
max-height: 20px;
}
The grid has a headerRow with appendHeaderRow() in which TextFields are to be displayed, which serve as filters for this column. How do I get these text fields smaller / denser. I cannot adjust the rowHeight of the headerRow.
The first line has also a wrong row height, see screenshot.
How can I adjust those row heights ?
From Discord:
This is how the Dense Grid Cookbook example does it:
grid.setThemeName("dense");
:host([theme~="dense"]) [part~="cell"] {
min-height: var(--lumo-size-xxs);
}
:host([theme~="dense"]) {
font-size: var(--lumo-font-size-xs);
}
:host([theme~="dense"]) [part~="cell"] ::slotted(vaadin-grid-cell-content) {
padding: 1px var(--lumo-space-s);
}
:host([theme~="dense"]:not([theme~="no-row-borders"])) [part="row"][first] [part~="cell"]:not([part~="details-cell"]) {
border-top: 0;
min-height: calc(var(--lumo-size-xxs) - var(--_lumo-grid-border-width));
}
There is only regular text content in that example, so the TextFields may need some additional styling.

Using relative sizes with rem units in Sapper

I am using Sapper to create a web app and want to use relative font sizes.
I have set fixed font sizes for different media queries on the body element. Then I want to use rem units for the font-size in subsequent text elements of Svelte components to adjust the font-size to the viewport.
HTML (Svelte component)
<h1>Title</h1>
CSS (of the Svelte component)
h1 {
font-size: 2rem;
}
Global CSS of Sapper
body {
font-size: 12 px;
}
#media (min-width: 600px ) {
body {
font-size: 15px;
}
}
I would expect that the local component CSS is able to read the font-size on the global body element and therefore adjust the font-size in h1 to the viewport size. However, no action is seen. In contrast, using em units works fine.
For Svelte to not remove unused CSS selectors you can use the :global modifier.
To change the font size used by rem values you should style html, not body.
Example (REPL)
<h1>Hello!</h1>
<style>
:global(html) {
font-size: 12px;
}
#media (min-width: 600px) {
:global(html) {
font-size: 15px;
}
}
h1 {
font-size: 2rem;
}
</style>

Place SAPUI5 button icon over text (not left of it)

I need to place the icon of my sap.m.Button on top of the text.
I found this blog post: Button with text UNDER the icon
but unfortunately, this method doesn't seem to work anymore.
Is there a convenient way of placing the icon on top of the text using CSS?
You can achieve it using custom class & CSS
VIEW
<Button class="newBtn" icon="sap-icon://sys-help" text="Default Button" />
CSS
.newBtn .sapMBtnInner {
height: 4rem; /* Increase it to 6rem */
}
.newBtn .sapMBtnText>.sapMBtnIcon {
display: contents;
line-height: 3.8rem; /* Add this line when you are using height as 6rem */
}
.newBtn .sapMBtnInner.sapMBtnText {
padding-left: 0.75rem;
}
.newBtn .sapMBtnIcon {
font-size: 1.7rem; /* Icon size */
}
.newBtn .sapMBtnContent {
line-height: normal;
}

How to make text inside a button scale horizontally to page?

enter image description hereText inside button is extending outside of the button. Is there anyways I can make the text scale based on the button/screen size? I already tried doing auto and searching youtube and google. Also used media query.
I already tried doing auto and searching youtube and google.
#media(min-width: 400px) {
.purplebutton {
min-width: 350px;
}
.buttontext {
font-size: 16px;
}
}
#media(min-width: 600px) {
.purplebutton {
min-width: 450px;
}
.buttontext {
font-size: 17px;
}
}
#media(min-width: 800px) {
.purplebutton {
min-width: 550px;
}
.buttontext {
font-size: 20px;
}
}
Expected result is the text to fit inside the button and size of font adjust according.
Actual result is the text extends outside the button
Instead of using absolute scaling units (px) for font-size use relative scaling font-size such as em, rem or vw.
Try using word-break property to the button like this
word-break: break-all;

Foundation 5: Changing font-sizes and font inheritance for content formatting

I've been looking at the code and documentation but I can't seem to be able to figure this out. Most content tags have a hard-coded font size to 1rem, which makes font size inheritance impossible.
This is the default CSS for Foundation:
https://github.com/zurb/bower-foundation/blob/master/css/foundation.css#L3481
/* Default paragraph styles */
p {
font-family: inherit;
font-weight: normal;
font-size: 1rem;
line-height: 1.6;
margin-bottom: 1.25rem;
text-rendering: optimizeLegibility; }
In an ideal scenario, if you set a container to have a font size of 20px, all content should inherit it and keep working from there - this should include paragraphs, lists, quotes, and the headings should use this as a base size.
This doesn't happen on Foundation, please see the following code snippet on JS Bin.
http://jsbin.com/muqij/1
The only way I've managed to make this work is by re-styling the font sizes to em and changing the container's size.
I would like to believe I'm missing something here.
Normally, you don't want inheritance of the font size because it leads to inconsistency and makes design noisy. Also it can entangle yours styles and markup in one big inflexible mess. Imagine alert box that looks different each time.
But if you really need such behavior you can edit settings with Sass version.
Since Foundation 5 encourages you to reset your styles for everything, I decided to fix this by using a CSS class that resets font-size inheritance.
I wish I didn't have to use this, but it's a good workaround. It resuses the SCSS variables from Foundation and converts all the REMs to EMs. So your fonts should scale accordingly where needed.
This snippet of code has been published as a Gist on GitHub.
https://gist.github.com/neojp/7f6f8e97ba7f0cbf3bd8
// Convert units
// Eg.
// font-size: convert-unit(16rem, em);
// >> font-size: 16em;
//
// font-size: convert-unit(16em, rem);
// >> font-size: 16rem;
//
// font-size: convert-unit(16em, px);
// >> font-size: 16rpx;
#function convert-unit($val, $unit) {
#return strip-units($val) + $unit;
}
// Bring back font-size inheritance for Foundation 5
// Add this class to the content container and change the font-size accordingly
// Eg.
// HTML markup
// <article class="MainContent u-textFormat">
// Font size with REM assuming html has a default font size of 16px
// .MainContent { font-size: 1.25rem; }
// or font size with pixels
// .MainContent { font-size: 20px; }
// Then all <p> tags would have a font-size of 20px;
.u-textFormat {
font-size: 1rem;
h1 {
font-size: convert-unit($h1-font-size, em);
}
h2 {
font-size: convert-unit($h2-font-size, em);
}
h3 {
font-size: convert-unit($h3-font-size, em);
}
h4 {
font-size: convert-unit($h4-font-size, em);
}
h5 {
font-size: convert-unit($h5-font-size, em);
}
h6 {
font-size: convert-unit($h6-font-size, em);
}
p {
font-size: convert-unit($paragraph-font-size, em);
}
ul,
ol,
dl {
font-size: convert-unit($list-font-size, em);
}
blockquote cite {
font-size: convert-unit($blockquote-cite-font-size, em);
}
table caption {
font-size: convert-unit($table-caption-font-size, em);
}
table thead tr th,
table thead tr td {
font-size: convert-unit($table-head-font-size, em);
}
table tfoot tr th,
table tfoot tr td {
font-size: convert-unit($table-foot-font-size, em);
}
table tr th,
table tr td {
font-size: convert-unit($table-row-font-size, em);
}
}

Resources