+ 4

What's wrong in my code?

https://sololearn.com/compiler-playground/W3PlK7AOGe5z/?ref=app I want that red background to go in bottom. But despite writing position:sticky; and bottom:0; it's not going at bottom. Why?

4th Jul 2025, 5:30 PM
Manav Roy
Manav Roy - avatar
22 Antworten
+ 5
maybe this? use 100% if you want to occupy the entire width or height . it's more flexible than hardcoding in px. i also used position:fixed for nav. having it scroll out of sight is inconvenient. i intentionally made the body height 200vh so that scrolling could be tested. i put some placeholder divs so that there's something to see. i also modified your logo css so that it's a circle. sticky could work, but it's more difficult to implement so that it doesn't become a distraction when it scrolls up and sticks to the middle of the page. perhaps it's not what you want. if so, maybe add some more details to your example code. https://sololearn.com/compiler-playground/W9RbZJ09T5UE/?ref=app
4th Jul 2025, 11:35 PM
Bob_Li
Bob_Li - avatar
+ 2
Sticky only makes the element stick at bottom when you scroll. But currently your page's other elements aren't big enough to make the page scrollable. Use position: fixed instead.
4th Jul 2025, 5:36 PM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
+ 2
Manav Roy , Afnan Irtesum Chowdhury yes, i can see why it's confusing. since nav have only one direct child (ul) and it's margin is auto, it seems to be overriding the place-item property. you can delete the ul's margin:auto or set it to 0. then it will work as expected . by the way, the values for place-item are start|center|end|stretch|normal|legacy.... https://developer.mozilla.org/en-US/docs/Web/CSS/place-items here is a working example https://sololearn.com/compiler-playground/WRLwU2xAeMIa/?ref=app
5th Jul 2025, 9:43 AM
Bob_Li
Bob_Li - avatar
+ 1
display:grid is another very useful display layout system. display:grid; place-items:center; this combination is an easy way to put items horizontally and vertically centered in divs. Think of it as a 2d display, with rows AND columns of items, while display:flex is a 1d display, being able to display just either row OR column of items, depending on flex-direction. https://www.w3schools.com/css/css_grid.asp
5th Jul 2025, 8:41 AM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li Thanks. Understood now !!
5th Jul 2025, 9:00 AM
Manav Roy
Manav Roy - avatar
+ 1
can you post your code?
5th Jul 2025, 9:22 AM
Bob_Li
Bob_Li - avatar
+ 1
Manav Roy In Bob_Li's code removing the place-items property doesn't bring any change either, neither does using left or right as its value. I don't see any "messed up" layout after removing it.
5th Jul 2025, 9:40 AM
Afnan Irtesum Chowdhury
Afnan Irtesum Chowdhury - avatar
+ 1
pls debug it well not resposive
5th Jul 2025, 10:39 AM
zain duah
zain duah - avatar
+ 1
Bob_Li Hii could you please check my original code no matter what I do the background with bottom class is not going downwards with postion: sticky; EVEN after setting height to 200vh(To make it long enough for sticky; but it's still not working)
5th Jul 2025, 4:11 PM
Manav Roy
Manav Roy - avatar
+ 1
Manav Roy .cont{ height:100%; } sticky will not snap to bottom: 0 it will position itself relative to the elements before it, so it is positioned relative to .cont, but because you did not give it any height, .cont is at minimal height. the bottom class will not touch bottom:0. sticky means it will not go beyond the set point once it reaches it. it sticks. so to make it stick to bottom:0, the divs before .bottom must expand vertically as much as possible. so you need to set .cont height:100% this will push your bottom class to contact bottom:0
5th Jul 2025, 5:16 PM
Bob_Li
Bob_Li - avatar
+ 1
Manav Roy put your link to the icon's stylesheet at the header. this way there's no need to wait for the body to be loaded to get the icons. i modified your code to better make use of the sticky property. here it is to make sure the controls are always accessible when the page is scrolled down while adding an interesting effect when scrolled up. https://sololearn.com/compiler-playground/W4ajfC8nO9Ek/?ref=app
6th Jul 2025, 12:51 AM
Bob_Li
Bob_Li - avatar
+ 1
I wasn't aware there is "sticky" value to position lol
6th Jul 2025, 7:32 AM
RuntimeTerror
RuntimeTerror - avatar
+ 1
Bob_Li Thank you so much 🙏🏿
6th Jul 2025, 11:10 AM
Manav Roy
Manav Roy - avatar
0
Afnan Irtesum Chowdhury Done that..but why width is too less? Even after setting it to width:200px;(Which usually takes up whole document flow). Width:200px; in this case is covering only half of maximum screen width.... And is there any way to make it work by postion:sticky; as I'll be applying many features which may result in bigger page..
4th Jul 2025, 5:45 PM
Manav Roy
Manav Roy - avatar
0
Bob_Li Hi, Thanks for your code. Learnt many things from it. I have few questions (1) What is the difference between place-items center and align-items:center (2) What display:grid is and what it does in this code? Why did you use it at first place?
5th Jul 2025, 8:36 AM
Manav Roy
Manav Roy - avatar
0
Bob_Li display:grid place-items:center Is giving me same output even if i write place-items: right or place-items:left why is that?
5th Jul 2025, 9:20 AM
Manav Roy
Manav Roy - avatar
0
Bob_Li I mean in your code... Inside the nav{} in css file Where you've written "display:grid; place-items:center;" If you write place-items:left; or place-items: right; in this code. It's showing same output. But when you remove the whole place-items and only writer display:grid. It's showing a real messed up code. Why is that?
5th Jul 2025, 9:25 AM
Manav Roy
Manav Roy - avatar
0
Afnan Irtesum Chowdhury It's showing messed up layout when you're writing "align-items:" only without giving it any value.....
5th Jul 2025, 10:04 AM
Manav Roy
Manav Roy - avatar
0
Bob_Li Yeah Thank you it works! Tutorial guy was doing the same like setting min-height to a container. Now i understood why!!
5th Jul 2025, 9:04 PM
Manav Roy
Manav Roy - avatar
0
Bob_Li Thank you so much 🙏🏿
6th Jul 2025, 5:25 AM
Manav Roy
Manav Roy - avatar