I am building a scrolling frame on a web page.
The frame is width: 90% of the page-width.
I have a total of 7 blocks but I only want to show 5 at a time with a left & right button for scrolling left and right. Each block is width: 18%
What are the minimum css styles I should consider to get starting building this?
What are the minimum css styles I should consider to get starting
building this?
Is this what are you trying to achieve?
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
}
body {
text-align: center;
}
.wrapper {
display: inline-block;
width: 90vw;
height: 100px;
background-color: lightgray;
padding: 16px 0;
overflow-x: scroll;
text-align: start;
}
.content {
display: inline-block;
height: 100%;
width: calc(90vw / 5);
text-align: start;
float: left;
}
.content-wrapper {
height: 100%;
width: calc((90vw / 5) * 7);
text-align: start;
}
.buttons-wrapper {
position: absolute;
width: 90vw;
height: calc(100px - 16px);
}
.left-button,
.right-button {
position: absolute;
background-color: black;
width: 30px;
height: 30px;
top: calc(50% - 15px);
color: white;
text-align: center;
}
.left-button {
left: 0;
}
.right-button {
right: 0;
}
<div class="wrapper">
<div class="buttons-wrapper">
<div class="left-button">L</div>
<div class="right-button">R</div>
</div>
<div class="content-wrapper">
<div class="content" style="background-color: red"></div>
<div class="content" style="background-color: orange"></div>
<div class="content" style="background-color: yellow"></div>
<div class="content" style="background-color: green"></div>
<div class="content" style="background-color: lightblue"></div>
<div class="content" style="background-color: blue"></div>
<div class="content" style="background-color: violet"></div>
</div>
</div>
Related
This question already has answers here:
Why bottom:0 doesn't work with position:sticky?
(2 answers)
If you specify `bottom: 0` for position: sticky, why is it doing something different from the specs?
(3 answers)
Closed 11 months ago.
I can't get #up-arrow to stick to the bottom of .container.
.container {
height: 100vh;
width: 100vh;
background-color: yellow;
}
#up-arrow {
width: 45px;
height: 45px;
border: 2px solid #23ADF8;
border-radius: 23.5px;
background-color: #23ADF8;
position: -webkit-sticky;
position: sticky;
bottom: 0;
}
#up-arrow:hover {
background-color: white;
}
#up-arrow:hover img {
filter: invert(63%) sepia(35%) saturate(5648%) hue-rotate(174deg) brightness(102%) contrast(95%);
}
<div class="container">
<div id="up-arrow">
<a href="#top">
<img src="https://mandoemedia.com/wp-content/uploads/2022/03/up.svg">
</a>
</div>
</div>
The element #up-arrow will not stick to the bottom of the container with the current layout.
Because, sticky element is positioned according to the normal flow of the document, and then offset relative to its nearest scrolling ancestor and containing block (nearest block-level ancestor).
Here the element #up-arrow is at the top of the container, hence the element will not be able to stick to bottom on scroll.
Add some content on top of #up-arrow to see sticky working.
Sample Implementation
.container {
min-height: 100vh;
width: 100vh;
background-color: yellow;
}
#up-arrow {
width: 45px;
height: 45px;
border: 2px solid #23ADF8;
border-radius: 23.5px;
background-color: #23ADF8;
position: -webkit-sticky;
position: sticky;
bottom: 0;
}
#up-arrow:hover {
background-color: white;
}
#up-arrow:hover img {
filter: invert(63%) sepia(35%) saturate(5648%) hue-rotate(174deg) brightness(102%) contrast(95%);
}
#an-element {
height: 100vh;
}
<div class="container">
<div id="an-element"></div>
<div id="up-arrow">
<a href="#top">
<img src="https://mandoemedia.com/wp-content/uploads/2022/03/up.svg">
</a>
</div>
</div>
OR
use position: relative; parent and position: absolute; child
Working Fiddle
.container {
height: 100vh;
width: 100vh;
background-color: yellow;
position: relative;
}
#up-arrow {
width: 45px;
height: 45px;
border: 2px solid #23ADF8;
border-radius: 23.5px;
background-color: #23ADF8;
position: absolute;
bottom: 0;
}
#up-arrow:hover {
background-color: white;
}
#up-arrow:hover img {
filter: invert(63%) sepia(35%) saturate(5648%) hue-rotate(174deg) brightness(102%) contrast(95%);
}
<div class="container">
<div id="up-arrow">
<a href="#top">
<img src="https://mandoemedia.com/wp-content/uploads/2022/03/up.svg">
</a>
</div>
</div>
as you haven't wrote any other content sitcky position may not work fine.
please review below stuff and you might get what you want,
.container {
height: 300vh;
width: 100vh;
background-color: yellow;
}
#up-arrow {
position: -webkit-sticky;
position: sticky;
bottom: 0;
width: 45px;
height: 45px;
border: 2px solid #23ADF8;
border-radius: 23.5px;
background-color: #23ADF8;
}
#up-arrow:hover {
background-color: white;
}
#up-arrow:hover img {
filter: invert(63%) sepia(35%) saturate(5648%) hue-rotate(174deg) brightness(102%) contrast(95%);
}
<div class="container">
<div style="background: red;">Scroll</div>
<div style="height: 300px; background: orange;"></div>
<div class="sticky">Sticky Section</div>
<div style="background: pink;">Scroll</div>
<div style="height: 300px; background: green;"></div>
<div class="sticky">Sticky Section</div>
<div style="background: red;">Scroll</div>
<div style="height: 300px; background: orange;"></div>
<div class="sticky">Sticky Section</div>
<div id="up-arrow">
<a href="#top">
<img src="https://mandoemedia.com/wp-content/uploads/2022/03/up.svg">
</a>
</div>
<div style="background: pink;">Scroll</div>
<div style="height: 300px; background: green;"></div>
<div class="sticky">Sticky Section</div>
</div>
Note: I have made sticky at bottom position and for your understanding how bottom positioned sticky works I've also added some stuff below sticky positioned content.
Whenever content below sticky position renders position of screen will be initial(normal).
References: https://www.w3schools.com/howto/howto_css_sticky_element.asp
Help me adjust my code so that it will be working in Safari. Initially I used answer from here with a few adjustments. I needed my card to be responsive and has some additional elements at the bottom.
Here's my code:
.gallery {
display: grid;
gap: 15px;
grid-template-columns: repeat(2, 1fr);
}
.card {
background-color: #fff;
border-radius: 4px;
box-shadow: 0 0 4px rgba(0, 0, 0, 0.14);
max-width: 200px;
padding: 10px 10px 20px;
cursor: pointer;
position: relative;
}
.wrapper {
width: 100%;
position: relative;
margin-bottom: 20px;
}
.wrapper::before {
content: '';
padding-bottom: 100%;
display: block;
}
.img-grid {
display: grid;
border-radius: 4px;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 3px;
overflow: hidden;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.img-grid > div {
position: relative;
width: 100%;
height: 100%;
}
.img-grid > div:first-child {
grid-column: 1 / span 2;
}
img {
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
}
.logo {
width: 50px;
height: 50px;
background: gainsboro;
float: left;
margin-right: 15px;
}
h4,p {
margin: 3px 0;
}
p {
font-size: 13px;
}
<div class="gallery">
<div class="card">
<div class="wrapper">
<div class="img-grid">
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
</div>
</div>
<div class="logo"></div>
<h4>Logo name</h4>
<p>Some description</p>
</div>
<div class="card">
<div class="wrapper">
<div class="img-grid">
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
<div>
<img loading="lazy" src="https://cdn.pixabay.com/photo/2015/04/19/08/32/marguerite-729510_960_720.jpg"></img>
</div>
</div>
</div>
<div class="logo"></div>
<h4>Logo name</h4>
<p>Some description</p>
</div>
</div>
It works fine in Chrome, but it doesn't work in Safari(current and older). It's because I needed my cards to be responsive and always maintain square grid. So I used same trick on the wrapper that's widely used to maintain responsive squares. But as a result of that height: 100% is no longer working in Safari. Is there any way to make it work? I would appreciate some your help.
.parnet{
max-width: 600px;
margin: 0 auto;
background: #f4f4f5;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.cell {
position: relative;
}
.inner {
width: 80px;
height: 80px;
padding: 40px;
text-align: left;
}
.wrapper .cell:nth-child(2n):before{
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 60%;
width: 1px;
background-color:red;
}
<div class="parnet">
<div class="wrapper">
<div class="cell">
<div class="inner">1</div>
</div>
<div class="cell">
<div class="inner">2</div>
</div>
<div class="cell">
<div class="inner">3</div>
</div>
<div class="cell">
<div class="inner">4</div>
</div>
<div class="cell">
<div class="inner">5</div>
</div>
<div class="cell">
<div class="inner">6</div>
</div>
</div>
</div>
I have a grid that I'm trying to add a :before Pseudo Element to create a divider line between each grid cell. I only want the divider lines to show in the center cells and not the outside left and right.
I'm able to achieve this using border-right and then using nth-child(3n) to remove borders. But having trouble trying to do the same using a Pseudo Element
.parent {
background: white;
max-width: 600px;
margin: 0 auto;
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
.cell {
position: relative;
&:before {
content: "";
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 60%;
width: 1px;
background-color:red;
}
&:nth-child(3n):before {
width: 0;
}
.inner {
max-width: 320px;
width: 320px;
height: 200px;
padding: 57px 43px 40px;
text-align: left;
}
}
}
}
.parnet{
max-width: 600px;
margin: 0 auto;
background: #f4f4f5;
}
.wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.cell {
position: relative;
}
.inner {
width: 80px;
height: 80px;
padding: 40px;
text-align: left;
}
.wrapper .cell:before{
content: "";
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
height: 60%;
width: 1px;
background-color:red;
}
.wrapper .cell:nth-child(3n):before {
width: 0;
}
<div class="parnet">
<div class="wrapper">
<div class="cell">
<div class="inner">1</div>
</div>
<div class="cell">
<div class="inner">2</div>
</div>
<div class="cell">
<div class="inner">3</div>
</div>
<div class="cell">
<div class="inner">4</div>
</div>
<div class="cell">
<div class="inner">5</div>
</div>
<div class="cell">
<div class="inner">6</div>
</div>
</div>
</div>
So the clue was to set right: 0; on the cell instead of left:0;
Then uses
.wrapper .cell:nth-child(3n):before {
width: 0;
}
Thanks Keith i'm going to score your answer for giving me that great clue.
This is my answer. I'm using the .cell:nth-child(3n):before for the horizontal lines. I hope this is what you need.
.parent {
background: white;
max-width: 600px;
margin: 0 auto;
font-size:2em;
}
.parent .wrapper {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.parent .wrapper .cell {
position: relative;
}
.parent .wrapper .cell:before {
content: "";
position: absolute;
right: 50%;
top:.2em;
height: 60%;
width: 1px;
background-color: red;
}
.parent .wrapper .cell:nth-child(3n):before {
width: 300%;
height:1px;
top:100%
}
<div class="parent">
<div class="wrapper">
<div class="cell">1</div>
<div class="cell">2</div>
<div class="cell">3</div>
<div class="cell">4</div>
<div class="cell">5</div>
<div class="cell">6</div>
<div class="cell">7</div>
<div class="cell">8</div>
<div class="cell">9</div>
</div>
</div>
I have a problem, i want to set 3 floated divs and on the bottom I would like to have a footer. So I got these two solutions, but it does not work. Please check out the image:
Here the problem is that the content is not not cleared, so the footer does not change position:
<div class="container">
<div class="left"><div class="content"><div class="right">
<div style="clear:left;"></div>
</div>
<div class="footer"></div>
.container {
height: auto !important;
min-height: 100%;
}
.left {
float: left;
width: 20%;
max-width: 200px;
}
.center {
float: left;
width: 80%;
max-width: 500px;
}
.right {
width: auto;
}
.content {
height: auto !important;
height: 100%;
min-height: 100%;
}
.footer {
height: 202px;
margin: -202px auto 0;
position: relative;
}
If i clear the content, I get the result that the right div goes to the next line:
thanks!
I played around a little bit. I think your html structure wasn't right for the effect you were trying to create.
Here is a new example:
HTML
<div class="container">
<div class="left">
</div>
<div class="center">
</div>
<div class="right">
</div>
<div style="clear">
<div class="content">
</div>
<div class="footer">
</div>
</div>
CSS
.container {
height: auto !important;
min-height: 100%;
}
.left {
float: left;
width: 20%;
max-width: 200px;
min-height: 100px;
background: red;
}
.center {
float: left;
width: 80%;
max-width: 500px;
min-height: 100px;
background: blue;
}
.right {
width: auto;
min-height: 100px;
background: green;
}
.content {
height: auto !important;
height: 100%;
min-height: 100px;
width: 80%;
max-width: 500px;
margin: 0 auto;
background: yellow;
}
.footer {
height: 202px;
margin: 0 auto;
position: relative;
background: purple;
}
I rearanged everything in this fiddle:
http://jsfiddle.net/LJQCx/2/
I hope this is what you trying to achiev.
Here is the code hope it will help check the fiddle
<div class="page-wrap">
<div class="container">
<div class="left">
<p>I am Left</p>
</div>
<div class="center">
<p>I am Center</p>
</div>
<div class="right">
<p>I am Right</p>
</div>
<div class="clear"></div>
</div>
</div>
<div class="footer">
<p>I am Footer</p>
</div>
* { margin: 0;}
html, body { height: 100%;}
.page-wrap {min-height: 100%;/* equal to footer height */margin-bottom: -142px; }
.page-wrap:after { content: ""; display: block;}
.footer, .page-wrap:after { /* .push must be the same height as footer */ height: 142px;}
.site-footer {}
.container{ width:100%;}
.left{ float:left; width:25%;}
.center{float:left; width:50%;}
.right{float:left; width:25%;}
This question already has answers here:
css background color with floating elements
(5 answers)
Closed 6 years ago.
I have an issue with my floated child divs not growing with my parent div. Is there a way to fix this? I need the wrapper to be 100% of the content in either div. Here is the html;
<body>
<div id="wrapper">
<div id="leftpane">
<div id="lefthead">
<div id="leftheadfiller">
</div>
<div id="leftheadlogo">
</div>
<div id="leftheaddivider">
</div>
</div>
<div id="leftcontent">
</div>
</div>
<div id="rightpane">
<div id="righthead">
<div id="rightheadfiller">
</div>
<div id="rightheadlogo">
</div>
<div id="rightheaddivider">
</div>
</div>
<div id="navigation">
Properties Careers About Blog Advertise Contact
</div>
<div id="rightcontent">
</div>
</div>
<div id="close">
</div>
</div>
</body>
And here is the css;
html,body {
background-image:url('images/background.gif');
background-repeat: repeat-y;
background-position: center;
background-attachment: fixed;
height: 100%;
width: 100%;
margin: 0px;
}
#wrapper {
background-color: aqua;
height: 100%;
width: 866px;
margin-left: auto;
margin-right: auto;
}
#leftpane {
background-image: url('images/darkbackground.gif');
width: 326px;
height: 100%;
float: left;
}
#lefthead {
height: 132px;
width: 100%;
}
#leftheadfiller {
height: 75px;
width: 100%;
}
#leftheadlogo {
background-image: url('images/index_07.gif');
width: 71px;
height: 56px;
float: right;
}
#leftheaddivider {
height: 1px;
width: 100%;
background-image: url('images/lightbackground.gif');
float: right;
}
#lefttcontent {
height: 100%;
background-color: fuchsia;
}
#rightpane {
background-image: url('images/lightbackground.gif');
width: 540px;
height: 100%;
float: right;
}
#righthead {
height: 132px;
width: 100%;
}
#rightheadfiller {
height: 75px;
width: 100%;
}
#rightheadlogo {
background-image:url('images/index_09.gif');
width: 109px;
height: 56px;
float: right;
}
#rightheaddivider {
height: 1px;
width: 100%;
background-image: url('images/darkbackground.gif');
float: right;
}
#navigation {
margin-top: 2px;
font-family: Arial, Helvetica, sans-serif;
color: #A3A3A3;
font-size: 14px;
word-spacing: 44px;
text-align: center;
width: 100%;
height: 18px;
}
#rightcontent {
padding-left: 6px;
background-color: fuchsia;
}
#close {
clear: both;
}
Is there a way to fix this? I have this set up on a temporary folder on my local server at:
http://68.113.27.229/test
The two divs that I need to force the wrapper to grow are Leftcontent and Rightcontent.
Thanks!
Add overflow: hidden to the parent div element.
If you don't want the overflowing content to be hidden, then try this:
Insert this as the last div inside the wrapper div.
<div style="clear: both"></div>