Why is a CSS 3D rotation not happening around the center point? - html

I'm building out an aggregation of 3d cubes and trying to rotate the aggregated piece. For some reason it's not rotating along the center point.
When I just have an individual cube, it works as expected. When I join 3 cubes into a column, it works as expected. It's just when I join 3 columns into a "section" that the "section" doesn't rotate along the center point.
When the column and cube had this issue it was because I didn't set a proper height and width on them. Am I setting the wrong height and width for the '.section' element? If so, what should it be? An explanation on why my dimensions are wrong would be appreciated as well.
(Sorry for the astronomical code, but SO won't allow just a codepen and the problem doesn't happen with simplified code.)
<div class="scene">
<div class="section col-section">
<div class="col col-back">
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
</div>
<div class="col col-middle">
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
</div>
<div class="col col-front">
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
<div class="cube">
<div class="cube__face cube__face--front">
<div>front</div>
</div>
<div class="cube__face cube__face--back">
<div>back</div>
</div>
<div class="cube__face cube__face--right">
<div>right</div>
</div>
<div class="cube__face cube__face--left">
<div>left</div>
</div>
<div class="cube__face cube__face--top">
<div>top</div>
</div>
<div class="cube__face cube__face--bottom">
<div>bottom</div>
</div>
</div>
</div>
</div>
</div>
.scene {
perspective: 600px;
}
.cube {
width: 100px;
height: 100px;
position: relative;
}
.cube__face {
position: absolute;
width: 100px;
height: 100px;
color: white;
font-size: 1.5rem;
display: flex;
align-items: center;
justify-content: center;
}
.cube__face--front {
transform: rotateY(0deg) translateZ(50px);
background-color: pink;
}
.cube__face--right {
transform: rotateY(90deg) translateZ(50px);
background-color: yellow;
}
.cube__face--back {
transform: rotateY(180deg) translateZ(50px);
background-color: green;
}
.cube__face--left {
transform: rotateY(-90deg) translateZ(50px);
background-color: blue;
}
.cube__face--top {
transform: rotateX(90deg) translateZ(50px);
background-color: orange;
}
.cube__face--bottom {
transform: rotateX(-90deg) translateZ(50px);
background-color: magenta;
}
.col {
position: absolute;
transform-style: preserve-3d;
width: 100px;
height: 300px;
}
.col .cube {
position: absolute;
top: 100px;
}
.col .cube:first-child {
top: 0;
}
.col .cube:last-child {
top: 200px;
}
.col-back {
transform: translateZ(-200px);
}
.col-middle {
transform: translateZ(-100px);
}
.section {
transform-style: preserve-3d;
backface-visibility: hidden;
transform: rotateX(0deg);
transition: all 1s linear;
}
.col-section {
width: 100px;
height: 100px;
}

Ok, I was swimming in a sea of ignorance as to the fact that transform-origin accepts a 3rd value that corresponds to the z-axis. Basically, the default transform origin was correct for the x and y access, but I needed a custom one for the z-index to push it back a bit.
transform-origin: 50px 150px -100px;

Related

How to make equal height of few flex-direction columns?

I'm struggling to make equal flex-box flex-direction column rows. Most of the code is added below. I am trying to deal with it through a long time already and I certainly would appreciate a help.
My code:
.table__cell {
flex: 1;
padding: 10px 20px;
border: 1px solid black;
margin: 3px;
}
.table--params {
width: auto;
flex: 1;
display: flex;
}
.table--params>.table__cell {
padding: 0;
display: flex;
flex-direction: column;
flex-grow: 1;
}
.table--params>.table__cell .table__row {
flex: 1;
}
<div class="table--params">
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Jan Kowalski
</div>
</div>
<div class="table__row">
<div class="table__cell">
John Kowalsky
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
email#example.com
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Tester
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
Grafik
</div>
</div>
</div>
</div>
The problem is visualized in jsfiddle:
https://jsfiddle.net/xp7cs5ag/
The question is - how to make equal height of every row in each column?
You could achieve this with display: grid (instead of flex) for the outer .table__cell. With grid-template-rows: 1fr 1fr 1fr; you define that each row should have an equal height. You could also define fixed values like px.
Working example:
.table__cell {
flex: 1;
padding: 10px 20px;
border: 1px solid black;
margin: 3px;
}
.table--params {
width: auto;
flex: 1;
display: flex;
}
.table--params>.table__cell {
padding: 0;
display: grid;
grid-template-rows: 1fr 1fr 1fr;
}
.table--params>.table__cell .table__row {
flex: 1;
}
<div class="table--params">
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Mariusz Bocz
</div>
</div>
<div class="table__row">
<div class="table__cell">
Feliks Michalski
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
programista#tech-studio.pl
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Programista
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
Grafik
</div>
</div>
</div>
</div>
If you want the grid-items to be centered you could use align-items: center.
Working example:
.table__cell {
flex: 1;
padding: 10px 20px;
border: 1px solid black;
margin: 3px;
}
.table--params {
width: auto;
flex: 1;
display: flex;
}
.table--params>.table__cell {
padding: 0;
display: grid;
grid-template-rows: 1fr 1fr 1fr;
align-items: center;
}
.table--params>.table__cell .table__row {
flex: 1;
}
<div class="table--params">
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Mariusz Bocz
</div>
</div>
<div class="table__row">
<div class="table__cell">
Feliks Michalski
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
<div class="table__row">
<div class="table__cell">
123123123
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
programista#tech-studio.pl
</div>
</div>
</div>
<div class="table__cell">
<div class="table__row">
<div class="table__cell">
Programista
</div>
</div>
<div class="table__row">
<div class="table__cell"></div>
</div>
<div class="table__row">
<div class="table__cell">
Grafik
</div>
</div>
</div>
</div>
I have the same problem once and I got this code and it worked for me
The HTML :-
<div class="cont">
<div class="col">
<h2>Column 1</h2>
<p>Hello World</p>
</div>
<div class="col">
<h2>Column 2</h2>
<p>Hello World!</p>
<p>Hello World!</p>
<p>Hello World!</p>
<p>Hello World!</p>
</div>
<div class="col">
<h2>Column 3</h2>
<p>Some other text..</p>
<p>Some other text..</p>
</div>
</div>
The CSS :-
.cont {
display: table;
width: 100%;
}
.col {
display: table-cell;
}

How do I place these div's next to each other to create a 3x2 layout

How do place these div's next to each other in a 3x2 row instead of rows of 1.
Should I make the event-box and event-info as one div instead of two separate div's? I've tried to combine them as one div and given the <p> the event-info class but that didn't work out. I've also tried different sizes for both of the div's and the container to maybe push them next to each other, but that also didn't work. See my code below.
.event-box{
height: 5rem;
width: 30rem;
float: left;
clear: both;
padding: 0;
margin-top: 1rem;
text-align: center;
background: url(/assets/images/placeholderimg4.jpg);}
.event-info{
height: 5rem;
width: 30rem;
float: left;
clear: both;
padding: 0;
margin: 0;
text-align: center;
background-color: rgba(77, 75, 75, 0.1);}
.container{
height: 100%;
width: 64rem;
word-wrap: break-word;
overflow-y: hidden;
padding: 0;}
<div class="container">
<div class="event-box">
<h3 class="event-text">Event 1</h3>
</div>
<div class="event-info">
<p>1</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 2</h3>
</div>
<div class="event-info">
<p>2</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 3</h3>
</div>
<div class="event-info">
<p>3</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 4</h3>
</div>
<div class="event-info">
<p>4</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 5</h3>
</div>
<div class="event-info">
<p>5</p>
</div>
<div class="event-box">
<h3 class="event-text">Event 6</h3>
</div>
<div class="event-info">
<p>6</p>
</div>
</div>
So I used CSS grid for this.
I did combine your event-info and event-box div's together to make them one object in the grid.
.event-box {
height: 5rem;
width: 30rem;
float: left;
clear: both;
padding: 0;
margin-top: 1rem;
text-align: center;
background: url(/assets/images/placeholderimg4.jpg);
}
.event-info {
height: 5rem;
width: 30rem;
float: left;
clear: both;
padding: 0;
margin: 0;
text-align: center;
background-color: rgba(77, 75, 75, 0.1);
}
.container {
height: 100%;
width: 64rem;
word-wrap: break-word;
padding: 0;
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: auto auto;
grid-gap: 2rem;
}
<div class="container">
<div class="event-box">
<h3 class="event-text">Event 1</h3>
<div class="event-info">
<p>1</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 2</h3>
<div class="event-info">
<p>2</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 3</h3>
<div class="event-info">
<p>3</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 4</h3>
<div class="event-info">
<p>4</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 5</h3>
<div class="event-info">
<p>5</p>
</div>
</div>
<div class="event-box">
<h3 class="event-text">Event 6</h3>
<div class="event-info">
<p>6</p>
</div>
</div>
</div>
So in the container class I added a display of grid (to use grid functions) and then I added grid-template-columns (which allows you to specify how many columns you want to include) and a grid-template-rows to do the same thing for the rows. I then added a grid-gap to separate the div tags a bit but this value can be played with depending on the desired gap.
You can add a wrap div, like 'event' for it :
<div class="container">
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 1</h3>
</div>
<div class="event-info">
<p>1</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 2</h3>
</div>
<div class="event-info">
<p>2</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 3</h3>
</div>
<div class="event-info">
<p>3</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 4</h3>
</div>
<div class="event-info">
<p>4</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 5</h3>
</div>
<div class="event-info">
<p>5</p>
</div>
</div>
<div class='event'>
<div class="event-box">
<h3 class="event-text">Event 6</h3>
</div>
<div class="event-info">
<p>6</p>
</div>
</div>
</div>
And a little css addition:
.event{
display:inline-block;
width:49%;
}
Try it - https://jsfiddle.net/5vz3Lhwc/
You can make use of the power of Flexbox! Wrap each row in a div with class row and each column in a div with class col. Example:
<div class="container">
<div class="row">
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 1</h3>
</div>
<div class="event-info">
<p>1</p>
</div>
</div>
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 2</h3>
</div>
<div class="event-info">
<p>2</p>
</div>
</div>
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 3</h3>
</div>
<div class="event-info">
<p>3</p>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 4</h3>
</div>
<div class="event-info">
<p>4</p>
</div>
</div>
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 5</h3>
</div>
<div class="event-info">
<p>5</p>
</div>
</div>
<div class="col">
<div class="event-box">
<h3 class="event-text">Event 6</h3>
</div>
<div class="event-info">
<p>6</p>
</div>
</div>
</div>
</div>
The CSS for the added elements:
.row {
width: 100%;
display: flex;
}
.col {
width: 33%;
flex: 1;
}
Edit: CSS Grid might be an even easier solution.

How can I prevent text from going out of the grid (make in centered)?

I am designing this website for my introductory course. They require flex/grid layouts (although we didn't cover this in class). I decided to follow a youtube tutorial that was making a grid with 3 columns (1fr each). It then added a background to every "cell". In every "cell" I have a title and a description. I want to style the title and description in each "cell" to always be in the center, no matter the sizing of the page. I have managed to make the text adjust its size to the dimension of the page, but the title still overflows to the right when I minimize the window's width.
This is what I mean by overflow:
As you might guess, when the width is too large, the title tends to go to the right. This is the code (I no longer have images as background but you get the idea):
const portfolioItems = document.querySelectorAll('.portfolio-item-wrapper');
portfolioItems.forEach(portfolioItem => { //pentru fiecare item din portofolioItem vad cand am mouse pe el
portfolioItem.addEventListener('mouseover', () => {
portfolioItem.childNodes[1].classList.add('img-darken');//si cand am mouse-ul pe el iau primul copil
//care este portofolio-img-background
})
portfolioItem.addEventListener('mouseout', () => {
portfolioItem.childNodes[1].classList.remove('img-darken');
})
})
.portfolio-items-wrapper{
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.portfolio-item-wrapper{
position:relative;
}
.portfolio-img-background{
height:350px;
width: auto;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.portfolio-img-background:nth-of-type(odd)
{
background-color: maroon;
}
.portfolio-img-background:nth-of-type(even)
{
background-color: rgb(101, 172, 122);
}
.title-text-wrapper{
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items:center;
height: 100%;
text-align: center;
padding-left: 100px;
padding-right: 100px;
}
#italian{
font-family: 'Pacifico', cursive;
}
#american{
font-family: 'Mitr';
}
.title-wrapper div{
justify-content: center;
font-size:5vw;
color: white;
align-items: center;
text-align: center;
align-content: center;
}
/* Needs to be more specific with selector*/
.title-text-wrapper .subtitle{
transition: 1s;
font-weight: 600;
color: transparent;
align-self: center;;
}
.title-text-wrapper:hover .subtitle{
font-weight: 600;
color: lightseagreen;
}
.img-darken{
transition: 1s;
filter: brightness(10%);
}
.logo-wrapper{
width: 50%;
margin-bottom: 2px;
}
<div class="content-wrapper">
<div class="portfolio-items-wrapper">
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio1.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="american">American</div>
</div>
<div class="subtitle">
This is a description of american food.
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio2.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="italian">Italian</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio3.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="chinese">Asian</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio4.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="mexican">Mexican</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio5.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="romanian">Romanian</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio8.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="barbeque">Barbeque</div>
</div>
<div class="subtitle">
Item
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio9.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="indian">Indian</div>
</div>
<div class="subtitle">
Item
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio10.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="chinese">Chinese</div>
</div>
<div class="subtitle">
Item
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio11.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="mediteranean">Mediteranean</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio12.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="desserts">Desserts</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio6.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="smoothies">Smoothies</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio7.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="coffee">Coffee</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
</div>
</div>
I'm a beginner at this, so I would appreciate your advice on anything that's wrong with this code.
Issue is you are using padding left right to make item in center, I removed that and make its width:100% as you are using flex so its align center already
const portfolioItems = document.querySelectorAll('.portfolio-item-wrapper');
portfolioItems.forEach(portfolioItem => { //pentru fiecare item din portofolioItem vad cand am mouse pe el
portfolioItem.addEventListener('mouseover', () => {
portfolioItem.childNodes[1].classList.add('img-darken');//si cand am mouse-ul pe el iau primul copil
//care este portofolio-img-background
})
portfolioItem.addEventListener('mouseout', () => {
portfolioItem.childNodes[1].classList.remove('img-darken');
})
})
.portfolio-items-wrapper{
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.portfolio-item-wrapper{
position:relative;
}
.portfolio-img-background{
height:350px;
width: auto;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.portfolio-img-background:nth-of-type(odd)
{
background-color: maroon;
}
.portfolio-img-background:nth-of-type(even)
{
background-color: rgb(101, 172, 122);
}
.title-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
width: 100%;
}
#italian{
font-family: 'Pacifico', cursive;
}
#american{
font-family: 'Mitr';
}
.title-wrapper div{
justify-content: center;
font-size:5vw;
color: white;
align-items: center;
text-align: center;
align-content: center;
}
/* Needs to be more specific with selector*/
.title-text-wrapper .subtitle{
transition: 1s;
font-weight: 600;
color: transparent;
align-self: center;
}
.title-text-wrapper:hover .subtitle{
font-weight: 600;
color: lightseagreen;
}
.img-darken{
transition: 1s;
filter: brightness(10%);
}
.logo-wrapper{
width: 50%;
margin-bottom: 2px;
}
<div class="content-wrapper">
<div class="portfolio-items-wrapper">
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio1.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="american">American</div>
</div>
<div class="subtitle">
This is a description of american food.
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio2.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="italian">Italian</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio3.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="chinese">Asian</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio4.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="mexican">Mexican</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio5.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="romanian">Romanian</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio8.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="barbeque">Barbeque</div>
</div>
<div class="subtitle">
Item
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio9.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="indian">Indian</div>
</div>
<div class="subtitle">
Item
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio10.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="chinese">Chinese</div>
</div>
<div class="subtitle">
Item
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio11.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="mediteranean">Mediteranean</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio12.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="desserts">Desserts</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio6.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="smoothies">Smoothies</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background-image:url(images/Portfolio7.jpg);"></div>
<div class="title-text-wrapper">
<div class="title-wrapper">
<div id="coffee">Coffee</div>
</div>
<div class="subtitle">
</div>
</div>
</div>
</div>
</div>

Divs disappear when using inline-block

Trying to create a responsive flip-card gallery using a code I came across here. Everything works great except for when I try to align the flip-cards next to each other (trying to create three cards per row) then they just disappear. I've tried using display: inline-block and a flex-grid, but can't figure out where i'm going wrong.
Thank you!
Here's the intial code:
HTML
<div class="container">
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="image1.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="metalcard.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="image3.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.container {
margin: 0 auto;
max-width: 1200px;
padding: 0 1rem;
display: inline-block;
}
.card-container{
width: 25%; /* Adjust the target width*/
}
.flip-container {
position: relative;
perspective: 1000px;
}
/* flip the pane when hovered */
.flip-container:hover .flipper, .flip-container.hover .flipper {
transform: rotateY(180deg);
}
.flip-container, .front, {
width: 100%;
height: 170px;
}
.flip-container,.back {
height: 190px;
width: 100%;
}
.flipper {
transition: 0.9s;
transform-style: preserve-3d;
position: relative;
}
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}
.front {
background: rgba(0,0,0,0.05);
z-index: 2;
/* for firefox 31 */
transform: rotateY(0deg);
}
/* back, initially hidden pane */
.back {
background: #00ccff;
transform: rotateY(180deg);
}
I tried your code in a jsfiddle and they were some parts of the html code missing and i fix the class .container and .card-container
Here you go
HTML
<div class="container">
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="image1.jpg" style="height: 100%;"> </div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="metalcard.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card-container">
<div class="row">
<div class="col">
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="inner"><img src="image3.jpg" style="height: 100%;"></div>
</div>
<div class="back">
<div class="inner">Back</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS
.container {
width: 100%;
}
.card-container{
width: 25%; /* Adjust the target width*/
display: inline-block;
}

How do I set div like table with different width?

I have div to look like table, this is my code:
.cell {
border: 1px solid red;
display: table-cell
}
.tableLike {
padding-bottom: 30px;
display: table
}
.rowLike {
display: table-row
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
Now all the the columns are in different width, and I don't know why. I want that div get different width but synchronize.
using display:table like this
.tableLike{width:100%;display:table;}
.cell{border:1px solid red;display:table-cell;}
.tableLike {display:table;}
.rowLike{display:table-row;}
.cell{border:1px solid red;display:table-cell;}
.tableLike{padding-bottom: 30px;}
.rowLike .cell:nth-child(1),.rowLike .cell:nth-child(3){ width: 15%;}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
Add the correct display styles:
.cell {
border: 1px solid red;
display: table-cell;
}
.tableLike {
padding-bottom: 30px;
display: table;
}
.rowLike {
display: table-row;
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
.tableLike {display:table;}
.rowLike{display:table-row;}
.cell{border:1px solid red;display:table-cell;}
.tableLike{padding-bottom: 30px;}
.rowLike .cell:nth-child(1),.rowLike .cell:nth-child(3){ width: 33%;}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>
I will do like this.
You can try, but it may not be the best answer.
.cell {
border-right:1px solid red;
border-bottom:1px solid red;
display: table-cell
}
.tableLike {
padding-bottom: 30px;
display: table
}
.rowLike {
display: table-row
}
.rowLike .cell:nth-child(1),
.rowLike .cell:nth-child(3) {
width: 15%;
}
.rowLike:nth-child(1) .cell:nth-child(1),
.rowLike:nth-child(1) .cell:nth-child(2),
.rowLike:nth-child(1) .cell:nth-child(3){
border-top:1px solid red;
}
.rowLike:nth-child(1) .cell:nth-child(1),
.icon-close{
border-left:1px solid red;
}
<div class="tableLike ">
<div class="rowLike">
<div class="cell"></div>
<div class="cell">
<div class="title">PRODUCT</div>
</div>
<div class="cell">
<div class="title">PRICE</div>
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content
</div>
<div class="cell bolder">
$30
</div>
</div>
<div class="rowLike">
<div class="cell">
<i class="icon-close">X</i>
</div>
<div class="cell">
some content some content
</div>
<div class="cell bolder">
$8
</div>
</div>
</div>