Absolute positioned div inside position:relative overflow:scroll div - html

We have a list of boxes with horizonal scrolling, like this:
ul {
padding: 0;
list-style: none;
display: flex;
justify-content: space-between;
flex-wrap: nowrap;
}
li {
display: inline-block;
flex: 0 0 24%;
max-width: 24%;
margin-right: 1.3%;
margin-top: 3px;
height: 140px;
position: relative;
color: #000000;
white-space: normal;
text-align: left;
}
.container {
white-space: nowrap;
background: #fff;
overflow-y: hidden;
overflow-x: scroll;
width: 100%;
position: relative;
height: 160px;
}
.cover {
content: '';
position: absolute;
right: 0;
top: 0;
width: 20px;
height: 100%;
background-color: #ffffff;
z-index: 999;
}
.box {
border: 1px solid #000;
}
<div class="container">
<div class="cover"> </div>
<ul>
<li class="box empty"></li>
<li class="box gradient"></li>
<li class="box gradient"></li>
<li class="box gradient"></li>
<li class="box gradient"></li>
</ul>
</div>
How to make the "cover" div fixed on the right after the div has scrolled horizontally? At the moment it's stuck at the original position, as you can see from this screenshot:

I have a potential solution but I needed to put the overflow onto the <ul>, move the "cover" after the <ul> and make the container display: flex as well. The "cover" is then just relatively positioned back over the <ul>.
I also added a background-color to show the "cover" better for the demo.
ul {
padding: 0;
list-style: none;
display: flex;
justify-content: space-between;
flex-wrap: nowrap;
position: relative;
width: 100%;
overflow-y: hidden;
overflow-x: scroll;
}
li {
display: inline-block;
flex: 0 0 24%;
max-width: 24%;
margin-right: 1.3%;
margin-top: 3px;
height: 140px;
color: #000000;
white-space: normal;
text-align: left;
}
.container {
white-space: nowrap;
background: #fff;
height: 180px;
background-color: white;
display: flex;
}
.cover {
content: '';
position: relative;
left: -20px;
width: 20px;
height: 150px;
background-color: tomato;
}
.box {
border: 1px solid #000;
}
<div class="container">
<ul>
<li class="box empty"></li>
<li class="box gradient"></li>
<li class="box gradient"></li>
<li class="box gradient"></li>
<li class="box gradient"></li>
</ul>
<div class="cover"></div>
</div>

Related

How to have same space between elements in list?

I'm trying to add the same space between li elements but I dont know how. Can someone point me in the right direction? Thanks in advance
.container {
width: 600px;
height: 500px;
margin:auto;
padding:10 ;
border: 1px solid #ccc;
}
#ul_top {
display: flex;
justify-content:space-around;
list-style-type:none;
}
li:not(:first-child) {
padding-right: 50px;
color:red;
}
.title {
padding-top: 80px;
}
.horizontal-line {
width: 490px;
margin: auto;
padding-left:10px;
border-top: 1px solid #cccccc;
position: relative;
top:-20;
}
<div class="container">
<div class="title"></div>
<div class="horizontal-line"></div>
<ul id ="ul_top">
<li>text1</li>
<li>text2</li>
<li>text3</li>
<li>text4</li>
<li>text5</li>
<li>text6</li>
</ul>
</div>
I want the same space distance between each li element and the last element (text6) to be move to the right a little bit so it lines up with the above horizontal line.
Use display: flex and justify-content: space-between/space-around.
Also, a ul has a default padding, so just override it with padding: 0.
And I removed the padding-right for the :not(:first-child)
You can adjust the width of horizontal-line and the flexbox to be the same, and when you use space between you will have the line and text align together.
.container {
width: 600px;
height: 500px;
margin: auto;
padding: 10;
border: 1px solid #ccc;
}
#ul_top {
display: flex;
justify-content: space-between;
list-style-type: none;
padding: 0;
width: 90%;
margin: 20px auto;
}
li:not(:first-child) {
color: red;
}
.title {
padding-top: 80px;
}
.horizontal-line {
width: 90%;
margin: auto;
padding-left: 10px;
border-top: 1px solid #cccccc;
position: relative;
top: -20;
}
<div class="container">
<div class="title"></div>
<div class="horizontal-line"></div>
<ul id="ul_top">
<li>text1</li>
<li>text2</li>
<li>text3</li>
<li>text4</li>
<li>text5</li>
<li>text6</li>
</ul>
</div>
Try this
.container {
width: 600px;
height: 500px;
margin: auto;
padding: 10;
border: 1px solid #ccc;
}
#ul_top {
display: flex;
justify-content: space-between;
list-style-type: none;
padding: 0;
width: 90%;
margin: 20px auto;
}
li:not(:first-child) {
color: red;
}
.title {
padding-top: 80px;
}
.horizontal-line {
width: 90%;
margin: auto;
border-top: 1px solid #cccccc;
position: relative;
top: -20;
}
<div class="container">
<div class="title"></div>
<div class="horizontal-line"></div>
<ul id="ul_top">
<li>text1</li>
<li>text2</li>
<li>text3</li>
<li>text4</li>
<li>text5</li>
<li>text6</li>
</ul>
</div>

Scrollable dropddown not fully visible

I have a navbar with a scrollable dropdown item(cart view) to the right side of it.
The problem is that if there are more than one item in the cart, the top part of the dropdown it is not visible anymore.
Could you please tell me where is the problem?
This is the html:
<body>
<div id="root">
<div class="App">
<nav>
<div class="links">
Something, something
</div>
<div class="asd">
bla
</div>
<div class="grand-parent">
<div class="bro">
bla
</div>
<div>
</div>
<div class="dropdown">
<div class="dropdown-content">
</div>
</div>
</div>
</nav>
</div>
</div>
</body>
And this is the CSS:
.App {
padding: 0;
margin: 0;
color: #1D1F22;
}
nav {
display: flex;
position: fixed;
justify-content: space-between;
z-index: 9990;
top: 0;
width: 100%;
background-color: white;
font-size: 1.2rem;
margin-left: 70px;
height: 80px;
}
.links {
justify-self: flex-start;
position: relative;
}
.asd {
align-self: center;
position: relative;
}
.grand-parent {
right: 100px;
text-align: center;
position: relative;
height: 90vh;
}
.bro {
position: relative;
padding: 0;
height: 3px;
width: 6px;
margin-right: 170px;
margin-top: 30px;
}
.dropdown {
position: absolute;
display: inline-block;
height: 90vh;
}
.dropdown-content {
margin-top: 0px;
display: flex;
flex-direction: column;
position: absolute;
right: 0;
width: 325px;
z-index: 9999;
border: 1px solid black;
justify-content: center;
align-items: center;
max-height: 90vh;
overflow-y: auto;
background-color: white;
overflow-x: hidden;
}
The project is done in ReactJS, but I think that this is not so important.
Thank you!
You centered vertically your elements in .dropdown-content with justify-content: center;
To fix it, you need to change it to justify-content: flex-start; and normally it'll works.

Flexbox element height 100% going outside of parent?

So because of design reasons I had to use flexbox here and I needed the btn p elements to act like display block, which I managed to through another stack post, but now when I make the "other divs" class 100%, it goes out of the main parent, I cannot figure out why?
#outterWrapper {
display: inline-block;
height: 200px;
border: 1px solid red;
}
#container {
display: flex;
height: 200px;
flex-wrap: wrap;
}
#menu {
display: flex;
flex-basis: 100%;
}
#menu p {
margin: 0;
padding: 8px;
padding-bottom: 0;
}
.otherDivs {
height: 100%;
width: 25%;
background-color: grey;
margin-right: 5px;
}
<div id="outterWrapper">
<div id="container">
<div id="menu">
<p>Btn</p>
<p>Btn</p>
<p>Btn</p>
</div>
<div class="otherDivs"></div>
</div>
</div>
As from the example above the grey box goes outside of the red border?
You can switch to column direction and have something like this :
#outterWrapper {
display: inline-block;
height: 200px;
border: 1px solid red;
}
#container {
display: flex;
height: 200px;
flex-direction:column;
}
#menu {
display: flex;
}
#menu p {
margin: 0;
padding: 8px;
padding-bottom: 0;
}
.otherDivs {
height: 100%;
width: 25%;
background-color: grey;
margin-right: 5px;
}
<div id="outterWrapper">
<div id="container">
<div id="menu">
<p>Btn</p>
<p>Btn</p>
<p>Btn</p>
</div>
<div class="otherDivs"></div>
</div>
</div>

Make list of inline nav items the full height of the container

I am using an inline list as a nav menu, and I would like the hyperlink/list item to take up the full height of the container with the label vertically positioned in the center of the container. Here is what I have:
#top-nav-container {
font-size: 14px;
width: 100%;
height: 50px;
overflow: hidden;
top: 0;
left: 0;
position: fixed;
z-index: 500;
background: #3498db;
}
#top-nav-container .nav-contents {
height: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
#top-nav-container .nav-left {
width: 175px;
}
#top-nav-container .nav-mid {} #top-nav-container .nav-right {
margin-left: auto;
text-align: right;
width: 250px;
}
#top-nav-container .top-nav-logo {
max-height: 35px;
float: left;
}
#top-nav-container ul {
margin: 0 0 0 30px;
padding: 0;
float: left;
list-style: none;
display: flex;
/* Removes whitespace between li elements */
flex-direction: row;
align-items: center;
}
#top-nav-container ul li {} #top-nav-container li a {
text-decoration: none;
background: red;
border-right: 1px solid #fff;
color: #fff;
padding: 0 12px;
}
<header id="top-nav-container">
<div class="container nav-contents">
<div class="nav-left">
<a href="#" title="Home">
<img src="http://coneyislandpark.com/imgUploader/logos/Pepsi_logo_2008.png" alt="Home" class="top-nav-logo" />
</a>
</div>
<div class="nav-mid">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<div class="nav-right">
Stuff here...
</div>
</div>
</header>
Any other suggestions you have with any of this is greatly appreciated.
You need to add both height and line-height to the links, and also make sure they are either display: block or display: inline-block. Note that inline-block would be preferred:
#top-nav-container li a {
height: 50px;
line-height: 50px;
display: inline-block;
}
Note that on small screens, the Stuff Here... div would get cut off due to having a current width of 250px. Simply turn this down to say 50px (or however wide your container would actually be):
#top-nav-container .nav-right {
width: 50px;
}
I've created a fiddle showing this here.
Hope this helps! :)
You need to modify your CSS a little, see the following snippet:
#top-nav-container {
font-size: 14px;
width: 100%;
height: 50px;
overflow: hidden;
top: 0;
left: 0;
position: fixed;
z-index: 500;
background: #3498db;
}
#top-nav-container .nav-contents {
height: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
#top-nav-container .nav-left {
width: 175px;
}
#top-nav-container .nav-mid {
/* all below rules were added*/
position: absolute;
line-height: 50px;
height: 100%;
left: 50%;
transform: translateX(-50%);
}
#top-nav-container .nav-right {
margin-left: auto;
text-align: right;
width: 250px;
}
#top-nav-container .top-nav-logo {
max-height: 35px;
float: left;
}
#top-nav-container ul {
margin: 0 0 0 30px;
padding: 0;
float: left;
list-style: none;
display: flex;
/* Removes whitespace between li elements */
flex-direction: row;
align-items: center;
}
#top-nav-container ul li {} #top-nav-container li a {
text-decoration: none;
background: red;
border-right: 1px solid #fff;
color: #fff;
padding: 0 12px;
/* all below rules were added*/
height: 50px;
line-height: 50px;
display: inline-block;
}
<header id="top-nav-container">
<div class="container nav-contents">
<div class="nav-left">
<a href="#" title="Home">
<img src="http://coneyislandpark.com/imgUploader/logos/Pepsi_logo_2008.png" alt="Home" class="top-nav-logo" />
</a>
</div>
<div class="nav-mid">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<div class="nav-right">
Stuff here...
</div>
</div>
</header>

HTML: Show full content of non-floated element on tree/menu structure

I need to properly skin a menu/tree like structure.
Each item is composed by three elements: two floats (one left and one right) and the last non-floated to fill the remaining space automatically expanding the container when possible.
In the first level all renders properly but on sub-levels the width of container is too small.
NOTE: I need each level ul container will be independently sized based on its content.
HTML example structure:
<ul>
<li>
<div class="link">
<span></span>
<span>3434</span>
<span>Item 1</span>
</div>
<ul>
<li>
<div class="link">
<span></span>
<span>123</span>
<span>Item 1.2</span>
</div>
</li>
<li>
<div class="link">
<span></span>
<span>312</span>
<span>Item 1.2342342</span>
</div>
</li>
<li>
<div class="link">
<span></span>
<span>12</span>
<span>Item 1.2234123</span>
</div>
</li>
</ul>
</li>
<li>
<div class="link">
<span></span>
<span>3453</span>
<span>Item 2123123123123123123</span>
</div>
</li>
<li>
<div class="link">
<span></span>
<span>34534</span>
<span>Item asdasdasd</span>
</div>
</li>
</ul>
CSS:
ul {
position: absolute;
background: white;
border: 1px solid black;
overflow: visible;
margin: 0;
padding: 0;
}
li {
position: relative;
margin: 0;
padding: 0.1em 0.5em;
}
ul>li>ul {
left: 100%;
}
.link {
display;
block;
position: relative;
}
.link>span:nth-child(1) {
display: block;
float: left;
width: 1em;
height: 1em;
margin-right: 0.25em;
background: cyan;
}
.link>span:nth-child(2) {
display: block;
float: right;
height: 1em;
margin-left: 0.25em;
background: red;
color: white;
}
.link>span:nth-child(3) {
display: block;
white-space: nowrap;
overflow: auto;
}
Here a jsfiddle to better show the problem
You can increase the width of the .ul>.li>.ul element:
ul>li>ul {
left: 100%;
width:100%;
}
This will make it increase to be the same width as the top level menu:
https://jsfiddle.net/dxr76e1z/1/
You could render inner <ul> as a table and it will autosize to fit its contents:
ul>li>ul {
left: 100%;
display: table;
}
Finally I have found the solution using flexbox model. This method preserve also jQuery animations.
Only CSS update is needed:
ul {
display: block;
position: absolute;
list-style: none;
background-color: orange;
border: 1px solid red;
padding: 0.2em;
}
li {
display: block;
}
ul>li>ul {
left: 100%;
}
.link {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
align-content: stretch;
margin: 0.2em;
}
.link>span {
display: block;
align-self: auto;
}
.link>:nth-child(1) {
flex-shrink: 0;
width: 1em;
background-color: cyan;
margin-right: 0.25em;
}
.link>:nth-child(2) {
order: 1;
flex-shrink: 0;
background-color: red;
margin-left: 0.25em;
white-space: nowrap;
color: white;
}
.link>:nth-child(3) {
flex-basis: 100%;
flex-shrink: 1;
background-color: yellow;
white-space: nowrap;
}
Here the updated jsfiddle.