I know there are similar questions but I can't seem to implement the answers successfully so i'd thought i'd ask to try get an answer for my context.
I'm trying to keep a div with class .product-info fixed on the screen as you scroll down the page, with in it's parent div (.product-info-container). Once the fixed div reaches the bottom of the parent it should stop, i've tried using position:fixed but it fixes the div to the window, not the parent div.
Any help would be appreciated.
HTML:
/* Container */
.product-wrapper {
width: 100vw;
margin: auto;
}
.product-introduction {
height: auto;
min-height: calc(100vh - 140px);
width: 70vw;
min-width: 1400px;
margin: auto;
margin-top: 140px;
margin-bottom: 0;
display: flex;
flex-direction: row;
position: relative;
}
.product-image-grid {
height: auto;
width: 60%;
display: flex;
flex-direction: row;
flex-grow: 1;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: flex-start
}
.image-container {
margin: 10px;
padding: 10px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: whitesmoke;
}
.image-container.small {
width: calc(50% - 40px);
height: 500px
}
.Product-Image {
height: 100%;
}
.image-container.large {
width: calc(100% - 10px);
height: 1000px;
}
.product-info-container {
height: 1500px;
min-height: calc(10vh - 140px);
width: calc(550px - 25px);
min-width: calc(550px - 25px);
position: relative;
padding-left: 25px;
}
.product-info {
position: fixed;
height: auto;
width: calc(550px - 20px);
padding: 10px;
}
h1.product-title {
font-family: "Magistral_Bold";
font-size: 32px;
letter-spacing: 0.05em;
text-transform: uppercase;
margin-top: 0;
margin-bottom: 0;
}
.icon-bar {
width: 50%;
min-width: 300px;
height: auto;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 25px;
margin-bottom: 25px;
}
.intro-feature-icon {
width: 150px;
}
.intro-feature-icon:first-child {
margin-left: 0;
}
.intro-feature-icon:nth-of-type(2) {
width: 100px;
}
.price-bar {
width: 50%;
height: auto;
display: flex;
flex-direction: row;
justify-content: unset;
align-items: flex-end;
}
.price-bar h2 {
margin-left: 0;
margin-right: 50px;
}
.currency-selector {
color: #919191;
font-size: 18px;
margin-bottom: 5px !important;
margin-right: 15px;
cursor: pointer;
}
.currency-selector.selected {
color: black !important;
}
.currency-selector:hover {
text-decoration: underline;
}
.wtb-cta {
width: auto;
padding: 16px 32px;
background: black;
text-align: center;
margin-top: 50px;
margin-bottom: 0;
}
.accordion {
cursor: pointer;
padding: 0;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 50px;
border-bottom: 1px solid black;
}
.accordion:after {
content: '\02795';
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}
.active,
.accordion:hover {}
.active:after {
content: "\2796";
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
<div class="product-wrapper">
<div class="product-introduction">
<div class="product-image-grid">
<div class="image-container small">
<img src="Images/01-Product-Images/Test-image-1.png" alt="Test Image 1" class="Product-Image One">
</div>
<div class="image-container small">
<img src="Images/01-Product-Images/Test-image-2.png" alt="Test Image 2" class="Product-Image Two">
</div>
<div class="image-container large">
<img src="Images/01-Product-Images/Test-image-3.png" alt="Test Image 3" class="Product-Image Three">
</div>
</div>
<div class="product-info-container">
<div class="product-info">
<h1 class="product-title no-shadow">Hinterland</h1>
<h4 class="h4-black no-shadow">DRY2DRY™ TRI-LAMINATE JACKET</h4>
<div class="icon-bar">
<img src="Images/02-Icons/Tech-Icons/Materials/TriLaminate/TriLaminateD2D-square-black.png" alt="Tri Laminate Logo" class="intro-feature-icon">
<img src="Images/02-Icons/Tech-Icons/CE-Icons/ce-approved.png" alt="CE Approved Logo" class="intro-feature-icon">
</div>
<p class="black no-shadow">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Veritatis velit aperiam soluta maiores fugiat facere dolorum obcaecati, repellat commodi eveniet deserunt doloribus, esse magnam alias qui eos officia reprehenderit? Dolorum.
</p>
<div class="price-bar">
<h2 class="h2-min black no-shadow">£299.99</h2>
<p class="currency-selector no-shadow selected"> £ </p>
<p class="currency-selector no-shadow "> $ </p>
</div>
<a href="#">
<div class="wtb-cta">
<h3>WHERE TO BUY</h2>
</div>
</a>
<button class="accordion">
<h3 class="black no-shadow">DESCRIPTION</h3>
</button>
<div class="panel">
<p class="no-shadow black">Lorem ipsum...</p>
</div>
<button class="accordion">
<h3 class="black no-shadow">ADDITIONAL INFO</h3>
</button>
<div class="panel">
<p class="no-shadow black">Lorem ipsum...</p>
</div>
</div>
</div>
</div>
</div>
I hope this is what u r expecting.
Add position:sticky and top:0 to .product-info class.
.product-info {
position:sticky;
top:0px;
height: auto;
width: calc(550px - 20px);
padding: 10px;
}
/* Container */
.product-wrapper {
width: 100vw;
margin: auto;
}
.product-introduction {
height: auto;
min-height: calc(100vh - 140px);
width: 70vw;
min-width: 1400px;
margin: auto;
margin-top: 140px;
margin-bottom: 0;
display: flex;
flex-direction: row;
position: relative;
}
.product-image-grid {
height: auto;
width: 60%;
display: flex;
flex-direction: row;
flex-grow: 1;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: flex-start
}
.image-container {
margin: 10px;
padding: 10px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: whitesmoke;
}
.image-container.small {
width: calc(50% - 40px);
height: 500px
}
.Product-Image {
height: 100%;
}
.image-container.large {
width: calc(100% - 10px);
height: 1000px;
}
.product-info-container {
height: 1500px;
min-height: calc(10vh - 140px);
width: calc(550px - 25px);
min-width: calc(550px - 25px);
position: relative;
padding-left: 25px;
}
.product-info {
position:sticky;
top:0px;
height: auto;
width: calc(550px - 20px);
padding: 10px;
}
h1.product-title {
font-family: "Magistral_Bold";
font-size: 32px;
letter-spacing: 0.05em;
text-transform: uppercase;
margin-top: 0;
margin-bottom: 0;
}
.icon-bar {
width: 50%;
min-width: 300px;
height: auto;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 25px;
margin-bottom: 25px;
}
.intro-feature-icon {
width: 150px;
}
.intro-feature-icon:first-child {
margin-left: 0;
}
.intro-feature-icon:nth-of-type(2) {
width: 100px;
}
.price-bar {
width: 50%;
height: auto;
display: flex;
flex-direction: row;
justify-content: unset;
align-items: flex-end;
}
.price-bar h2 {
margin-left: 0;
margin-right: 50px;
}
.currency-selector {
color: #919191;
font-size: 18px;
margin-bottom: 5px !important;
margin-right: 15px;
cursor: pointer;
}
.currency-selector.selected {
color: black !important;
}
.currency-selector:hover {
text-decoration: underline;
}
.wtb-cta {
width: auto;
padding: 16px 32px;
background: black;
text-align: center;
margin-top: 50px;
margin-bottom: 0;
}
.accordion {
cursor: pointer;
padding: 0;
width: 100%;
text-align: left;
border: none;
outline: none;
transition: 0.4s;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: 50px;
border-bottom: 1px solid black;
}
.accordion:after {
content: '\02795';
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}
.active,
.accordion:hover {}
.active:after {
content: "\2796";
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
<div class="product-wrapper">
<div class="product-introduction">
<div class="product-image-grid">
<div class="image-container small">
<img src="Images/01-Product-Images/Test-image-1.png" alt="Test Image 1" class="Product-Image One">
</div>
<div class="image-container small">
<img src="Images/01-Product-Images/Test-image-2.png" alt="Test Image 2" class="Product-Image Two">
</div>
<div class="image-container large">
<img src="Images/01-Product-Images/Test-image-3.png" alt="Test Image 3" class="Product-Image Three">
</div>
</div>
<div class="product-info-container">
<div class="product-info">
<h1 class="product-title no-shadow">Hinterland</h1>
<h4 class="h4-black no-shadow">DRY2DRY™ TRI-LAMINATE JACKET</h4>
<div class="icon-bar">
<img src="Images/02-Icons/Tech-Icons/Materials/TriLaminate/TriLaminateD2D-square-black.png" alt="Tri Laminate Logo" class="intro-feature-icon">
<img src="Images/02-Icons/Tech-Icons/CE-Icons/ce-approved.png" alt="CE Approved Logo" class="intro-feature-icon">
</div>
<p class="black no-shadow">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Veritatis velit aperiam soluta maiores fugiat facere dolorum obcaecati, repellat commodi eveniet deserunt doloribus, esse magnam alias qui eos officia reprehenderit? Dolorum.
</p>
<div class="price-bar">
<h2 class="h2-min black no-shadow">£299.99</h2>
<p class="currency-selector no-shadow selected"> £ </p>
<p class="currency-selector no-shadow "> $ </p>
</div>
<a href="#">
<div class="wtb-cta">
<h3>WHERE TO BUY</h2>
</div>
</a>
<button class="accordion">
<h3 class="black no-shadow">DESCRIPTION</h3>
</button>
<div class="panel">
<p class="no-shadow black">Lorem ipsum...</p>
</div>
<button class="accordion">
<h3 class="black no-shadow">ADDITIONAL INFO</h3>
</button>
<div class="panel">
<p class="no-shadow black">Lorem ipsum...</p>
</div>
</div>
</div>
</div>
</div>
Related
I don't know where that box thingy comes from under the (-) button. It stretches when the single-card div becomes bigger. When I take out rating div from the single-card div, there is no box thingy under the (-) button. Can anyone please help? Thank you.
I don't know where that box thingy comes from under the (-) button. It stretches when the single-card div becomes bigger. When I take out rating div from the single-card div, there is no box thingy under the (-) button. Can anyone please help? Thank you.
*,*::before, *::after {
margin: 0;
padding: 0;
box-sizing: border-box;
--violet: #8F00FF;
--usernamecolor: rgb(43, 72, 83);
}
.single-card {
margin-top: 60px;
display: flex;
justify-content: center;
background-color: white;
}
.rating {
border-radius: 8px;
width: 35px;
background-color: #f0f0f0;
display: flex;
flex-direction: column;
align-items: center;
box-shadow: -5px 0px 8px rgba(172, 169, 169, 0.1);
overflow: hidden;
margin-right: 15px;
}
button {
border: none;
height: 30px;
border-radius: 8px;
align-items: center;
color: var(--violet);
font-weight: bold;
cursor: pointer;
opacity: 0.7;
}
button:hover {
color: purple;
opacity: 1;
}
.rating span {
height: 30px;
display: flex;
justify-content: center;
align-items: center;
color: var(--violet);
font-weight: bold;
}
.wrapper {
width: 800px;
padding: 8px;
}
.top {
display: flex;
align-content: center;
justify-content: space-between;
}
.top .top-left {
display: flex;
}
.top img {
width: 40px;
border-radius: 100%;
margin-right: 15px;
border: 1px solid blue;
}
.top .username {
padding-top: 5px;
margin-bottom: 1px;
margin-right: 10px;
font-weight: bold;
color: var(--usernamecolor);
}
.top .date {
padding-top: 5px;
margin-bottom: 1px;
opacity: 0.8;
}
.top button {
background-color: white;
display: flex;
align-items: center;
}
<div class="single-card">
<div class="rating">
<button>+</button>
<span>12</span>
<button>-</button>
</div>
<div class="wrapper">
<div class="top">
<div class="top-left">
<div><img src="photo.jpg" alt=""></div>
<p class="username">amyrobson</p>
<p class="date">1 month ago</p>
</div>
<button><box-icon name='reply'></box-icon>Reply</button>
</div>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Vero at ut facere. Quae eos soluta nesciunt perspiciatis neque a ipsa omnis eligendi nemo quidem similique, autem minima? Facilis, voluptatibus voluptatum.</p>
</div>
</div>
The - display: flex on .single-card is the cause, in the flexbox container if some items are taller than others, all items will stretch along the cross axis to fill its full size.
add to the container(.single-card): align-items: center / start / end (choose one option as it feet’s your design)
you can read more about it - https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox
I am able to make a vertical flex card with an image on top and it will maintain 16:9 aspect ratio always. My vertical flex card code
.card {
display: flex;
flex-direction: column;
margin: 0.75rem;
}
.card .card-img {
position: relative;
padding-bottom: 56.25%;
}
.card .card-img img {
position: absolute;
object-fit: cover;
width: 100%;
height: 100%;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.card .card-body {
margin-bottom: 0.75rem;
display: flex;
flex-direction: column;
}
.card .card-body a {
text-decoration: none;
font-size: clamp(1rem, 0.6505rem + 0.9709vw, 1.5rem);
color: #3e3700;
font-weight: 500;
}
.card .card-body .card-title {
font-size: clamp(1.125rem, 0.5133rem + 1.699vw, 2rem);
font-weight: 500;
line-height: 1;
}
.card .card-body .card-description {
font-size: clamp(1rem, 0.6505rem + 0.9709vw, 1.5rem);
font-weight: 300;
margin-bottom: 0.75rem;
}
<div class="card">
<div class="card-img">
<img
src="https://via.placeholder.com/150"
alt="img"
/>
</div>
<div class="card-body">
<h2 class="card-title">
Lorem ipsum dolor sit, amet consectetur
adipisicing elit. Ratione, cumque?
</h2>
</div>
</div>
But I want to make it horizontal and I am stuck. Whenever I change the flex-direction to row flex-direction: row; it does not work. I always want the image to be in a 16:9 aspect ratio. My progress
.card {
display: flex;
flex-direction: row;
margin: 0.75rem;
}
.card.card-h .card-img {
width: 40%;
}
.card.card-h .card-body {
width: 60%;
}
.card .card-img {
position: relative;
padding-bottom: 56.25%;
}
.card .card-img img {
position: absolute;
object-fit: cover;
width: 100%;
height: 100%;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.card .card-body {
margin-bottom: 0.75rem;
display: flex;
flex-direction: column;
}
.card .card-body a {
text-decoration: none;
font-size: clamp(1rem, 0.6505rem + 0.9709vw, 1.5rem);
color: #3e3700;
font-weight: 500;
}
.card .card-body .card-title {
font-size: clamp(1.125rem, 0.5133rem + 1.699vw, 2rem);
font-weight: 500;
line-height: 1;
}
.card .card-body .card-description {
font-size: clamp(1rem, 0.6505rem + 0.9709vw, 1.5rem);
font-weight: 300;
margin-bottom: 0.75rem;
}
<div class="card card-h">
<div class="card-img">
<img
src="https://via.placeholder.com/150"
alt="img"
/>
</div>
<div class="card-body">
<h2 class="card-title">
Lorem ipsum dolor sit, amet consectetur
adipisicing elit. Ratione, cumque?
</h2>
</div>
</div>
Here is the aspect-ratio example with old browser support. I copied the card layout from bootstrap.
Please view in "Full Page"
.mycard .card-img {
aspect-ratio: 16 / 9;
object-fit: cover;
}
/*Old Browser Support*/
#supports not (aspect-ratio: 16 / 9) {
.mycard {
position: relative;
height: 0;
padding-bottom: 56.25%;
}
.mycard .card-img {
width: 100%;
height: 100%;
position: absolute;
top: 0;
bottom: 0;
background: red;
/* just for illustration */
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div class="card mb-3" style="max-width: 540px;">
<div class="row no-gutters">
<div class="col-md-4">
<div class="mycard">
<img src="https://via.placeholder.com/150" class="card-img" alt="">
</div>
</div>
<div class="col-md-8">
<div class="card-body">
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>
I have a problem making the page responsive. The property flex-wrap: nowrap is not working properly. Can you please help me to find out where the problem is?
.logo {
text-decoration: none;
color: white;
}
.header {
width: 100%;
max-width: 960px;
min-width: 460px;
min-height: 100px;
margin: 0 auto 30px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
box-sizing: border-box;
}
.logo {
background: black;
width: 150px;
min-height: 50px;
align-items: center;
display: flex;
flex: none;
margin: 0 10px 40px;
justify-content: center;
}
.contnet {
background: black;
min-height: 50px;
font-size: 20px;
color: white;
margin-bottom: 40px;
flex-basis: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.bottom-content {
min-height: 50px;
display: flex;
flex-wrap: wrap;
flex: auto;
background: black;
width: 100%;
color: white;
font-size: 20px;
justify-content: center;
align-items: center;
}
.main {
width: 100%;
max-width: 960px;
min-width: 430px;
display: flex;
flex: auto;
margin: auto;
box-sizing: border-box
}
.grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.griditem {
margin-bottom: 30px;
display: flex;
flex-basis: calc(33.33% - 20px * 2/3);
flex-wrap: wrap;
}
.img {
width: 200px;
height: 200px;
background-color: black;
margin: 0 auto;
}
.title {
text-align: center;
}
.grid-content {
flex: 0 1 100%;
}
.text {
text-align: center;
}
.footer {
width: 100%;
background-color: black;
max-width: 960px;
min-width: 460px;
margin: 0 auto;
padding: 15px;
color: white;
text-align: center;
}
.img {
color: white;
}
#media screen and (max-width: 800px) {
.contnet {
display: none
}
.griditem {
flex-wrap: nowrap;
flex-basis: 100%;
}
.img {
flex: 0 0 auto;
}
.griditem:nth-child(even) {
margin: 0 0 0 30px;
order: 2
}
.footer{
display: none
}
.griditem:nth-child(odd) {
margin: 0 30px 0 0;
}
}
<hrader class="header">
Logo
<div class="contnet">Content</div>
<div class="bottom-content">2</div>
</hrader>
<main class="main">
<div class="grid">
<div class="griditem">
<div class="img">1</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
<div class="grid">
<div class="griditem">
<div class="img">2</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div> <div class="grid">
<div class="griditem">
<div class="grid-content">
<div class="img">3</div>
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
</main>
<footer class="footer">
Footer
</footer>
Fiddle: https://jsfiddle.net/q9bcpr4L/
Add flex-wrap to main and flex-basis to grid
.main {
width: 100%;
max-width: 960px;
min-width: 430px;
display: flex;
flex: auto;
flex-wrap:wrap;
margin: auto;
box-sizing: border-box
}
.grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
flex-basis: calc(33.33% - 20px * 2/3);
}
That's what do you want? I:
Moved .title and .text elements inside .grid-content element.
Added flex-wrap: wrap to .main selector.
Fixed some typos.
.logo {
text-decoration: none;
color: white;
}
.header {
width: 100%;
max-width: 960px;
min-width: 460px;
min-height: 100px;
margin: 0 auto 30px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
box-sizing: border-box;
}
.logo {
background: black;
width: 150px;
min-height: 50px;
align-items: center;
display: flex;
flex: none;
margin: 0 10px 40px;
justify-content: center;
}
.content {
background: black;
min-height: 50px;
font-size: 20px;
color: white;
margin-bottom: 40px;
flex-basis: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.bottom-content {
min-height: 50px;
display: flex;
flex-wrap: wrap;
flex: auto;
background: black;
width: 100%;
color: white;
font-size: 20px;
justify-content: center;
align-items: center;
}
.main {
width: 100%;
max-width: 960px;
min-width: 430px;
display: flex;
flex: auto;
margin: auto;
box-sizing: border-box;
}
.grid {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.griditem {
margin-bottom: 30px;
display: flex;
flex-basis: calc(33.33% - 20px * 2/3);
flex-wrap: wrap;
}
.img {
width: 200px;
height: 200px;
background-color: black;
margin: 0 auto;
}
.title {
text-align: center;
}
.grid-content {
flex: 0 1 100%;
}
.text {
text-align: center;
}
.footer {
width: 100%;
background-color: black;
max-width: 960px;
min-width: 460px;
margin: 0 auto;
padding: 15px;
color: white;
text-align: center;
}
.img {
color: white;
}
#media screen and (max-width: 800px) {
.content {
display: none
}
.main {
flex-wrap: wrap;
}
.griditem {
flex-wrap: nowrap;
flex-basis: 100%;
}
.img {
flex: 0 0 auto;
}
.griditem:nth-child(even) {
margin: 0 0 0 30px;
order: 2
}
.footer {
display: none
}
.griditem:nth-child(odd) {
margin: 0 30px 0 0;
}
}
<header class="header">
Logo
<div class="content">Content</div>
<div class="bottom-content">2</div>
</header>
<main class="main">
<div class="grid">
<div class="griditem">
<div class="img">1</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
<div class="grid">
<div class="griditem">
<div class="img">2</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
<div class="grid">
<div class="griditem">
<div class="img">3</div>
<div class="grid-content">
<h1 class="title">Title</h1>
<p class="text">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Distinctio neque magnam amet, praesentium vel illum error autem voluptatibus veniam consequuntur.</p>
</div>
</div>
</div>
</main>
<footer class="footer">
Footer
</footer>
I am try to write markup and css for table based design in flexbox module !
Here is the Design
Here is the Markup
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.header-area {
margin: 50px auto;
max-width: 800px;
}
.flextable-header {
width: 100%;
background: #f7f7f7;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
height: 45px;
}
.flextable-header span {
width: 20%;
text-align: center;
}
.flextable-header .amount {
flex: auto;
text-align: right;
padding-right: 30px;
}
.flextable-content {
height: 100px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.flextable-content div {
width: 20%;
text-align: center;
}
.text-left {
display: flex;
flex-direction: column;
justify-content: center;
font-size: 15px;
height: 100%;
}
#dates {
text-align: left;
display: inline-block;
}
.flextable-content .money {
flex: auto;
text-align: right;
padding-right: 30px;
}
.flextable-content div img {
width: 120px;
height: 80px;
border-radius: 5px;
object-fit: cover;
object-position: center;
}
<div class="header-area">
<div class="flextable-header">
<span>Photos</span>
<span>Date</span>
<span class="amount">Amount</span>
</div>
<div class="flextable-content">
<div><img src="https://i.imgur.com/VzV3NwJ.jpg" alt=""></div>
<div class="text-left">
<div>Business</div><br/>
<div id="dates">25 December 2019</div>
</div>
<div class="money">3500 <small>Taka</small></div>
</div>
</div>
I'm stack at date alignment and bottom border as per design which I put on top !
You can simplify your code like below and use a simple gradient for the line:
* {
box-sizing: border-box;
}
.header-area {
margin: 50px auto;
max-width: 800px;
}
.flextable-header,
.flextable-content{
background: #f7f7f7;
display: flex;
align-items: center;
height: 45px;
}
.flextable-header > span:first-child {
min-width:130px;
text-align:center;
}
.flextable-header .amount,
.flextable-content .money{
margin-left:auto;
padding-right: 30px;
}
.flextable-content {
height: 100px;
background:linear-gradient(grey,grey) bottom right/calc(100% - 130px) 1px no-repeat;
padding-bottom:10px;
margin:10px 0;
}
.flextable-content:last-child {
background:none;
}
.flextable-content > img {
max-width:120px;
border-radius: 5px;
}
.text-left {
padding-left:10px;
font-size: 15px;
}
<div class="header-area">
<div class="flextable-header">
<span>Photos</span>
<span>Date</span>
<span class="amount">Amount</span>
</div>
<div class="flextable-content">
<img src="https://i.imgur.com/VzV3NwJ.jpg" alt="">
<div class="text-left">
<div>Business</div>
<div class="dates">25 December 2019</div>
</div>
<div class="money">3500 <small>Taka</small></div>
</div>
<div class="flextable-content">
<img src="https://i.imgur.com/VzV3NwJ.jpg" alt="">
<div class="text-left">
<div>Business</div>
<div class="dates">25 December 2019</div>
</div>
<div class="money">3500 <small>Taka</small></div>
</div>
<div class="flextable-content">
<img src="https://i.imgur.com/VzV3NwJ.jpg" alt="">
<div class="text-left">
<div>Business</div>
<div class="dates">25 December 2019</div>
</div>
<div class="money">3500 <small>Taka</small></div>
</div>
</div>
Add width: 100% to your dates (use it as class, not id, id should be unique)
Add a spacer div at the bottom.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.header-area {
margin: 50px auto;
max-width: 800px;
}
.flextable-header {
width: 100%;
background: #f7f7f7;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
height: 45px;
}
.flextable-header span {
width: 20%;
text-align: center;
}
.flextable-header .amount {
flex: auto;
text-align: right;
padding-right: 30px;
}
.flextable-content {
height: 100px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.flextable-content div {
width: 20%;
text-align: center;
}
.text-left {
display: flex;
flex-direction: column;
justify-content: center;
font-size: 15px;
height: 100%;
}
div.dates {
text-align: left;
display: inline-block;
width: 100%;
}
.flextable-content .money {
flex: auto;
text-align: right;
padding-right: 30px;
}
.flextable-content div img {
width: 120px;
height: 80px;
border-radius: 5px;
object-fit: cover;
object-position: center;
}
.spacer{
height: 1px;
background-color: #e5e5e5;
width: 78%;
float: right;
margin-right: 2%;
}
<div class="header-area">
<div class="flextable-header">
<span>Photos</span>
<span>Date</span>
<span class="amount">Amount</span>
</div>
<div class="flextable-content">
<div><img src="https://i.imgur.com/VzV3NwJ.jpg" alt=""></div>
<div class="text-left">
<div>Business</div><br/>
<div class="dates">25 December 2019</div>
</div>
<div class="money">3500 <small>Taka</small></div>
</div>
<div class="spacer"></div>
</div>
And to give some rest for other users, you can also change your HTML structure and use a border as a separator
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.header-area {
margin: 50px auto;
max-width: 800px;
}
.flextable-header {
width: 100%;
background: #f7f7f7;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
height: 45px;
}
.flextable-header span {
width: 20%;
text-align: center;
}
.flextable-header .amount {
flex: auto;
text-align: right;
padding-right: 30px;
}
.flextable-content {
height: 100px;
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.img-container {
flex-basis: 20%;
flex-shrink: 0;
flex-grow: 0;
text-align: center;
}
.border-container{
flex-basis: 78%;
flex-shrink: 0;
flex-grow: 0;
display: flex;
align-items: center;
border-bottom: 1px solid #e5e5e5;
margin-right: 2%;
padding-bottom: 15px;
height: 100%;
}
.text-left {
display: flex;
flex-direction: column;
justify-content: center;
font-size: 15px;
height: 100%;
}
div.dates {
text-align: left;
display: inline-block;
width: 100%;
}
.flextable-content .money {
flex: auto;
text-align: right;
padding-right: 30px;
}
.flextable-content div img {
width: 120px;
height: 80px;
border-radius: 5px;
object-fit: cover;
object-position: center;
}
<div class="header-area">
<div class="flextable-header">
<span>Photos</span>
<span>Date</span>
<span class="amount">Amount</span>
</div>
<div class="flextable-content">
<div class="img-container"><img src="https://i.imgur.com/VzV3NwJ.jpg" alt=""></div>
<div class="border-container">
<div class="text-left">
<div>Business</div><br/>
<div class="dates">25 December 2019</div>
</div>
<div class="money">3500 <small>Taka</small></div>
</div>
</div>
</div>
I have some divs and an image inside, and the css is working as I want it (almost), except that when I refresh the page or load it for the first time, the image width takes the entire div width, which ignores the css properties. It only notices the css properties when the window is resized (e.g. by 1px), or if in google developer tools, I toggle the max-width off and then back on, or if I toggle the parent div display off and then back on.
You can see this is the case in this video I just took:
https://youtu.be/YLx4NjKuzMo
Bear in mind, this issue occurs after about 880px width.
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
width: 100%;
}
header {
height: 15vh;
min-height: 80px;
background-color: #262626;
}
h2 {
font-size: 3vw;
color: #f60;
}
ul {
line-height: 3.5vw;
}
.white-text {
color: #fff;
}
.orange-text {
color: #f60;
}
.page-container {
width: 100%;
height: 85vh;
min-height: 460px;
display: flex;
justify-content: space-between;
font-size: 2vw;
position: relative;
}
#logo {
position: relative;
height: 100%;
padding: 3vh;
}
.landing-section {
width: 33.3%;
height: 100%;
padding: 4vw;
padding-top: 0;
display: flex;
flex-direction: column;
justify-content: space-around;
}
#employees {
background-color: #fff;
}
#employers {
background-color: #fff;
}
.values-list {
margin-left: 7vw;
margin-top: 2vw;
}
.rounded {
border-radius: 100%;
}
.div-call-to-action {
width: 100%;
height: 15vw;
display: flex;
justify-content: space-between;
}
.landing-icon {
width: 15vw;
height: 15vw;
}
.p-see-how {
margin: auto 0;
color: #f60;
}
.arrow-icon {
margin: auto 1.5vw;
min-width: 45px;
min-height: 45px;
width: 4vw;
height: 4vw;
background-size: contain;
background-color: #f60 /*in case image doesn't load*/;
border-radius: 5px;
}
.arrow-icon:active {
background-color: #fff /*in case image doesn't load*/;
border: 1px solid #f60;
}
.is-flex {
display: flex;
}
/*#media (max-width: 1000px) and (max-height: 1000px)
#logo
width 320px
height initial
padding 0*/
#img-screen-chat-top-parent {
width: 33.3%;
padding: 2.5%;
}
#img-screen-chat-btm-parent {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
#img-screen-chat {
display: block;
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
}
<header>
<img id="logo" src="http://via.placeholder.com/350x150" alt="ratedby">
</header>
<section class="page-container">
<section class="landing-section" id="employees">
<div class="div-why">
<h2>Lorem ipsum</h2>
<ul class="values-list">
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
</ul>
</div>
<div class="div-call-to-action">
<img class="rounded landing-icon" id="chef-icon" src="http://via.placeholder.com/150x150" alt="Looking for work?">
<div class="is-flex">
<p class="p-see-how">Lorem</p>
<div class="arrow-icon" id="arrow-employees"></div>
</div>
</div>
</section>
<section id="img-screen-chat-top-parent">
<div id="img-screen-chat-btm-parent">
<img id="img-screen-chat" alt="Mobile app screen" src="http://via.placeholder.com/729x1530">
</div>
</section>
<section class="landing-section" id="employers">
<div class="div-why">
<h2>Lorem ipsum</h2>
<ul class="values-list">
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
</ul>
</div>
<div class="div-call-to-action">
<img class="rounded landing-icon" id="hire-icon" src="http://via.placeholder.com/150x150" alt="Looking for work?">
<div class="is-flex">
<p class="p-see-how">Lorem</p>
<div class="arrow-icon" id="arrow-employers"></div>
</div>
</div>
</section>
</section>