Sliding Cards Spacing Issue - html

I have made some cards and restricted them from wrapping, thus making
a card-wrapper which becomes container for Horizontal Scrollable
Cards.
I am Facing small issue. The Last Card does not get any spacing at
the end..
See below screenshot
html,
body {
width: 100%;
height: 100%;
}
body {
background-color:#f4f4f4;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
}
.card {
display: flex;
background-color: #fff;
min-width: 100%;
min-height: 200px;
margin: 1rem;
overflow-x: auto;
}
.card--content {
background-color: #DED3EE;
min-width: 200px;
margin: 5px;
}
<section class="card">
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
</section>
Codepen Link : Click
Any help?

I think you are looking for this solution. You should calculate .card-track width dynamicaly
This method use when creating image slider
html,
body {
width: 100%;
background-color:#f4f4f4;
display: flex;
justify-content: center;
align-items: center;
}
.card {
background-color: red;
width: 80%;
position: relative;
display: block;
overflow: hidden;
margin: 0;
padding: 0;
overflow-x: scroll;
}
.card-track {
position: relative;
top: 0;
left: 0;
display: block;
margin-left: auto;
margin-right: auto;
width: calc(200px*10 + 10px*10); /*Card content width x no of iems + margins */
}
.card--content {
background-color: #DED3EE;
width: 200px;
height: 120px;
margin: 5px;
float: left;
}
<section class="card">
<div class="card-track">
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
<div class="card--content"></div>
</div>
</section>

All you need to do is switch your card spacing from margin to padding and add an inner container to each card.
Overflowing margin doesn't push the items within the parent container, rather it pushes the siblings outside. Since you have overflow hidden (by auto/scroll), it is effectively rendered margin-right: 0;
A relatively easy fix is to use padding instead. But you'll have to create an inner container so that you can use padding on the contents and so that the background-color is contained within the spacing.
You can see a working example here: https://codepen.io/rjhewitt3/pen/MqYjeg

Related

Items inside of container won't stay inside parent despite child having overflow set to "auto"

I'm in a bit of a pickle. Been searching and testing this out for a while but can't seem to get it it work.
Here's what I've got so far:
* {
box-sizing: border-box;
}
html, body {
margin: 0;
height: 100%;
font-family: Arial, sans-serif;
}
.container {
position: fixed;
top: 0;
right: 0;
height: 100%;
width: 30%;
background-color: #f9f9f9;
padding: 20px 30px;
}
.box-container {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
height: 100%;
overflow-y: auto;
}
.box {
display: flex;
justify-content: center;
align-items: center;
height: 150px;
width: 49%;
background-color: #FFDAC7;
margin-bottom: 5px;
font-size: 32px;
}
<div class="container">
<h2>lorem ipsum dolor sit amet</h2>
<h3>Some other stuff</h3>
<div class="box-container">
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
<div class="box">4</div>
<div class="box">5</div>
<div class="box">6</div>
<div class="box">7</div>
<div class="box">8</div>
<div class="box">9</div>
<div class="box">10</div>
</div>
<h5>Maybe a button here</h5>
</div>
Now, I would expect the "box-container" div to only occupy 100% of the available space and having the children be scrollable but that doesn't seem to be the case.
Seems like I'm missing something obvious.
Here's a pen for those who prefer that, btw: https://codepen.io/georgiosApo/pen/gORxJwb
Thanks a bunch in advance for any pointers!
// G
Change you css like this:
.container {
height: 100vh;
width: 100%;
background-color: #f9f9f9;
padding: 20px 30px;
}
Working example

Bottom of flex item is cut off when stacked in column

(Edit) Please view the codepen here.
I am making a card stack with Vue.js and flex box to display various apps on my website. I use a component for each card and use Vues' for function to render cards with the following template html:
<div class="card">
<img src="">
<h1>Title</h1>
<a>Click</a>
</div>
This component is called "app-card". I render the cards within the following HTML:
<div id="app">
<div class="row">
<div id="card-container">
<app-card> <!--Above HTML from template goes here--> </app-card>
</div>
<div id="main"></div>
</div>
</div>
I use the following SASS (CSS without the { } in this case) for my card deck:
*
margin: 0
padding: 0
font-family: 'Montserrat', sans-serif !important
box-sizing: border-box
.row
display: flex
flex-wrap: wrap
justify-content: space-evenly
align-items: auto
#card-container
flex: 10%
#main
flex: 90%
.card
width: 100%
margin-top: 0;
margin-bottom: auto;
.card img
width: 100%
max-width: 100%
.card a
padding: 10px
background: blue
However the top of the next card in the deck cuts of the bottom of the button of the above card as shown in this image:
How would I go about fixing this? I've just started learning flex-box after having used Bootstrap-4 for years.
You can fix this by adding margin-bottom property in card class.
* {
margin: 0;
padding: 0;
font-family: "Montserrat", sans-serif !important;
box-sizing: border-box;
}
.row {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: auto;
}
#card-container {
flex: 10%;
}
#main {
flex: 90%;
}
.card {
width: 100%;
margin-bottom: 50px; /* Add Margin Bottom */
}
/* For last card no margin bottom */
.card:last-child{
margin-bottom:0;
}
.card img {
width: 100%;
max-width: 100%;
}
.card a {
padding: 10px;
background: blue;
}
<div class="row">
<div id="card-container">
<div class="card">
<img src="https://img.itch.zone/aW1nLzQyNTE2MjcucG5n/315x250%23c/NpEkhf.png">
<h1>Title</h1>
<a>Click</a>
</div>
<div class="card">
<img src="https://img.itch.zone/aW1nLzQyNTE2MjcucG5n/315x250%23c/NpEkhf.png">
<h1>Title</h1>
<a>Click</a>
</div>
<div class="card">
<img src="https://img.itch.zone/aW1nLzQyNTE2MjcucG5n/315x250%23c/NpEkhf.png">
<h1>Title</h1>
<a>Click</a>
</div>
</div>
<div id="main">
</div>
</div>
.card a {
padding: 10px;
background: blue;
display:block;
}

Why do my divs go out of position whenever they get any content? [duplicate]

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 1 year ago.
I'm trying to have my divs in a tic tac toe sort of way, where it’s just a 3 by 3 grid, and it works fine, just until I type in a letter or something inside the div. Anyone know why and how to fix it?
body,
html {
min-width: 100%;
min-height: 100%;
margin: 0;
padding: 0;
font: Arial 14px;
}
#blocks {
background-color: red;
width: 50px;
height: 50px;
display: inline-block;
margin-right: 6px;
}
#canvas {
margin-left: 40%;
}
<div id="canvas">
<div id="blocks"></div>
<div id="blocks"></div>
<div id="blocks"></div><br>
<div id="blocks"></div>
<div id="blocks"></div>
<div id="blocks"></div><br>
<div id="blocks"></div>
<div id="blocks"></div>
<div id="blocks"></div>
</div>
Apply margin-bottom to the divs.
body,
html {
min-width: 100%;
min-height: 100%;
margin: 0;
padding: 0;
font: Arial 14px;
}
#blocks {
background-color: red;
width: 50px;
height: 50px;
display: inline-block;
margin-right: 6px;
margin-bottom:6px;
}
#canvas {
margin-left: 40%;
}
<div id="canvas">
<div id="blocks">x</div>
<div id="blocks">x</div>
<div id="blocks">x</div><br>
<div id="blocks">o</div>
<div id="blocks">o</div>
<div id="blocks">o</div><br>
<div id="blocks">x</div>
<div id="blocks">o</div>
<div id="blocks">x</div>
</div>
You should probably use grid or flexbox. Something like this:
body,
html {
min-width: 100%;
min-height: 100%;
margin: 0;
padding: 0;
font: Arial 14px;
}
.blocks {
background-color: red;
/* Center content within each cell */
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: center;
}
#canvas {
max-width: 200px;
margin: 1rem auto;
/* Achieve layout using grid */
display: grid;
grid-template-columns: repeat(3, 50px);
grid-template-rows: repeat(3, 50px);
gap: 1rem;
}
<div id="canvas">
<div class="blocks"><span>1</span></div>
<div class="blocks"><span>2</span></div>
<div class="blocks"><span>3</span></div>
<div class="blocks"><span>4</span></div>
<div class="blocks"><span>5</span></div>
<div class="blocks"><span>6</span></div>
<div class="blocks"><span>7</span></div>
<div class="blocks"><span>8</span></div>
<div class="blocks"><span>9</span></div>
</div>
I changed the blocks ids to classes. Also added some styles of my own to center the content inside each grid cell (added span tags within each cell div for that).
try that:
body {
font : Arial 14px;
}
#canvas {
--sz_blk : 50px;
--in_blk : 6px;
width : calc((var(--sz_blk) * 3) + (var(--in_blk) * 6));
margin : auto;
}
#canvas > div {
background-color : red;
width : var(--sz_blk);
height : var(--sz_blk);
margin : var(--in_blk);
display : block;
float : left;
text-align : center;
line-height : calc(var(--sz_blk) / 5 * 4)
}
<div id="canvas">
<div>x</div>
<div>x</div>
<div>x</div>
<div>o</div>
<div>o</div>
<div>o</div>
<div>x</div>
<div>o</div>
<div>x</div>
</div>

CSS Horizontal scroll container with an overlay that overflow's vertically

I'm trying to make a horizontally scrolling container that holds a bunch of tabs. I want to make an overlay (think an options menu) that can appear over a tab. And what I would like is for the overlay to sit over the top of the horizontal scrollbar. Here is an image with what I mean:
But here is what I actually get:
I've recreated my problem with a small example below:
.page {
display: flex;
flex-direction: column;
max-width: 800px;
margin: 0 auto;
}
.header {
height: 30px;
background: #ccc;
display: flex;
}
.items {
display: flex;
align-items: stretch;
margin-right: 0.5rem;
&:last-child {
margin-right: 0;
}
> * {
margin-right: 0.5rem;
&:last-child {
margin-right: 0;
}
}
}
//Why I'm using 2 wrappers: https://front-back.com/how-to-make-absolute-positioned-elements-overlap-their-overflow-hidden-parent/
.scroll-super-wrapper {
display: flex;
flex-grow: 1;
height: 100%;
width: 100%;
position: relative;
}
.scroll-wrapper {
display: flex;
flex-grow: 1;
overflow-x: hidden;
}
.tabs {
display: flex;
flex-wrap: nowrap;
align-items: start;
position: absolute;
top: 0;
right: 0;
bottom: -0.85rem; // Makes the scrollbar appear underneath
left: 0;
overflow-x: auto;
}
.tab {
background: #444;
color: #FFF;
display: flex;
align-items: center;
white-space: nowrap;
height: 100%;
text-align: center;
padding: 0 1rem;
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
margin-right: 0.5rem;
position: relative;
&:last-child {
margin-right: 0;
}
}
.overlay {
position: absolute;
top: 100%;
left: 0;
height: 100px;
padding: 1rem;
background-color: black;
}
<div class="page">
<div class="header">
<div class="items left-items">
<button>Options</button>
<button>New</button>
</div>
<div class="items scroll-super-wrapper">
<div class="scroll-wrapper">
<div class="tabs">
<div class="tab">Tab 1</div>
<div class="tab">Tab 2</div>
<div class="tab">
Tab 3
<div class="overlay">
Overlay content
</div>
</div>
<div class="tab">Tab 4</div>
<div class="tab">Tab 5</div>
<div class="tab">Tab 6</div>
<div class="tab">Tab 7</div>
<div class="tab">Tab 8</div>
<div class="tab">Tab 9</div>
<div class="tab">Tab 10</div>
<div class="tab">Tab 11</div>
</div>
</div>
</div>
<div class="items left-items">
<button>Export</button>
<button>Share</button>
</div>
</div>
</div>
Stackoverflow's code snippets totally mess up the formatting. I've made a codepen here: https://codepen.io/anon/pen/rXLZgN
Is it possible to do this without using JavaScript to calculate the x/y coordinates and make the element position: fixed? I would like to do this with just CSS if possible.
You defined your tabs class as absolute to the relative scroll-super-wrapper
That means that the wrapper will always contain it.
so or you will built it again from in a different way.
or you can take your overlay class and set it position:fixed and it will take it out the relative of the wrapper (not recommended at all);

adding inline-block divs moves parent to the bottom of the screen

I have 2 divs (.showcase, .highlight) nested inside an element with position: relative:
I would like to have a margin on the left of the .contentContainer for the navigation menu (23.79%). Then I would like 2 divs inside the contentContainer div that extend the whole height of the screen, regardless of their content. Then I would like to add content inside those two divs.
<div id="App">
<div data-reactroot="">
<div class="navbarContainer">
</div>
<div class="contentContainer">
<div class="showcase">
<div class="thumb"></div>
<div class="thumb"></div>
<div class="thumb"></div>
<div class="thumb"></div>
</div>
<div class="highlight"></div>
</div>
</div>
</div>
Now when I add more divs into my showcase div, the .showcase div gets moved to the bottom of the screen (so only the 100px of the .thumb divs are visible.). I can't figure out what I am doing wrong.
Stylesheet:
#App {
background-color: #fff;
color: $fontC2;
font-family: 'Roboto';
min-height: 100vh;
min-width: 320px;
position: relative;
}
.contentContainer {
margin-left: 23.79%;
width: 76.21%;
height: 100vh;
.showcase {
width: 61%;
height: 100vh;
display: inline-block;
background-color: red;
top: 0;
.thumb {
width: 20%;
height: 100px;
background-color: $primaryC3;
display: inline-block;
}
}
.highlight {
width: 39%;
background-color: $primaryC2;
height: 100vh;
display: inline-block;
}
}
Fiddle here:
https://jsfiddle.net/2tz9940v/