I need help with position.
This is setup code
<div style="background-color: gray; width: 100%; height: 100vh; display: flex; justify-content: center; ">
<div style="display: flex; flex-direction: column; background-color: rgb(248, 83, 83); width: 300px; position: sticky; bottom:0; ">
<div style="width: 100%; border: 1px solid black; ">Something</div>
And this is code where is problem
<ul >
<div *ngFor="let x of elementList" >
<li style="border: 1px solid black; position: relative; height: 500px; overflow-y: scroll;"> <span>{{x.Title}}</span>
<ul>
<div style="background: pink; position: absolute; right: -50px; top: 0;">
<li >{{x.Subtitle}}</li>
<li >{{x.Subtitle}}</li>
<li >{{x.Subtitle}}</li>
<li >{{x.Subtitle}}</li>
</div>
</ul>
</li>
</div>
</ul>
</div>
<div style="border: 1px solid black; width: 100%; display: flex; gap: 10px; padding: 5px;">
<span class="material-icons-outlined">
arrow_back
</span> <span>Hide navigation</span>
</div>
</div>
<div style="background-color: rgb(152, 247, 152); width: 100%; height: 100%;"></div>
</div>
I working on this for past 5h so can you help me?
This is full code
enter image description here
What I want is set list outside of contaner next to scroll
HTML;
<div id="container">
<div id="middle">
<div id="inner">Something</div>
</div>
<div>
<ul>
<li>List item one</li>
<li>List item two</li>
</ul>
</div>
</div>
To force a container to have a scrollbar, the inner content needs to have a width greater than it's container. Therefore I set the inner div's width to 120% and then put overflow: scroll on the middle div.
Styling;
body {
margin: 0;
}
#container {
background-color: gray;
width: 100%;
height: 100vh;
display: flex;
}
#middle {
display: flex;
flex-direction: column;
background-color: rgb(248, 83, 83);
width: 300px;
position: sticky;
bottom:0;
overflow: scroll;
}
#inner {
width: 120%;
border: 1px solid black;
}
Demo
Related
I'm trying to use sticky to have the div "Sticky" stick to the top of the screen, while allowing for transparency in the background, so they can't just overlap each other. I've seen some videos and tutorials on people getting it to work. but I can't seem to figure it out.
I've read that positions other than relative breaks it. but I don't believe thats used here.
I can't nest it, like i've seen in other posts, as i can't change the html. this is purely css for me.
This would be a good addition to my little project, but even being told its not possible with this html would save me hours of banging my head.
edit: I would like the previous 'Sticky' to move up and/or go away when the next 'Sticky' Appears.
body{
padding: 0;
margin: 0;
}
.Container {
max-width: 200px;
margin: 0 auto;
overflow: hidden scroll;
height: 200px;
}
.Wrapper {
padding: 0;
position: relative;
}
.List {
margin: 0;
padding: 0;
position: relative;
background: black;
}
.Sticky {
height: 20px;
position: sticky;
top: 0;
background: rgba(200,70,70,.8);
}
.Message {
color: white;
height: 20px;
display: block;
text-align: center;
}
.info {
background: green;
color: white;
height: 50px;
display: block;
text-align: center;
}
.spacer {
background: blue;
color: white;
height: 100px;
display: block;
text-align: center;
}
<div class="Container">
<div class="Wrapper">
<ol class="List">
<li class="info">Info</li>
<div class="Sticky">
<span class="Message">Sticky Box</span>
</div>
<li class="info">Info</li>
<li class="info">Info</li>
<li class="info">Info</li>
<div class="Sticky">
<span class="Message">Sticky Box</span>
</div>
<li class="info">Info</li>
<li class="info">Info</li>
<li class="info">Info</li>
<div class="Sticky">
<span class="Message">Sticky Box</span>
</div>
<li class="info">Info</li>
<li class="info">Info</li>
<div class="spacer">Spacer<\div>
</ol>
</div>
</div>
body{
padding: 0;
margin: 0;
}
.Container {
max-width: 200px;
margin: 0 auto;
overflow: hidden scroll;
height: 200px;
}
.Wrapper {
padding: 0;
position: relative;
}
.List {
margin: 0;
padding: 0;
position: relative;
background: black;
}
.Sticky {
height: 20px;
position: sticky;
background: rgba(200,70,70,.8);
}
.Stick1{top: 0;}
.Stick2{top: 20px;}
.Stick3{top: 40px;}
.Message {
color: white;
height: 20px;
display: block;
text-align: center;
}
.info {
background: green;
color: white;
height: 50px;
display: block;
text-align: center;
}
.spacer {
background: blue;
color: white;
height: 100px;
display: block;
text-align: center;
}
<div class="Container">
<div class="Wrapper">
<ol class="List">
<li class="info">Info</li>
<div class="Sticky Stick1">
<span class="Message">Sticky Box</span>
</div>
<li class="info">Info</li>
<li class="info">Info</li>
<li class="info">Info</li>
<div class="Sticky Stick2">
<span class="Message">Sticky Box</span>
</div>
<li class="info">Info</li>
<li class="info">Info</li>
<li class="info">Info</li>
<div class="Sticky Stick3">
<span class="Message">Sticky Box</span>
</div>
<li class="info">Info</li>
<li class="info">Info</li>
<div class="spacer">Spacer<\div>
</ol>
</div>
</div>
Want to create a slider containing 3 image containers and need all of them in the same row. All image containers are same size, but the size of slider is around 2.5 images, so the third one should overflow instead of going to new row. Example:
How it should look
What i have for now
html
<div class="image-slide-wrapper">
<div class="images-section">
<div class="image-slide">
<div class="slide-img">
</div>
</div>
<div class="image-slide">
<div class="slide-img">
</div>
</div>
<div class="image-slide">
<div class="slide-img">
</div>
</div>
</div>
</div>
scss
.image-slide-wrapper {
float: left;
height: 55%;
width: 100%;
.images-section {
float: left;
height: 85%;
width: 100%;
border: 1px solid grey;
border-radius: 8px;
overflow: hidden;
padding: 0.125rem;
}
.image-slide {
float: left;
height: 100%;
width: 100px;
margin-right: 0.25rem;
.slide-img {
float: left;
height: 100%;
width: 100%;
border-radius: 0.35rem;
background-color: #e9e9e9;
in the text slider is images-section class and image container is image-slide class. Forgot to mention that I have to go with float to make consistent with the rest of the code.
<div style="overflow: hidden; width: 250px;">
<div style="width: max-content">
<img style="width: 100px;height: 100px;border: 1px solid black;" src="...">
<img style="width: 100px;height: 100px;border: 1px solid black;" src="...">
<img style="width: 100px;height: 100px;border: 1px solid black;" src="...">
</div>
</div>
You could remove float from the thumb elements and use display: flex and flex-flow: row nowrap on the container
.container {
height: 100px;
width: 250px;
border: 1px solid grey;
border-radius: 8px;
overflow: hidden;
padding: 0.125rem;
display: flex;
flex-flow: row nowrap;
}
.image-slide {
height: calc(100% - .25rem);
flex: 1 0 100px;
margin-right: 0.25rem;
border: 1px #ccc solid;
}
<div class="container">
<div class="image-slide"></div>
<div class="image-slide"></div>
<div class="image-slide"></div>
<div class="image-slide"></div>
</div>
This works. You can add display:flex; and flex-wrap:nowrap; to .image-slide-wrapper class.
.main {
float: left;
height: 85%;
width: 100%;
border: 1px solid grey;
border-radius: 8px;
overflow: hidden;
padding: 0.125rem;
display:flex;
flex-wrap:nowrap;
}
.slider {
float: left;
height: 100%;
width: 300px;
margin-right: 0.25rem;
display: block;
}
<div class="main">
<div class="slider">
<img class="img" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTBYCs940TLL3tx_nyn7fVeidXWZyfOKV5QrQ&usqp=CAU">
</div>
<div class="slider">
<img class="img" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTBYCs940TLL3tx_nyn7fVeidXWZyfOKV5QrQ&usqp=CAU">
</div>
<div class="slider">
<img class="img" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTBYCs940TLL3tx_nyn7fVeidXWZyfOKV5QrQ&usqp=CAU">
</div>
</div>
I am using flex to display pictures. For wide screen all works well but as for for smaller media sizes I would like to see div with the class "base" apper under pictures even when they are displayed in a second an third row. How could I implement this?
Take a look at it on Codepen
<div class="container">
<div class="bookshelf">
<div class="bookshelf-background">
<div class="base"></div>
</div>
<div class="bookshelf-images">
<ul class="container">
<li class="flex flex1">
<a href="#" class="img">
<div style="width: 250px">
<img src="https://image.shutterstock.com/image-illustration/amazing-word-pop-art-retro-
600w-1112517635.jpg" style="width: 150px;">
</div>
</a>
</li>
<li class="flex flex1">
<a href="#" class="img">
<div style="width: 250px">
<img src="https://image.shutterstock.com/image-illustration/amazing-word-pop-art-retro-
600w-1112517635.jpg" style="width: 150px;">
</div>
</a>
</li>
</ul>
</div>
</div>
</div>`
Can you please check with this code, hope it will resolve your query. First, we remove static "base" class div and add background in separate list item using pseudo-element.
.flex {
margin-bottom: 50px;
color: white;
font-size: 20px;
text-align: center;
position: relative;
}
.bookshelf-images .flex {
position: relative;
padding-bottom: 14px;
}
.bookshelf-images .flex:before {
content: "";
width: 100%;
height: 45px;
border-bottom: 9px solid fuchsia;
position: absolute;
left: 0;
bottom: 0;
background: #35091b;
}
.bookshelf-images .flex a{
position: relative;
}
.container {
max-width: 800px;
background: none;
margin-bottom: 0px;
text-align: center;
display: flex;
flex-wrap: wrap;
margin-top: -3px;
}
.container .bookshelf {
display: flex;
position: relative;
}
.container .bookshelf-images {
height: 100%;
}
.container .bookshelf-image {
height: 100%;
position: relative;
max-width: 100%;
display: flex;
}
li {
list-style-type: none;
}
ul {
margin-left: 0;
padding-left: 0;
}
.container .bookshelf-background {
position: absolute;
border: 0px solid #ff0000;
left: 0;
bottom: 45px;
width: 100%;
height: 42px;
}
.container .bookshelf-background .base {
width: 100%;
height: 100%;
border: 0px solid #fff000;
box-shadow: 0px 9px 1px fuchsia;
position: absolute;
background: #35091b;
}
<div class="container">
<div class="bookshelf">
<!-- <div class="bookshelf-background">
<div class="base"></div>
</div> -->
<div class="bookshelf-images">
<ul class="container">
<li class="flex flex1">
<a href="#" class="img">
<div style="width: 250px">
<img
src="https://image.shutterstock.com/image-illustration/amazing-word-pop-art-retro-600w-1112517635.jpg"
style="width: 150px;"
/>
</div>
</a>
</li>
<li class="flex flex1">
<a href="#" class="img">
<div style="width: 250px">
<img
src="https://image.shutterstock.com/image-illustration/amazing-word-pop-art-retro-600w-1112517635.jpg"
style="width: 150px;"
/>
</div>
</a>
</li>
<li class="flex flex1">
<a href="#" class="img">
<div style="width: 250px">
<img
src="https://image.shutterstock.com/image-illustration/amazing-word-pop-art-retro-600w-1112517635.jpg"
style="width: 150px;"
/>
</div>
</a>
</li>
</ul>
</div>
</div>
</div>
I have an absolute slider div including images and some arrows, When I add another div, I expect it appear after last div (that is absolute), but it places behind absolute div, I know it's because absolute position is beyond box flow, and I just want to know how to put new div after last absolute div, widout giving margin-top?
HTML code:
<div id="next">
<i class="fa fa-5x fa-angle-right" aria-hidden="true"></i>
</div>
<div id="slider">
<div class="slide">
<img src="images/1.jpg" alt="">
</div>
<div class="slide">
<img src="images/2.jpg" alt="">
</div>
<div class="slide">
<img src="images/3.jpg" alt="">
</div>
</div>
<div id="prev">
<i class="fa fa-5x fa-angle-left" aria-hidden="true"></i>
</div>
<div id="advertises">
</div>
Css code:
#slider{
position: relative;
margin-top: -17px;
}
.slide{
position: absolute;
width: 100%;
height: 400px;
}
.slide img{
width: 100%;
height: 400px;
}
#next, #prev{
width: 70px;
margin-top: 150px;
cursor: pointer;
position: relative;
z-index: 100;
background-color: rgba(255, 255, 255, .5);
display: flex;
justify-content: center;
border-radius: 50%;
}
#next{
margin-right: 25px;
float: right;
}
#prev{
margin-left: 25px;
float: left;
}
#advertises{
width: 50%;
height: 300px;
border: 1px solid #101010;
display: flex;
}
Jsfiddle
When you use absolute positioning you lose the ability to relate that to other elements. That is, you can place a element relatively to other when the other is absolute.
You should try to look for another solution that fits your intention. I don't see the reason to not use a "normal" positioning.
One way is to wrap the slider, then add overflow:auto and height:400px
.wrapper {
overflow: auto;
height: 400px;
}
#slider {
position: relative;
margin-top: -17px;
}
.slide {
position: absolute;
width: 100%;
height: 400px;
}
.slide img {
width: 100%;
height: 400px;
}
#next,
#prev {
width: 70px;
margin-top: 150px;
cursor: pointer;
position: relative;
z-index: 100;
background-color: rgba(255, 255, 255, .5);
display: flex;
justify-content: center;
border-radius: 50%;
}
#next {
margin-right: 25px;
float: right;
}
#prev {
margin-left: 25px;
float: left;
}
#advertises {
clear: both;
width: 50%;
height: 300px;
border: 1px solid #101010;
display: flex;
}
<div class="wrapper">
<div id="next">
<i class="fa fa-5x fa-angle-right" aria-hidden="true"></i>
</div>
<div id="slider">
<div class="slide">
<img src="images/1.jpg" alt="">
</div>
<div class="slide">
<img src="images/2.jpg" alt="">
</div>
<div class="slide">
<img src="images/3.jpg" alt="">
</div>
</div>
<div id="prev">
<i class="fa fa-5x fa-angle-left" aria-hidden="true"></i>
</div>
</div>
<div id="advertises">
</div>
I have folowing code:
html:
<div class="container">
<div class="content">
<ul>
<li class="item">a</li>
<li class="item">bb</li>
<li class="item">ccc</li>
<li class="item">dddd</li>
<li class="item">eeeee</li>
</ul>
</div>
</div>
css:
.container{
width: 200px;
background-color: red;
overflow: hidden;
}
.content ul{
padding: 0px;
margin: 0px;
}
.item{
padding: 1px 10px 1px 10px;
background-color: green;
border: 1px black solid;
margin: 1px;
display: inline-block;
}
http://jsfiddle.net/VSfHS/183/
And i need to display items in one row with scrollable overflow.
Number of items is dynamic, so I can't preset width of content.
Here you go.
http://jsfiddle.net/VSfHS/184/
The solution is white-space: nowrap