CSS div height & width not be applied - html

For some reason I am unable to apply height and width to div elements. I am using TailwindCSS and Nextjs.
My goal is to create slides to snap scroll vertically, but the height and width properties are removed in the browser.
Please any suggestions Im desperate.
This is my css for the container and each view within:
.snap-container {
overflow-y: scroll;
width: 100%;
height: 100vh;
display: flex;
flex-flow: column nowrap;
}
.snap-view {
height: 100vh;
width: 100%;
display: flex;
}

if you had
.snap-container {
overflow-y: scroll;
width: 100%;
height: 100vh;
display: flex;
flex-flow: column nowrap;
}
.snap-view {
height: 100vh;
width: 100%;
display: flex;
}
both your styles will be applied, even if on the picture you are showing only the .snap/view
but the height and width properties are removed in the browser.
this is because those are other properties around the code that are above the code you posted and they may have been overwritten by that, by being cascading
if you want the .h-screen and .w-full properties to apply regardless, you can put them direclty into the element, or trying putting them in the CSS below the .snap-container and .snap-view
try that, hoping I have helped

Related

Problems with using flexbox for vertically aligning

I have a page-wide wrapping div that has flexbox alignment to center:
.app_container{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
overflow-y: auto;
overflow-x: hidden;
padding: 10px;
}
In this wrapper, I have a menu that can vary in height as the user expands submenus. The problem is when the menu becomes vertically bigger than the window height. Some parts of the menu gets cut off at the top.
Image: https://imgur.com/a/x00tnoJ
One solution that I found was to simply get overflow: auto on the menu. But that causes the scroll bar to appear on the menu, not on the page wrapper. I want the scroll bar to be on the page wrapper.
Image: https://imgur.com/a/0eZM5Iq
Don't think it is relevant, but I use React.
Here is codepen: https://codepen.io/GuacomoleCyclone/pen/xxEoary
EDIT: I've stumbled upon a solution. I've added this and it solved all problems:
html, body{
display: grid;
}
If I understand correctly what your codepen is showing, the issue seems to be coming from setting the width and height on the html element. You want to change:
html, body {
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
}
to
html, body {
padding: 0px;
margin: 0px;
}
body {
width: 100%;
height: 100%;
}

html body does not capture the entire size of the mobile resolution

I am trying to make flexible my application, I use 100vw width and 100vh height for my components, in the browser on the computer it is displayed perfectly in any resolution. But as soon as I start using it in mobile resolution, the body draws an empty background below, in the picture I have displayed it with a blue background. Tell me what could be the problem here and how can I solve it? Thanks
html, body {
height: 100%;
}
.page {
top: 0;
display: flex;
flex-direction: row;
min-width: 100vw;
min-height: 100vh;
&_content {
flex-direction: column;
width: 100%;
background-color: #ec7373;
min-height: 100vh;
}
}
You may need to use the box-sizing css property on your .page class to define your height and width and override possible padding and margin
like so :
html, body {
height: 100%;
}
.page {
box-sizing : border-box;
top: 0;
display: flex;
flex-direction: row;
min-width: 100vw;
min-height: 100vh;
&_content {
flex-direction: column;
width: 100%;
background-color: #ec7373;
min-height: 100vh;
}
}
You can refer to W3C but please do share the HTML and CSS as we can't really help without being able to reproduce the issue.

Sticky first row and first column with no scroll overflow issues

I've managed to create a sticky first row and first column, but I'm facing several issues.
.App{
display: grid;
overflow: scroll;
}
.grid {
display: flex;
flex-wrap: nowrap;
flex-direction: column;
}
.row{
display: flex;
flex-direction: row;
}
.cell {
width: 150px;
height: 150px;
flex-grow: 0;
flex-shrink: 0;
}
.row-stick-top {
position: sticky;
z-index: 1;
top: 0;
}
.cell-sticky-left {
position: sticky;
left: 0;
}
Here is my codesandbox
ISSUES
Issues are on MOBILE displays. You can use this link to just view the output
1) As you scroll around, you'll notice that the square on the top left is not super sticky, as if its trying to catch up to the scroll. (I've tried this solution to no avail as well)
2) Overscroll...
I've added in all the parents and even the scroll component .App:
overscroll-behavior: none;
I've added overflow: hidden to the html, body, #root (as mentioned here)
I've added -webkit-overflow-scrolling: touch as mentioned here
I've tried body, html { position: fixed; }
My best guess now, is that I will need to put my first row and first column in different divs that don't scroll the same way as the content one does, and add an event listener for scroll...?

Angular: Flexbox Won't Fill Screen

I'd like to understand how Angular interprets my HTML and CSS code. Layouts that I've been using without Angular seem to break down.
Simple Example: I am trying to create a fixed height header div followed by a body div that fills the remaining space.
It works in vanilla HTML/CSS: https://jsfiddle.net/d4Lmbk2q/1/
HTML:
<div id='mainCont'></div>
<div id='bodyCont'></div>
CSS:
html,
body {
height: 100%;
width: 100%;
margin: 0;
}
body {
display: flex;
flex-flow: column;
align-items: stretch;
}
#mainCont {
background-color: blue;
flex: 0 0 1.8cm;
min-width: 970px;
}
#bodyCont {
background-color: green;
flex: 1 1 auto;
}
In Angular, nothing shows up (presumably because Angular inserts the empty app-root component wrapper element between the flex container and the flex items?): https://codesandbox.io/s/beautiful-pike-u7hbl?file=/src/app/app.component.css
Yes, the display:flex applies to the direct children of body element which in this case are not your divs but app-root tag
I fixed mine by adding a display of flex to the Angular element that's the direct child of the parent that was flexed. In your case it's app-root.
Here is what it will look like:
body {
display: flex;
flex-flow: column;
align-items: stretch;
}
app-root {
display: flex;
}

How to stack divs on top of each other? Position absolute isn't working

So I'm using flexbox to create the grid unfortunately, I'm a little stuck as to how to make the divs stack on top of each other. This is what it looks like when I hide overflow:auto and add position relative to the carddiv. I believe the divs are stacking on top but they don't look the right way.
this is what it looks like:
Image Link
https://imgur.com/a/1KsJDh7
What I want it to look like is this:
Except positon:absolute makes everything disappear.
I'm new to css/html so I'm not exactly sure what I'm doing wrong.
https://imgur.com/a/mrLsTdX
App.css
* {
/*overflow:auto*/
}
.App {
/*display: flex;*/
/*flex-wrap: wrap;*/
}
Card.css
.container{
background-color: yellow;
display: flex;
flex-flow: column;
text-align: center;
position: relative;
margin: 10% 10% 10%;
}
.cardDiv {
height: 100vh;
position: absolute;
}
.cardPicture {
background-color: blue;
height: 50vh;
}
.cardDescription {
background-color: green;
height: 50vh;
}
However, without position:absolute it looks like this which is what I want it to look like except it doesn't stack. I assume the first version is stacked which is why it only shows one div?
The code below is for the second image link:
https://imgur.com/a/mrLsTdX
App.css
* {
overflow:auto
}
.App {
/*display: flex;*/
/*flex-wrap: wrap;*/
}
Card.css
.container{
background-color: yellow;
display: flex;
flex-flow: column;
text-align: center;
position: relative;
margin: 10% 10% 10%;
}
.cardDiv {
height: 100vh;
}
.cardPicture {
background-color: blue;
height: 50vh;
}
.cardDescription {
background-color: green;
height: 50vh;
}
The cardDivs are being generated through a map function that is inserting the divs.
The html looks like this:
<div className='container'>
<div className="cardDiv">
<div className="cardPicture"></div>
<div className="cardDescription"></div>
</div>
</div>
Does anyone have any idea on what I could do make the divs stack up without disappearing?
I think the issue is the combination of a flex container and flex items that have been set to absolute positioning. When you set position: absolute on .cardDiv it takes all the cardDiv elements out of the flex flow, and without any width or content, the cardDiv's disappear. As an experiment, take your first CSS block and add a width (say, 50px) to .cardDiv. You should see the cards reappear, stacked and taking up 50 pixels horizontally.
When you set a element to display: flex or display: inline-flex, all the direct children of that element become flex items. You can see all the things that does to the children by default here, and the purpose of the various flex properties are there to manipulate how the children will be displayed along the axis you specify. If you set one of these flex-items to absolute positioning, however, it takes that element out of that flex configuration.
If I understand what you want correctly, I'm not sure you need the container to be flex at all. Try taking the flex properties out of the container, setting the cardDivs to position:absolute and setting width and height to conform to how much of the screen you want filled.
.container {
position: relative;
margin: 1rem;
}
.cardDiv {
position: absolute;
width: 100%;
height: 100vh;
}
.cardPicture {
background-color: blue;
height: 50%;
}
.cardDescription {
background-color: green;
height: 50%;
}
Let me know if this is not what you were looking for-- I figure you can adjust it to how you want the cards to appear. But that's them stacked and split 50-50 between picture and description.