Goal
Create a vertical carousel containing square items with up / down navigation across various pages. It should take up it's parent container's height and with it's width set automatically.
Approach
I used a nested grid layout, where the first grid represents a "page", taking up 100% of the parent's container. The second grid is nested in the first grid, taking up the remaining space with an equally divided height. This allows me to achieve most of what I need except that the nested grid width is not following it's children.
Problem
My current approach does not allow the nested grid to respect the children's width as seen in the above image. I need the width to be reflected correctly so that I can center the up / down buttons centrally. Does anyone know why is the grid width not respecting the children? And are there any other solutions for centering the elements aside from doing a margin offset on the 2 buttons?
Sample code
https://codesandbox.io/s/sharp-tdd-2rgb6e?file=/src/App.tsx
Note that this code does not include any translation logic, overflow is disabled so that the pages are visible.
So I am trying to build a kanban like layout (with Vue and Vuetify) that has lists that grow with their content but then stop growing the moment they reach the end of their container (the container would be the remaining size of the screen) and put in an overflow-y inside the column's div.
Here is the reproduction link: https://codesandbox.io/s/dear-god-in-heavens-o55oz
I have tried to make it look as similar to what I have in my own project at the moment.
Here's what you can see in the reproduced link:
The container inside src/components/common/ListsContainer.vue is a flex-grow flex item. I need this because I want this container to automatically take the remaining height of the screen because the wToolbar will have an extension slot that will change its height. I might also introduce new changes to it therefore it would be much more simpler if the container of the columns has a dynamic height.
The columns inside ListsContainer.vue stretch the parent container when the contents are too much, the only way I can control it is by adding a calc(100vh - XXrem) value to the container and the columns to control their height. You can see that I have commented out my calc values inside src/assets/css/custom.css in lines 19 and 24 to demonstarte the overflow of the columns from the screen.
The reason I dont want to use calc is because
calc doesnt react nicely inside an iPad and I have to introduce different calc values just to contain the columns, I have checked that different devices calculate the height differently (I checked in actual iPads since Chrome's simulator works flawlessly which isnt the case in the actual device)
When the wToolbar is extended, the calc doesnt respond and it pushes it down the page, I would like to keep the overflow-y disabled in this page.
So can you guys let me know how I can set my flex-box settings so that everything is contained the way I am trying to?
Difficult to come up with a good title - by all means, change if you can.
Traditionally, a margin on an element can be used to move elements around a page relative to its previous elements. So, if I had a div as a column on my page I could shift elements vertically within that by setting their top-margin CSS property.
This is handy in dynamic pages where some elements might not exist according to given condition, eg, a very simple example here:
https://jsfiddle.net/jhartnoll/4s6pcLu0/1/
I have simply defined a column with a div element, positioned two other div elements and made one of them have a 2em vertical gap between it and its predecessor.
If you remove (or set Display:none) element #one then element #two is shifted up the column and positioned 2em from the top of the column, rather than 2em from element #one which is no longer there.
However, if I try to do a similar thing using a CSS grid, thus making the DOM tree simpler and more flexible, I run into a problem:
https://jsfiddle.net/jhartnoll/xvhycg0k/11/
In this case, the columns are set by the CSS grid so are sort of pseudo columns, but when I set my elements to have margin-top: 2em the margin is calculated from the top of the grid column, not relative to a predecessor element.
Therefore, if element #one is not present, #two simply remains 2em down from the top leaving a gap above...
This behaviour renders margin-top useless, because it is exactly interchangeable with top on relative positioned elements.
Is this a bug with CSS Grid, or am I using it wrong, or is there a way around this?
CSS Grid seems great, but I have run into several problems like this where dynamic content is concerned, if elements have potentially variable heights, or may not be there at all, the Grid leaves other elements floating in space, unable to shift up.
EDIT for clarity of the dynamic problem
Thanks for the comments so far. The problem is not with using the layout, I understand how to set up grids, and rows, define sizes, spaces, span etc, the problem is with dynamic content.
Supposing I have an extremely simple product page:
https://jsfiddle.net/jhartnoll/xvhycg0k/42/
Irrespective of the grid spacing, row/column size etc, the concept is simply that I have thrown in a "Price reduced by 10%" splash element above the product title.
Naturally, product pages would be using templates and therefore the HTML and CSS should be fixed and flexible enough to enable elements to be missing or present.
Not all product pages will display the 10% off deal, so on those pages, I would want the Product Title to shift up into the top element position.
This, as far as I can tell, cannot be achieved with grids.
Similarly, if there was a div which contained a product description and underneath it some product cross promotion or something, the description might be of variable length, so with the div as a column example in the my original question, the content would automatically expand the description grid and shift the cross promotion stuff down the page. Again, this can't be achieved with grids?
So, I was messing around with using a grid defining columns only and simply one row per page so that content could be stacked in columns similarly to the original div as a column example, but then I ran into this margin-top problem which, within a Grid is that margin-top is relative to the grid top, not to the elements above.
So I can't find a way of creating a dynamic website, using a template design which allows for conditional elements and variable element dimensions using Grid and without using Javascript to manipulate on page load.
In my mind, there should be an option for a row-shift property to allow elements to jump down a row if the content is too large, or jump up if there is nothing obstructing it... or something like that anyway!
Hey try the following code I guess it will help your requirement!
#column{display:grid;grid-row-gap: 10px;width:4em;height:auto;border:1px solid grey;}
#one{background:red;width:2em ; height:2em}
#two{background:blue;width:2em ; height:2em}
<div>
<div id="column">
<div id="one">
</div>
<div id="two">
</div>
</div>
</div>
I need to set height of a vertical layout dynamically. My page has a header image of height 100px, a tab of height 26px remaining part is the main content. I have written the following code in App.controller.js. It doesn't works
// tab_layt is the id of vertical layout
var thisView = this.getView().byId("tab_layt");
var height = jQuery(window).height() - (jQuery(".header").height() + jQuery(".tab").height());
thisView.setHeight(height);
it shows the error
"thisView.setHeight is not a function".
sap.ui.layout.VerticalLayout has no property called height.
Layout height will be aligned to the child elements' height automatically.
However, you can overwrite this by using custom CSS classes, but it's not really recommended.
thisView.addStyleClass("nameOfTheCssClass");
Or you can resize the child elements to fill the whole screen - this will resize the layout itself. For example, if you are using a table, you can set the height property of the table instead of the outer layout.
(variable name thisView is not the best if you are referencing to a layout, later it can cause misunderstanding when you are trying to understand your own code)
I have angular app that is using Bootstrap 3 and Angular UI for layout control.
I want to have a particular element fit to the full width of the browser. This element lives inside a bootstrap grid (col-xx), which is itself inside an angular directive, which is placed inside another bootstrap grid, which is inside a Angular UI tab, which is inside another grid. I think you get the idea.
What is the correct CSS to get my element to be the full browser width ? The width of the parent of the element is only a fraction of the screen width, but I need this particular div to override everything because I need maximum real estate (trying to show a gantt chart).
The effect I am trying for is similar to the current google image search feature when you click on a particular image and the bar expand across the full screen.
Apologies if the question is a bit unclear. I may need to add some code.
You'll have to use position: fixed to take it out of the document flow, otherwise using width:100% will always refer to it taking up 100% of the width of it's parent container.
Add the class fullWidth and style like this:
.fullWidth {
position: fixed;
left: 0;
right: 0;
}
Here's a Demo in jsFiddle