Why does the divs starts from between in case of overflow hidden? - html

Styles
body{
margin:unset;
}
.carousel{
height: 200px;
width: 100%;
padding: 10px;
box-sizing: border-box;
display: grid;
grid-template-columns: 50px 1fr 50px;
grid-gap: 10px;
}
.carousel-controls{
color: navy;
}
.carousel > div{
display: grid;
align-items: center;
justify-content: center;
}
.carousel-holder{
background: purple;
display: grid;
grid-gap: 10px;
grid-auto-flow: column;
overflow: hidden;
padding: 10px;
box-sizing: border-box;
}
.carousel-cards{
background: white;
height: 100%;
width: 125px;
display: grid;
place-items:center;
font-weight: bolder;
color: navy;
}
Markup with bit of php for card generation
<div class="carousel">
<div class="carousel-controls carousel-controls-prev ">
<i class="fas fa-arrow-left"></i>
</div>
<div class="carousel-holder">
<?php
$x = 1;
while ($x <= 250) {
echo "<div class='carousel-cards'>".$x."</div>";
$x++;
}
?>
</div>
<div class="carousel-controls carousel-controls-next ">
<i class="fas fa-arrow-right"></i>
</div>
</div>
The result
Problem
I am making a carousel to which Ill add javascript later. Now my problem is that the generated cards which should start from 1 are actually starting from 120 when I am using overflow hidden.

In regards to your content centering, in your css, it should be justify-content:start and not justify-content:center.
So, it should look like this:
.carousel > div{
display: grid;
align-items: center;
justify-content: start;
}

You can change your alignment to left if you want it to start at 1 rather than the center using:
.carousel-cards{
justify-content: left;
}
See it in action below:
body{
margin:unset;
}
.carousel{
height: 200px;
width: 100%;
padding: 10px;
box-sizing: border-box;
display: grid;
grid-template-columns: 50px 1fr 50px;
grid-gap: 10px;
}
.carousel-controls{
color: navy;
}
.carousel > div{
display: grid;
align-items: center;
justify-content: left;
}
.carousel-holder{
background: purple;
display: grid;
grid-gap: 10px;
grid-auto-flow: column;
overflow: hidden;
padding: 10px;
box-sizing: border-box;
}
.carousel-cards{
background: white;
height: 100%;
width: 125px;
display: grid;
place-items:center;
font-weight: bolder;
color: navy;
}
<div class="carousel">
<div class="carousel-controls carousel-controls-prev ">
<i class="fas fa-arrow-left"></i>
</div>
<div class="carousel-holder">
<div class='carousel-cards'>1</div>
<div class='carousel-cards'>2</div>
<div class='carousel-cards'>3</div>
<div class='carousel-cards'>4</div>
<div class='carousel-cards'>5</div>
<div class='carousel-cards'>6</div>
<div class='carousel-cards'>7</div>
<div class='carousel-cards'>8</div>
<div class='carousel-cards'>9</div>
<div class='carousel-cards'>10</div>
<div class='carousel-cards'>11</div>
<div class='carousel-cards'>12</div>
<div class='carousel-cards'>13</div>
<div class='carousel-cards'>14</div>
<div class='carousel-cards'>15</div>
<div class='carousel-cards'>16</div>
<div class='carousel-cards'>17</div>
<div class='carousel-cards'>18</div>
<div class='carousel-cards'>19</div>
<div class='carousel-cards'>20</div>
<div class='carousel-cards'>21</div>
<div class='carousel-cards'>22</div>
<div class='carousel-cards'>23</div>
<div class='carousel-cards'>24</div>
<div class='carousel-cards'>25</div>
</div>
<div class="carousel-controls carousel-controls-next ">
<i class="fas fa-arrow-right"></i>
</div>
</div>

Related

Why does giving my nested CSS grid values for "grid-template-columns" stretch the entire parent container?

I have a block element (class "blockWrap" in the example code) which contains a nested grid (class "optionsUnderDialogue").
I can't figure out why giving the grid the CSS property "grid-template-columns: 1fr 1fr 1fr;" stretches the width of the entire block. I would expect the space to be divided into three fractions that have no effect on the width of the parent.
Here is the demo in Codepen (simply uncomment the grid-template-columns: 1fr 1fr 1fr; line to observe the issue):
https://codepen.io/noip/pen/oNdgqBj
The HTML code:
<div class="blockWrap">
<div class="contentWrap">
<div style="display: flex; align-items:center; justify-content: center;">
<div class="topConnectionSocket">o</div>
</div>
<div id="id0" class="block">
<div style="text-align: left;">
<span style="width: 15%; display:inline-block; text-align: right;">ID:</span><input class="next"
style="width: 15%; display:inline-block;" type="number">
</div>
<input type="text" class="elementInfoField" placeholder="character name">
<select name="blockType" class="selectBlockType">
<option value="line">Line</option>
<option value="question">Question</option>
<option value="fight">Fight</option>
</select>
<textarea placeholder="Dialogue" data-autoresize></textarea>
<div class="optionsUnderDialogue" style="text-align: right;">
<div class="option1"></div>
<div class="option2"></div>
<div class="option3">
<span style=" text-align: right;">Next:</span><input class="next"
style="display:inline-block;" type="number">
</div>
</div>
</div>
<div class="plusButtonContainer" style="display: flex; align-items: end; justify-content: center;">
<div class="blockPlusButton">+</div>
</div>
</div><!-- end contentwrap -->
</div><!-- end blockwrap -->
The CSS:
.plus {
font-size: 5rem;
font-weight: bolder;
background-color: crimson;
width: 4rem;
height: 4rem;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
border-radius: 0.5rem;
}
.blockWrap {
position: absolute;
box-sizing: border-box;
}
.block {
min-width: 200px;
background: crimson;
margin: 1rem;
border-radius: 5%;
display: grid;
align-items: center;
justify-content: center;
/* position: absolute; */
box-sizing: border-box;
z-index: 2;
transform-origin: 50% 50%;
overflow: hidden;
padding:15px;
}
.blockPlusButton{
margin-top: -3rem;
border-radius: 50%;
text-align: center;
font-size: 1.5rem;
font-weight: bolder;
width: 2rem;
aspect-ratio: 1;
background-color: #0075ff;
display: flex;
justify-content: center;
align-items: center;
}
.optionsUnderDialogue{
display: grid;
max-width: 100%;
/* grid-template-columns: 1fr 1fr 1fr; */
}
.block input {
background-color: white;
color: black;
border: none;
text-align: center;
}
.block input, .block select, .block textarea {
margin: 0.3rem;
}
.topConnectionSocket {
margin-bottom: -2.2rem;
}
.block input::placeholder {
color: rgb(182, 182, 182);
}
Can you help me out as I'm quite stumped. When I inspect the elements inside the grid columns, I don't see anything that would force things to stretch.

How to span a one of the grandchild element to 100% width in CSS Grid

How to span a one of the grandchild element to 100% width in CSS Grid while the parent is container is divided into 3 fractions.
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.container > div {
background-color: #4834d4;
width: 100%;
}
.container > div .child_01 {
background-color: #f9ca24;
width: 80%;
height: 50px;
margin: 1rem auto;
}
.container > div .child_02 {
background-color: #eb4d4b;
width: 80%;
height: 50px;
margin: 1rem auto;
}
<div class="container">
<div>
<div class="child_01"></div>
<div class="child_02"></div>
</div>
<div>
<div class="child_01"></div>
<div class="child_02"></div>
</div>
<div>
<div class="child_01"></div>
<div class="child_02"></div>
</div>
</div>
What I am trying to achieve is this.desired layout
Is this possible to achieve in CSS Grid.
Here you go with a solution
.container {
padding: 20px;
display: flex;
flex-direction: column;
background-color: #4834d4;
}
.container > div {
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom: 1rem;
}
.child_01 {
display: inline-flex;
background-color: #f9ca24;
width: 30%;
height: 50px;
}
.child_02 {
display: flex;
background-color: #eb4d4b;
width: 100%;
height: 50px;
margin: 1rem auto;
}
<div class="container">
<div>
<div class="child_01"></div>
<div class="child_01"></div>
<div class="child_01"></div>
</div>
<div class="child_02"></div>
<div class="child_02"></div>
<div class="child_02"></div>
</div>
I have use flex instead of grid.

css, how to combine shape-outside and flex-wrap?

I'm trying to combine flex-wrap and shape-outside to get something like this :
What i want to do is : the blue zone to flex-wrap it's content, and to be on the right and bottom of the grey zone :
adding display: flex; break the shape-outside
Any tips ? thanks
A JSfiddle :
https://jsfiddle.net/81b3cLxf/
HTML
<div class="main">
<div class="left"></div>
<div class="flex-container wrap">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
<div class="flex-item">4</div>
<div class="flex-item">5</div>
<div class="flex-item">6</div>
<div class="flex-item">7</div>
<div class="flex-item">8</div>
</div>
</div>
CSS
.main {
width: 600px;
height: 500px;
box-sizing: border-box;
overflow: hidden;
background-color: black;
padding: 10px;
}
.left {
width: 50%;
height: 200px;
background-color: lightgray;
shape-outside:"none";
float: left;
}
.flex-container {
height: 100%;
background-color: blue;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
}
.wrap {
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
.flex-item {
background: tomato;
padding: 5px;
width: 75px;
height: 75px;
margin: 10px;
line-height: 75px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
}
Please check my example with grid:
.main {
width: 600px;
height: 500px;
box-sizing: border-box;
overflow: hidden;
background-color: black;
padding: 10px;
}
.left {
grid-column: span 3;
grid-row: span 2;
background-color: lightgray;
}
.flex-container {
height: 100%;
background-color: blue;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
grid-gap: 10px;
grid-auto-rows: 85px;
}
.flex-item {
background: tomato;
padding: 5px;
width: 75px;
height: 75px;
margin: 0;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
<div class="main">
<div class="flex-container wrap">
<div class="left"></div>
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
<div class="flex-item">4</div>
<div class="flex-item">5</div>
<div class="flex-item">6</div>
<div class="flex-item">7</div>
<div class="flex-item">8</div>
<div class="flex-item">9</div>
<div class="flex-item">10</div>
</div>
</div>

How to make a block of prices for all the same padding

Faced with the problem the block of my prices has different indents everywhere. This is due to the length of the text (product name). How to make a block of prices for all the same markup. How can I do it? Help me, please. At least a small example.
html
<div class="product_grid">
<div class="product_section">
<div>
<a href="#">
<div>
<img class="product_image" src="#">
<div class="product_text">
<div class="product_name">Name</div>
<div class="product_price_block">
<div class="product_price empty">1200 ₽</div>
<div class="product_price">1800 ₽</div>
</div>
</div>
</div>
</a>
</div>
<div>
<button class="add_to_cart">Add to cart</button>
</div>
</div>
</div>
css
.product_grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
grid-row-gap: 20px;
grid-column-gap: 3%;
padding: 8px;
}
.product_grid > * {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 1rem;
border: 1px solid #ccc;
border-radius: 8px;
text-align: center;
}
.product_price_block {
display: flex;
justify-content: space-around;
border: 1px solid grey;
padding: 10px 12px;
margin-top: 3rem;
}
.add_to_cart {
border: 1px solid grey;
padding: 10px 12px;
margin-top: 3rem;
cursor: pointer;
background: none;
outline: none;
}
.product_image {
vertical-align: middle;
max-width: 100%;
}
Thanks!
You can fix the product name div height.
Try this:-
.product_name{
height: 30px;
}

How to make horizontal scroll on page

I have div in which placed inner divs i need to make all inner divs in line and horizontal scrollbar should be displayed (i know it sounds crazy, but i need that). I tried container width auto and overflow scroll but nothing.
How to accomplish that?
my markup:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>text-overflow</title>
<style>
body{
width: auto;
}
#items{
overflow-x: scroll;
width: auto;
}
.item{
display: inline-block;
width: 400px;
height: 100px;
border:1px solid;
}
</style>
</head>
<body>
<div id="items">
<div class="item">
Item content
</div>
<div class="item">
Item content
</div>
<div class="item">
Item content
</div>
<div class="item">
Item content
</div>
<div class="item">
Item content
</div>
<div class="item">
Item content
</div>
</div>
</body>
</html>
Use white-space: nowrap; on #items
#items{
overflow-x: scroll;
width: auto;
white-space: nowrap;
}
DEMO
simply give #items to height and overflow-x:auto.
#items{
overflow-x: auto;
width: auto;
height: 200px;
}
<div style="overflow-x:scroll;">
<div style="width:1600px;">
<div style="width:1500px;">
<table>
<tr>
<td> Your Value </td>
</tr>
</table>
</div>
</div>
</div>
I think you want something like this...
:root {
--gutter: 20px;
}
.app {
padding: var(--gutter) 0;
display: grid;
grid-gap: var(--gutter) 0;
grid-template-columns: var(--gutter) 1fr var(--gutter);
align-content: start;
}
.app > * {
grid-column: 2 / -2;
}
.app > .full {
grid-column: 1 / -1;
}
.hs {
display: grid;
grid-gap: calc(var(--gutter) / 2);
grid-template-columns: repeat(6, calc(50% - var(--gutter) * 2));
grid-template-rows: minmax(150px, 1fr);
overflow-x: scroll;
scroll-snap-type: x proximity;
padding-bottom: calc(.75 * var(--gutter));
margin-bottom: calc(-.25 * var(--gutter));
}
/* Demo styles */
html,
body {
height: 100%;
}
body {
display: grid;
place-items: center;
background: #456173;
}
ul {
list-style: none;
padding: 0;
}
h1,
h2,
h3 {
margin: 0;
}
.app {
width: 375px;
height: 667px;
background: #DBD0BC;
overflow-y: scroll;
}
.hs > li,
.item {
scroll-snap-align: center;
padding: calc(var(--gutter) / 2 * 1.5);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: #fff;
border-radius: 8px;
}
<div class="app">
<h1>Some headline</h1>
<ul class="hs">
<li class="item">test</li>
<li class="item">test</li>
<li class="item">test</li>
<li class="item">test</li>
<li class="item">test</li>
<li class="item">test</li>
</ul>
<div class="container">
<div class="item">
<h3>Block for context</h3>
</div>
</div>
</div>