I'm new to CSS and HTML. I made 3 boxes next to each other and I want to have 2 more rows of 3 boxes per row. I can't seem to understand how to separate the rows. They always end up on the same row, distorted and I've been trying all morning to fix it. I will appreciate your help, thank you!
.container {
display: flex;
justify-content: space-between;
}
.box {
width: 400px;
height: 240px;
background-color: #ccc;
margin: 10px;
transition: all 0.3s ease-in-out;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
overflow: hidden;
text-align: justify;
position: relative;
}
.box:hover {
transform: scale(1.1);
}
.box .content {
font-size: 10px;
padding: 20px;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
}
.box .title {
font-size: 14px;
font-weight: bold;
margin-bottom: 10px;
position: justify;
top: 50%;
left: 50%;
}
.box:nth-child(1) {
background-color: #fec10d;
}
.box:nth-child(2) {
background-color: #0077c0;
}
.box:nth-child(3) {
background-color: #b2d234;
}
.box img {
position: relative;
top: 1%;
left: 50%;
transform: translateX(-175%);
height: 80px;
width: 80px;
object-fit: contain;
margin-bottom: 5px;
padding-bottom: 5px;
margin: auto;
display: block;
}
<div class="container">
<div class="box">
<div class="content">
<img src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD" alt="Care">
<div class="title">TEAMWORK</div>
<div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
</div>
</div>
<div class="box">
<div class="content">
<img src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD" alt="Care">
<div class="title">BUILDS TRUST</div>
<div>Gains the trust of others through honesty and authenticity. Shows consistency between his/her words and actions, upholds professional codes of conduct, acts in accordance with the company’s policies, delivers on promises, and takes personal responsibility
for decisions, actions, and mistakes.</div>
</div>
</div>
<div class="box">
<div class="content">
<img src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD" alt="Care">
<div class="title">CARE FOR OTHERS AND INCLUSION</div>
<div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
</div>
</div>
</div>
Please use the below code.
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 20px;
}
.box {
background-color: #ccc;
transition: all 0.3s ease-in-out;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
overflow: hidden;
text-align: justify;
flex-basis: calc(32% - 6.67px); /* calculate flex-basis to account for gap */
margin-bottom: 20px;
}
.box:hover {
transform: scale(1.1);
}
.box .content {
font-size: 10px;
padding: 20px;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
}
.box .title {
font-size: 14px;
font-weight: bold;
margin-bottom: 10px;
text-align: center;
}
.box:nth-child(1) {
background-color: #fec10d;
}
.box:nth-child(2) {
background-color: #0077c0;
}
.box:nth-child(3) {
background-color: #b2d234;
}
.box img {
position: relative;
height: 80px;
width: 80px;
object-fit: contain;
margin-bottom: 5px;
padding-bottom: 5px;
}
below code:
<div class="container">
<div class="box">
<div class="content">
<img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
<div class="title">TEAMWORK</div>
<div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
</div>
</div>
<div class="box">
<div class="content">
<img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
<div class="title">BUILDS TRUST</div>
<div>Gains the trust of others through honesty and authenticity. Shows consistency between his/her words and actions, upholds professional codes of conduct, acts in accordance with the company’s policies, delivers on promises, and takes personal responsibility
for decisions, actions, and mistakes.</div>
</div>
</div>
<div class="box">
<div class="content">
<img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
<div class="title">CARE FOR OTHERS AND INCLUSION</div>
<div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
</div>
</div>
<div class="box">
<div class="content">
<img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
<div class="title">TEAMWORK</div>
<div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
</div>
</div>
<div class="box">
<div class="content">
<img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
<div class="title">TEAMWORK</div>
<div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
</div>
</div>
</div>
Apply these changes to resolve this issue :
.container {
display: flex;
justify-content: center;
}
/* add this style */
.boxes {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
<div class="container">
<div class="boxes">
<div class="box">
<div class="content">
<img
src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
alt="Care"
/>
<div class="title">TEAMWORK</div>
<div>
Actively seeks opportunities to collaborate with and support
others. Builds relationships across the organization, shares
knowledge and experience, involve others and communicates
effectively.
</div>
</div>
</div>
<div class="box">
<div class="content">
<img
src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
alt="Care"
/>
<div class="title">BUILDS TRUST</div>
<div>
Gains the trust of others through honesty and authenticity. Shows
consistency between his/her words and actions, upholds
professional codes of conduct, acts in accordance with the
company’s policies, delivers on promises, and takes personal
responsibility for decisions, actions, and mistakes.
</div>
</div>
</div>
<div class="box">
<div class="content">
<img
src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
alt="Care"
/>
<div class="title">CARE FOR OTHERS AND INCLUSION</div>
<div>
Actively seeks opportunities to collaborate with and support
others. Builds relationships across the organization, shares
knowledge and experience, involve others and communicates
effectively.
</div>
</div>
</div>
<div class="box">
<div class="content">
<img
src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
alt="Care"
/>
<div class="title">TEAMWORK</div>
<div>
Actively seeks opportunities to collaborate with and support
others. Builds relationships across the organization, shares
knowledge and experience, involve others and communicates
effectively.
</div>
</div>
</div>
<div class="box">
<div class="content">
<img
src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
alt="Care"
/>
<div class="title">BUILDS TRUST</div>
<div>
Gains the trust of others through honesty and authenticity. Shows
consistency between his/her words and actions, upholds
professional codes of conduct, acts in accordance with the
company’s policies, delivers on promises, and takes personal
responsibility for decisions, actions, and mistakes.
</div>
</div>
</div>
<div class="box">
<div class="content">
<img
src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
alt="Care"
/>
<div class="title">CARE FOR OTHERS AND INCLUSION</div>
<div>
Actively seeks opportunities to collaborate with and support
others. Builds relationships across the organization, shares
knowledge and experience, involve others and communicates
effectively.
</div>
</div>
</div>
</div>
https://learncssgrid.com/
Related
I'm trying to add a x-axis scrollable slider, but cant seems to figure it out.
Here, I'm trying to do a horizontal card scroll. If I add padding to the card Wrapper it extends itself out of the body. which I don't want to happen. Therefore I removed the padding and added overflow-x: scroll . I thought it will solve the issue and I will be able to scroll left/right.
Please tell me how to add the scroll without going out of the body.
Thanks in advance.
.services {
display: flex;
flex-direction: column;
width: 100%;
overflow-x: visible;
height: fit-content;
align-items: center;
justify-content: space-between;
padding: 30px 0;
}
.cardWrapper {
display: flex;
background: red;
overflow-x: scroll;
flex-direction: row;
justify-content: space-around;
}
.cardContainer {
width: 500px;
height: 500px;
background: blue;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
}
.cardContainer .cardsImage {
width: 60%;
}
.cardContainer .cardsImage img {
width: 100%;
}
.cardContainer .cardContents {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
<div class="services">
<h1>Our Services</h1>
<div class="cardWrapper">
<div class="cardContainer">
<div class="cardsImage">
<img src="https://via.placeholder.com/300" alt="Qa Services">
</div>
<div class="cardContents">
<h2>Qa Services</h2>
<p>Our Qa engineers don't just test,they make your software application successful ensuring quality delivery with expert manual and automated testing services.</p>
</div>
</div>
<div class="cardContainer">
<div class="cardsImage">
<img src="https://via.placeholder.com/300" alt="Qa Services">
</div>
<div class="cardContents">
<h2>Qa Services</h2>
<p>Our Qa engineers don't just test,they make your software application successful ensuring quality delivery with expert manual and automated testing services.</p>
</div>
</div>
<div class="cardContainer">
<div class="cardsImage">
<img src="https://via.placeholder.com/300" alt="Qa Services">
</div>
<div class="cardContents">
<h2>Qa Services</h2>
<p>Our Qa engineers don't just test,they make your software application successful ensuring quality delivery with expert manual and automated testing services.</p>
</div>
</div>
</div>
</div>
You need to have a simple wrapper that acts as a boundary for your scrollbar. Then inside you need the wrapper for your flex contents.
In addition, simple using a width on elements within a flex context is not enough. You need to provide flex as well
.services {
padding: 30px 0;
}
.cardWrapperOuter {
overflow-x: scroll;
}
.cardWrapper {
display: flex;
background: red;
}
.cardContainer {
flex: 0 0 500px;
width: 500px;
height: 500px;
background: blue;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
}
.cardContainer .cardsImage {
width: 60%;
}
.cardContainer .cardsImage img {
width: 100%;
}
.cardContainer .cardContents {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
<div class="services">
<h1>Our Services</h1>
<div class="cardWrapperOuter">
<div class="cardWrapper">
<div class="cardContainer">
<div class="cardsImage">
<img src="./assets/images/QaServices.svg" alt="Qa Services">
</div>
<div class="cardContents">
<h2>Qa Services</h2>
<p>Our Qa engineers don't just test,they make your software application successful ensuring quality delivery with expert manual and automated testing services.</p>
</div>
</div>
<div class="cardContainer">
<div class="cardsImage">
<img src="./assets/images/QaServices.svg" alt="Qa Services">
</div>
<div class="cardContents">
<h2>Qa Services</h2>
<p>Our Qa engineers don't just test,they make your software application successful ensuring quality delivery with expert manual and automated testing services.</p>
</div>
</div>
<div class="cardContainer">
<div class="cardsImage">
<img src="./assets/images/QaServices.svg" alt="Qa Services">
</div>
<div class="cardContents">
<h2>Qa Services</h2>
<p>Our Qa engineers don't just test,they make your software application successful ensuring quality delivery with expert manual and automated testing services.</p>
</div>
</div>
</div>
</div>
</div>
This question already has answers here:
Equal height children of flex items
(2 answers)
Closed 3 years ago.
I'm trying to achieve a flexbox, where the row will have the titles all lined up. Requirements:
The images won't always be the same height
The description won't always be the same height
The title could be 1 row, or 3 (depending on the length)
Here is a simple fiddle:
https://jsfiddle.net/youradds/r56j4uLe/6/
As you can see this is what you get:
This is more what I'm after:
My SCSS is:
#item-wrapper {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
.item-block {
background: yellow;
flex-grow: 0;
width: 350px;
margin: 2rem 1rem;
display: flex;
flex-direction: column;
justify-content: space-between;
align-content: center;
align-items: center;
.what-logo {
img {
max-height: 100%;
}
}
.text-info {
flex-grow: 1;
.desc {
padding: 1rem;
}
h2 {
flex-grow: 0;
}
}
.action-button {
margin: 0 auto;
}
}
}
.pure-img {
max-width: 100%;
height: auto;
display: block;
}
..and test HTML:
<div id="item-wrapper">
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/3/3-1562951826-3.png" class="pure-img">
</div>
<div class="text-info">
<h2>Zydrunas Savickas Seminar</h2>
<div class="desc">Bodywise Gym and Studios are proud to announce we are bringing the greatest strongman Zydrunas Savickas (Big Z) to Horsham for a seminar.</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/7/7-1562936970-7.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>Class for mums</h2>
<div class="desc">Join Quick HIIT</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/6/6-1562936464-6.png" class="pure-img">
</div>
<div class="text-info">
<h2>Gratitude Day</h2>
<div class="desc">To spread the positivity you can bring a training partner along to workout with you or to attend one of our classes.</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/4/4-1562951950-4.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>The experience of non-duality</h2>
<div class="desc">Yoga & meditation workshop with Indian Spiritual Master Acharya Shree Shankar </div>
</div>
Find out more »
</div>
</div>
Important note: This is a responsive design, so I can't set a height on the image div (i.e min-height 600px) because while this kind of sorts it on wider screens:
...but then on smaller screens, it scales down to 1 element per row - and this then means we have a silly amount of padding between the image and the title on the entries with smaller images:
you could look for a visual compromise.
flex children do not align with flex children from another flex parent.
You may try centering tex-info and what-logo and add an average min-height on .desc
Demo below, play it in full page to test behavior and visual.
#item-wrapper {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
#item-wrapper .item-block {
background: yellow;
max-width: 350px;
margin: 2rem 1rem;
padding:2px;/* see me */
display: flex;
flex-direction: column;
align-items: center;
}
#item-wrapper .item-block .what-logo img {
max-height: 100%;
}
#item-wrapper .item-block .text-info,
#item-wrapper .item-block .what-logo {/* update */
margin-top: auto;
}
#item-wrapper .item-block .text-info .desc {
padding: 1rem;
min-height: 4em;/* 3 lines , average */
}
#item-wrapper .item-block .text-info h2 {text-align:center}
#item-wrapper .item-block .action-button {
margin: 0 auto;
}
.pure-img {
max-width: 100%;
height: auto;
display: block;
}
<div id="item-wrapper">
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/3/3-1562951826-3.png" class="pure-img">
</div>
<div class="text-info">
<h2>Zydrunas Savickas Seminar</h2>
<div class="desc">Bodywise Gym and Studios are proud to announce we are bringing the greatest strongman Zydrunas Savickas (Big Z) to Horsham for a seminar.</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/7/7-1562936970-7.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>Class for mums</h2>
<div class="desc">Join Quick HIIT</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/6/6-1562936464-6.png" class="pure-img">
</div>
<div class="text-info">
<h2>Gratitude Day</h2>
<div class="desc">To spread the positivity you can bring a training partner along to workout with you or to attend one of our classes.</div>
</div>
Find out more »
</div>
<div class="item-block">
<div class="what-logo">
<img src="https://bodywisegym.co.uk/2018/images/events/4/4-1562951950-4.jpg" class="pure-img">
</div>
<div class="text-info">
<h2>The experience of non-duality</h2>
<div class="desc">Yoga & meditation workshop with Indian Spiritual Master Acharya Shree Shankar </div>
</div>
Find out more »
</div>
</div>
forked fiddle
We have to display blocks of content in many rows with max 3 columns. Each block of content contains a heading, description, and link. We are using flexbox to display the blocks in a row such that the height of the row is taken up by the tallest element. However, we are not able to always align the link at the bottom and it always seems to be place right below each description.
How can we align the link in the bottom of each block and have each block still be the height of the tallest block using flexbox?
Here is what we have tried: https://codepen.io/userrj/pen/WYXoOO
Code explained:
each block is surrounded by .bkg--grey so you can see the block is taking the height of the tallest block as expected.
border is added to each element with flex__item so you can see how much space it is taking up.
each block contains: heading, description, and link from top down (column)
Current issue:
Desired output
We are hoping to not use float or position: absolute to get this done.
You need to make article a flex container and adjust some alignment:
article {
display: flex;
}
.flex__item > div:last-child {
margin-top:auto;
}
Full code:
.flex__item {
display: flex;
justify-content: center;
align-items: stretch;
flex: 0 1 auto;
flex-direction: column;
}
.flex__col {
display: flex;
justify-content: center;
align-items: stretch;
}
.flex__wrapper {
display: flex;
align-items: stretch;
justify-content: flex-start;
flex-wrap: wrap;
flex-direction: row;
flex: 0 1 auto;
}
.flex__item {
padding: 16px;
border: 1px solid black;
}
.bkg--grey {
background-color: #ddd;
}
.col--sm-12 {
width: 100%;
}
.col--md-6 {
width: 50%;
}
.col--lg-4 {
width: 33.33%;
}
/*added this*/
article {
display: flex;
}
.flex__item > div:last-child {
margin-top:auto;
}
/**/
[class*=col--] {
box-sizing: border-box;
padding: 16px;
}
<section class="flex__wrapper">
<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
<article class="bkg--grey">
<div class="flex__item">
<div>
<h4>Some Efficiently</h4>
<p>Efficiently enhance frictionless markets without distinctive deliverables. </p>
</div>
<div>Read More</div>
</div>
</article>
</div>
<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
<article class="bkg--grey">
<div class="flex__item">
<div>
<h4>Some Objectively promote</h4>
<p>Objectively promote enterprise-wide strategic theme areas rather than process-centric catalysts for change. Completely procrastinate sticky best practices and corporate sources. Distinctively unleash superior metrics via go forward alignments. Uniquely reconceptualize plug-and-play e-services through collaborative solutions. Progressively maximize adaptive experiences with. </p>
</div>
<div>Read More</div>
</div>
</article>
</div>
<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
<article class="bkg--grey">
<div class="flex__item">
<div>
<h4>Completely create</h4>
<p>Completely create equity invested relationships for client-focused paradigms. Distinctively benchmark exceptional information before corporate materials. Compellingly pontificate 2.0. </p>
</div>
<div>Read More</div>
</div>
</article>
</div>
<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
<article class="bkg--grey">
<div class="flex__item">
<div>
<h4>Distinctively deliver</h4>
<p>Distinctively deliver one-to-one potentialities with excellent resources. Collaboratively.</p>
</div>
<div>Read More</div>
</div>
</article>
</div>
<div class="col--sm-12 col--md-6 col--lg-4 flex__col">
<article class="bkg--grey">
<div class="flex__item">
<div>
<h4>Authoritatively facilitate</h4>
<p>Authoritatively facilitate sustainable portals through cross-platform catalysts for change. Monotonectally transform e-business total linkage without front-end action items.</p>
</div>
<div>Read More</div>
</div>
</article>
</div>
</section>
I'm currently working on my code where i tried making a responsive image gallery with a hover effect. At my first code I created, the effects are working great. However, it is not responsive as it stays in 4 rows always. Please see this Codepen 1
When I tried to change some of the contents of my style.css using flexbox, i was able to make it responsive and change its size depending on the window size. However, whenever you hover to the image, the hover box does not align with the container itself. Please see this Codepen2
The codes are written on the codepen itself. The only code i changed in the 1st code to the 2nd one is this (I commented the previous code instead of removing it to remember which part i changed:
.container
{
/*width: 1280px;
margin: 70px auto 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;*/
margin: .5vw;
font-size: 0;
display: -ms-flexbox;
-ms-flexbox-wrap : wrap;
-ms-flexbox-direction: column;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
display: -webkit-box;
display: flex;
}
.container .box
{
/*position: relative;
width: 300px;
height: 300px;
background: #ff0;
margin: 10px;
box-sizing: border-box;
display: inline-block;*/
-webkit-box-flex: auto;
-ms-flex: auto;
flex: auto;
width: 300px;
margin: .5vw;
}
.container .box .imgBox img
{
/*max-width: 100%;*/
width: 100%;
height: auto; /*added this*/
transition: transform 2s;
}
Please do help me figure out why the hover position is not working. Thanks
You could modify the width's of the container so that it size is defined by relative positioning, this will solve your issue.
The only change that is to be made is to the div with class container, shown below.
.container {
width: 80%;
margin: 0px auto;
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
}
Please check the below example.
body {
margin: 0;
padding: 0;
background: #262626;
font-family: sans-serif
}
.container {
width: 80%;
margin: 0px auto;
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
}
.container .box {
position: relative;
width: 300px;
height: 300px;
background: #ff0;
margin: 10px;
box-sizing: border-box;
display: inline-block;
}
.container .box .imgBox {
position: relative;
overflow: hidden;
}
.container .box .imgBox img {
max-width: 100%;
transition: transform 2s;
}
.container .box:hover .imgBox img {
transform: scale(1.2);
}
.container .box .details {
position: absolute;
top: 10px;
left: 10px;
bottom: 10px;
right: 10px;
background: rgba(0, 0, 0, .8);
transform: scaleY(0);
transition: transform .5s;
}
.container .box:hover .details {
transform: scaleY(1);
}
.container .box .details .content {
position: absolute;
top: 50%;
transform: translateY(-50%);
text-align: center;
padding: 15p;
color: #fff;
}
.container .box .details .content h1 {
margin: 0;
padding: 0;
font-size: 20px;
color: #ff0;
}
.container .box .details .content p {
margin: 10px 0 0;
padding: 0;
}
<div class="container">
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/1.jpg">
</div>
<div class="details">
<div class="content">
<h1> Snow Queen Elsa </h1>
<p>Elsa is the daughter of Agnarr and Iduna, older sister of Anna, and queen of Arendelle. Elsa was born with the powers to manipulate ice and snow and used them to entertain her sister. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/2.jpg">
</div>
<div class="details">
<div class="content">
<h1> The Little Mermaid Ariel </h1>
<p>Ariel as she appears in her mermaid form in Disney's The Little Mermaid. Ariel is a fictional character and the title character of Walt Disney Pictures' 28th animated film The Little Mermaid (1989). She is often rebellious, and in the first film,
she longs to be a part of the human world. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/3.jpg">
</div>
<div class="details">
<div class="content">
<h1> Sleeping Beauty Aurora </h1>
<p>Princess Aurora, also known as Sleeping Beauty or Briar Rose, is a fictional character who appears in Walt Disney Pictures' animated feature film Sleeping Beauty (1959). Originally voiced by singer Mary Costa, Aurora is the only daughter of King
Stefan and Queen Leah. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/4.jpg">
</div>
<div class="details">
<div class="content">
<h1> Aladdin's Jasmine </h1>
<p>Princess Jasmine is the deuteragonist of Disney's 1992 animated feature film, Aladdin. She is from the Middle Eastern kingdom of Agrabah where her father, the Sultan, rules. Jasmine was born into a role and society that treats her as an object
and a tool, rather than a person </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/5.jpg">
</div>
<div class="details">
<div class="content">
<h1> Rupunzel </h1>
<p>Princess Rapunzel (voiced by Mandy Moore) is more assertive in character, and was born a princess. Her long blonde hair has magical healing and restoration powers. A woman named Mother Gothel (voiced by Donna Murphy) kidnaps Rapunzel for her magical
hair which would help maintain her youth. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/5.jpg">
</div>
<div class="details">
<div class="content">
<h1> Megara </h1>
<p>In Greek mythology, Megara was the oldest daughter of Creon, king of Thebes. Megara was offered by her father to Hercules because he defended Thebes. She had two children, a boy and a girl, but was killed with both of them by Hercules in excess
of madness caused by Hera. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="c">
</div>
<div class="details">
<div class="content">
<h1> Belle The Beauty </h1>
<p>Belle is a fictional character who appears in Walt Disney Pictures' animated feature film Beauty and the Beast (1991). Originally voiced by American actress and singer Paige O'Hara, Belle is the non-conforming daughter of an inventor who yearns
to abandon her predictable village life in return for adventure. </p>
</div>
</div>
</div>
<div class="box">
<div class="imgBox">
<img src="http://www.gstatic.com/webp/gallery/1.jpg">
</div>
<div class="details">
<div class="content">
<h1> Mulan The Great Warrior Of China </h1>
<p>Mulan (full name Fa Mulan) is a character, inspired by an actual historic figure, who appears in Walt Disney Pictures' animated feature film Mulan (1998), as well as its sequel Mulan II (2004). </p>
</div>
</div>
</div>
</div>
I have a design below which I am trying to replicate in HTML and CSS:
Note: I have written text Margin and Padding to make things easy to understand. It will not come in the actual design
At this moment, I am able to get this in my fiddle.
The only thing which is not matching the above design in the fiddle are the paragraphs (eg: Our main goal, Among our biggest, etc) in every box which don't have line break. I am considering boxes as every job-opening with titles (Back-end .., Front-end .., etc) and paragraphs (eg: Our main goal, Among our biggest, etc).
The CSS for every box is:
.firstrow {
display: inline-block;
width: 100%;
}
.firstrow #front-end {
text-align: center;
width: 50%;
height: 250px;
float: left;
background-repeat: no-repeat;
display: flex;
align-items: center;
background-size: 100% 100%;
justify-content: center;
}
Here is a improved version of your code, just using flexbox, without using floats or anything else.
h2 {
text-align: center;
font-size: 2.8rem;
color: #444444;
}
.row {
display: flex;
flex-wrap: wrap;
padding: 5%;
}
.row>div {
padding: 5%;
background: gray;
margin: 15px;
display: flex;
flex-flow: column wrap;
align-items: center;
justify-content: center;
text-align: center;
flex: 1;
box-sizing:border-box
}
<div class="job-openings">
<h2>Seems Interesting? Apply Now</h2>
<div class="row">
<div id="back-end">
<h3>Back-end Developer</h3>
<p> Our main goal is to build and maintain the online platform and...</p>
</div>
<div id="front-end">
<h3>Front-end Web Developer</h3>
<p>Among our biggest priorities are interface design and user experience...</p>
</div>
<div id="graphics">
<h3>Graphics Designer</h3>
<p> We believe in the power of design. Our designers are motivated, creative and...</p>
</div>
<div id="sales">
<h3>Sales & Marketing</h3>
<p>Our Marketing team is focussed on driving growth and building a brand that customers love...</p>
</div>
</div>
</div>
Op's Comment to answer:
Back-end and front-end will come in one row with graphics designer and
sales and marketing in another row.
Assuming you want to have always 2 rows, then you can use flex:0 50% instead of flex:1, in this case flex: 0 calc(50% - 30px) to take in count the margin
h2 {
text-align: center;
font-size: 2.8rem;
color: #444444;
}
.row {
display: flex;
flex-wrap: wrap;
padding: 5%;
}
.row>div {
padding: 5%;
background: gray;
margin: 15px;
display: flex;
flex-flow: column wrap;
align-items: center;
justify-content: center;
text-align: center;
flex: 0 calc(50% - 30px);
box-sizing:border-box
}
<div class="job-openings">
<h2>Seems Interesting? Apply Now</h2>
<div class="row">
<div id="back-end">
<h3>Back-end Developer</h3>
<p> Our main goal is to build and maintain the online platform and...</p>
</div>
<div id="front-end">
<h3>Front-end Web Developer</h3>
<p>Among our biggest priorities are interface design and user experience...</p>
</div>
<div id="graphics">
<h3>Graphics Designer</h3>
<p> We believe in the power of design. Our designers are motivated, creative and...</p>
</div>
<div id="sales">
<h3>Sales & Marketing</h3>
<p>Our Marketing team is focussed on driving growth and building a brand that customers love...</p>
</div>
</div>
</div>