At the moment I am trying to program the wireframe I have made, but experience some problems with specially the left side of the element:
The problem is that the 200x200px image is going full width in the left column. Therefore I cannot center the image.
I can see it can be changed with overwriting the following CSS, and set the width to none;.
.cms-area img {
width: 100%;
}
But as I see it will break the reponsive on the images?
Can anybody help me in goal here?
See the [Testpage here][2].
The site is still using Bootstrap 3, and I do not have access to change the main CSS. Therefore I need to overwrite CSS if I need that.
Best regards
<style>
#front .row {
padding-bottom: 0px;
}
.row [class*="col-"] {
padding-right: 7.5px;
padding-left: 7.5px;
}
.padding-white-bg {
padding: 15px;
background-color: #fff;
margin-bottom:30px;
border: 1px solid #ebecf0;
}
.padding-twocolumn-bg {
margin-bottom:30px;
}
.padding-grey-bg {
padding: 7.5px;
}
.padding-white-border {
border: 1px solid #ebecf0;
}
.top-pad-d {
padding-top: 15px;
}
.sbp-2-column {
background-color:#fff;
padding-top:15px;
padding-bottom:15px;
border:1px solid #ebecf0;
}
/********************************/
/* Product styling */
/********************************/
/* Make spot image go full width */
.cms-area .result-cols ul.items li.add-item {
width: 100% !important;
}
.cms-area .result-cols ul.items li.add-item .item {
padding: 0px;
}
/* Remove add to basket button */
.cms-area .result-cols ul.items li.add-item a.button-add {
display:none;
}
/* Set height on product description */
.cms-area .result-cols ul.items li.add-item .desc {
height: 0px;
overflow: visible;
}
/* Remove fade on product headline */
.cms-area .result-cols ul.items li.add-item .desc:after {
background: none;
}
.cms-area .result-cols .more-wrap {
padding-bottom: 0px;
}
/* Remove Sub-heading */
.desc2{
display:none;
}
/* Remove product text */
.ext-description {
display:none;
}
/* Remove padding multiple products on row */
.cms-area .result-cols {
padding:0px;
}
/********************************/
/* Custom Buttons */
/********************************/
.btn.btn-lg {padding: 10px 40px;}
.btn.btn-hero,
.btn.btn-hero:hover,
.btn.btn-hero:focus {
color: #f5f5f5;
background-color: #1abc9c;
border-color: #1abc9c;
outline: none;
margin: 20px auto;
}
/********************************/
/* Media Queries */
/********************************/
#media screen and (min-width: 980px){
.hero { width: 980px; }
}
#media screen and (max-width: 640px){
.hero h1 { font-size: 4em; }
}
#media screen and (max-width: 896px){
.top-pad-m {
padding-top: 15px;
}
}
#media only screen and (max-width: 1280px) {
.fade-carousel .slides .slide-1,
.fade-carousel .slides .slide-2,
.fade-carousel .slides .slide-3 {
height: 60vh;
}
}
/********************************/
/* Overall Styling */
/********************************/
#sbp-hr {
margin-top:10px !important;
margin-bottom:10px !important;
}
.sbp-align {
text-align: left;
padding-left:10px;
}
.test {
padding:20px 20px 20px 20px;
}
/* TEST on 2 column */
.classWithPad { margin:8px; padding:10px; background-color: #fff; border:1px solid #ebecf0;}
.cms-area img {
max-width: 100%;
}
</style>
<div class="wrapper">
<!-- Section 7 -->
<div class="section padding-twocolumn-bg">
<div class="row">
<div class="text-center col-md-6">
<div class="classWithPad">
<p style="padding:75px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a><img src="https://placehold.it/200x200" class="img-responsive test"></a>
</div>
</div>
<div class="text-center col-md-6">
<div class="classWithPad">
<div class="row">
<div class="col-sm-12">
<h3 class="sbp-align">Headline</h3>
<hr>
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" style="padding:10px;">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" style="padding:10px;">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
</div>
</div>
</div>
</div>
</div>
</div>
If you make width=200px to the left column the uploaded image will always be at center and there are lots of padding you are using for centering the images, you can use various classes of bootstrap for that!
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<div class="container-fluid">
<!-- Section 7 -->
<div class="section padding-two column-bg">
<div class="row align-items-center">
<div class="text-center col-md-6 col-12">
<div class="classWithPad">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a><img src="https://placehold.it/200x200" width="200px"></a>
</div>
</div>
<div class="text-center col-md-6">
<div class="classWithPad">
<div class="row p-3">
<div class="col-sm-12">
<h3 class="sbp-align">Headline</h3>
<hr>
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" width="100%" class="pb-2">
<h4 class="sbp-align pb-2">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" width="100%" class="pb-2">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Related
I'm learning React by starting to build a simple webpage (I know, overkill.) but I ran across a weird issue.
So I have three "bubbles" on my homepage each containing an icon, title, and text. I am using flex in their parent container to align them as a row but when I do this I can only select the title and text of the last "bubble".
If I choose flex-direction: column; (or if I don't set a direction) I am able to select the text of all three bubbles. If I choose: flex-direction: row; and flex-wrap: wrap; and then make the window smaller so one of the bubbles goes to the next line, I am able to select the text from 1/2 of the bubbles on line one and the text from the bubble on line two.
Also the :hover is no longer working in that last section of CSS code.
Been at this problem for a couple of days and it makes no sense to me. Thanks in advance for the help. See code below.
.home-services {
padding: 50px;
background-color: bisque;
transform: skewY(-3deg) translateY(-55px);
z-index: -1;
}
.home-bubbles {
display: flex;
flex-direction: row;
flex-wrap: wrap;
transform: skewY(3deg) translateY(50px);
width: 100%;
user-select: all;
z-index: -1;
}
.home-services-bubble {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
margin: 10px;
padding: 10px 30px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 2px 3px #ddd;
width: 29%;
}
.bubble-icon {
display: flex;
justify-content: center;
align-items: center;
background-color: #f64a01;
height: 100px;
width: 100px;
font-size: 3vw;
text-align: center;
border-radius: 100px;
color: #ffffff;
}
.home-services-bubble:hover .bubble-icon {
transform: translateY(-5px);
background-color: black;
box-shadow: 2px 3px #ddd;
transition: 0.5s;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" rel="stylesheet"/>
<div class="home-services">
<div class="home-bubbles">
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-search fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-wind fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
<div class="home-services-bubble">
<div class="bubble-icon">
<i class="fas fa-sign fa-2x"></i>
</div>
<div class="bubble-title">
<h2>Lorem ipsum dolor</h2>
</div>
<div class="bubble-text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
</div>
</div>
The user-select property with the value all selects the whole text on a simple click. Just remove it like this:
.home-bubbles {
display: flex;
flex-direction: row;
flex-wrap: wrap;
transform: skewY(3deg) translateY(50px);
width: 100%;
z-index: -1;
}
I'm brushing up on Responsive Grid CSS on YouTube. Following along with the instructors lesson. I'm having trouble formatting my nave grid. I've included both the html and css code along with pictures of his nav results vs mine. Any help would be appreciated.
I'm trying to get the navigation bar in a 4 column grid. I'm trying to see what I'm missing here.
Instructor Results:
My Results:
/* CSS Variables */
:root {
--primary: #ddd;
--dark: #333;
--light: #fff;
--shadow: 0 1px 5px rgba(104, 104, 104, 0.8);
}
html {
box-sizing: border-box;
font-family: Arial, Helvetica, san-serif;
color: var(--dark);
}
body {
background: #ccc;
margin: 30px 50px;
line-height: 1.4;
}
.btn {
background: var(--dark);
color: var(--light);
padding: 0.6rem 1.3rem;
text-decoration: none;
border: 0;
}
img {
max-width: 100%;
}
.wrapper {
display: grid;
grid-gap: 20px;
}
/* Navigation */
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<div class="wrapper">
<!-- Navigation -->
<nav class="main-nav">
<ul>
<li><a href="#">Home</li>
<li><a href="#">About</li>
<li><a href="#">Services</li>
<li><a href="#">Contact</li>
</ul>
</nav>
<!-- Top Container -->
<section class="top-container">
<header class="showcase">
<h1>Damn That Looks Delicious</h1>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Aliquam sem et tortor consequat id porta.
</p>
Read More
</header>
<div class="top-box top-box-a">
<h4>Membership</h4>
<p class="price">$199/mo</p>
Buy Now
</div>
<div class="top-box top-box-b">
<h4>Pro Membership</h4>
<p class="price">$299/mo</p>
Buy Now
</div>
</section>
<!-- Boxes Section -->
<section class="boxes">
<div class="box">
<i class="fas fa-pizza-slice fa-4x"></i>
<h3>Restaurants</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-utensils fa-4x"></i>
<h3>Chefs</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-hamburger fa-4x"></i>
<h3>Catering</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-ice-cream fa-4x"></i>
<h3>Sweets</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
</section>
<section>
<img src="images/dtld.jpg" alt="">
<div>
<h2> Your Business On DTLD</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Learn More
</div>
</section>
<!-- Portfolio Section -->
<section class="portfolio">
<img src="https:/source.unsplash.com/random/200x200" alt="">
<img src="https:/source.unsplash.com/random/201x200" alt="">
<img src="https:/source.unsplash.com/random/202x200" alt="">
<img src="https:/source.unsplash.com/random/203x200" alt="">
<img src="https:/source.unsplash.com/random/204x200" alt="">
<img src="https:/source.unsplash.com/random/205x200" alt="">
<img src="https:/source.unsplash.com/random/206x200" alt="">
<img src="https:/source.unsplash.com/random/207x200" alt="">
<img src="https:/source.unsplash.com/random/208x200" alt="">
</section>
<!-- Footer -->
<footer>
<p> Damn That Looks Delicious © 2005</p>
</footer>
</div>
<!-- Wrapper Ends -->
Once you add the closing tag to your anchor elements the layout works as you expect.
This is what you have now:
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<nav class="main-nav">
<ul>
<li><a href="#">Home</li>
<li><a href="#">About</li>
<li><a href="#">Services</li>
<li><a href="#">Contact</li>
</ul>
</nav>
Because the anchor elements are left open (creating invalid HTML code), the browser generates four additional grid items. Now the grid container has eight children: 4 li and 4 a.
Since your code allows for only four items per row, a second row is created to accommodate the other four items. In fact, you always had a four-column grid.
Once you close the anchor tags (creating valid HTML code), only four grid items are rendered.
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<nav class="main-nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
Also, you may want to see my answer here for a brief analysis and suggestion regarding unordered lists inside nav elements.
There is missing of closing anchor </a> tag in your code so once you add closing anchor tag in it. Your code will run perfectly.
screenshot of missing anchor tag
I need to animate a div going from bottom to top.
This is the situation:
I have a thumbnail that includes the title and description of a movie inside of it. I want to hide the description and only show it when the user hovers the mouse on it.
I tried resizing the height of the container but you can't animate it when the value is set to "auto", and i can't provide an specific size for it because the title may vary for each movie.
And as a lot of you may know, you can't animate from bottom to top using the "bottom" and "top" properties.
This is the html:
<div class="thumbnail-component">
<img class="thumbnail-component__background" src="background.jpg" alt="">
<div class="thumbnail-component__gradient"></div>
<div class="text">
<div class="text__content">
<p class="text__title">The movie title</p>
<div class="text__separator"></div>
<p class="text__description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<p class="text__author">Published by Author</p>
</div>
</div>
And here is an image of what i'm trying to accomplish:
I'm honestly completely lost, i think i tried everything i know.
Sorry for my not too great english.
Show Card description on Card hover
Completely flexible and responsive
No hard-coded or arbitrary heights, no JS involved.
Basically,
translateY the title to -100%, on hover animate to 0
Wrap both title and content into a DIV (i.e: .anim)
translateY .anim to +100%, and on hover animate it to 0
Open the example in full page to see what happens and how it works:
/*QuickReset*/*{margin:0;box-sizing:border-box;}
.thumb {
width: 140px;
background: #eee;
}
.anim {
transition: 0.5s;
transform: translateY(100%);
}
.title {
color: red;
transition: 0.5s;
transform: translateY(-100%);
}
.author {
color: blue;
}
/* ANIMATE */
.thumb:hover .anim,
.thumb:hover .title {
transform: translateY(0);
}
<div class="thumb">
<div class="anim">
<div class="title">The movie even longer title</div>
<div class="description">
Text lenghts of Title and Author or even Description do not matter. They will all perfectly accommodate into .thumb on hover
</div>
</div>
<div class="author">Published by super long some Author</div>
</div>
Flexbox Grid!
The real-case proof of concept example:
/*QuickReset*/
* {
margin: 0;
box-sizing: border-box;
}
html {
height: 100%
}
body {
min-height: 100%;
font: 14px/1.4 sans-serif;
}
.grid-3 {
display: flex;
flex-flow: row wrap;
}
.thumb {
display: flex;
flex-flow: column nowrap;
position: relative;
overflow: hidden;
width: 33.333%;
color: #fff;
}
.thumb-gradient,
.thumb-img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.thumb-gradient {
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.24) 0%, rgba(0, 0, 0, 0.56) 100%);
}
.thumb-anim {
margin-top: auto; /* pushes all content to bottom */
position: relative;
transition: 0.5s;
transform: translateY(100%);
}
.thumb-title {
text-transform: uppercase;
padding: 20px;
transition: 0.5s;
transform: translateY(-100%);
}
.thumb-description {
padding: 10px 20px;
transition: 0.5s;
opacity: 0;
flex: 1;
}
.thumb-author {
padding: 20px;
position: relative;
}
/* ANIMATE */
.thumb:hover .thumb-anim {
transform: translateY(0);
}
.thumb:hover .thumb-title {
transform: translateY(0%);
}
.thumb:hover .thumb-description {
opacity: 1;
}
<div class="grid-3">
<div class="thumb">
<img class="thumb-img" src="http://placekitten.com/300/300" alt="Catz!">
<div class="thumb-gradient"></div>
<div class="thumb-anim">
<h3 class="thumb-title">The movie title</h3>
<p class="thumb-description">
Text lenghts of Title and Author or even Description do not matter. They will all perfectly accommodate into .thumb on hover
</p>
</div>
<div class="thumb-author">Published by super long some Author</div>
</div>
<div class="thumb">
<img class="thumb-img" src="http://placekitten.com/400/300" alt="Catz!">
<div class="thumb-gradient"></div>
<div class="thumb-anim">
<h3 class="thumb-title">The movie title</h3>
<p class="thumb-description">
The row heights are dictated by the tallest in the horizontal group
</p>
</div>
<div class="thumb-author">Published</div>
</div>
<div class="thumb">
<img class="thumb-img" src="http://placekitten.com/230/300" alt="Catz!">
<div class="thumb-gradient"></div>
<div class="thumb-anim">
<h3 class="thumb-title">The movie title a super long title here</h3>
<p class="thumb-description">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus facilis beatae, numquam aliquam eveniet. Iure porro provident itaque hic quae tempora. Quaerat doloribus dolore facilis similique, soluta asperiores quas sapiente.
</p>
</div>
<div class="thumb-author">Published by super long some Author</div>
</div>
<div class="thumb">
<img class="thumb-img" src="http://placekitten.com/270/300" alt="Catz!">
<div class="thumb-gradient"></div>
<div class="thumb-anim">
<h3 class="thumb-title">The movie title</h3>
<p class="thumb-description">
Text lenghts of Title and Author or even Description do not matter. They will all perfectly accommodate into .thumb on hover
</p>
</div>
<div class="thumb-author">Published by super long some Author</div>
</div>
<div class="thumb">
<img class="thumb-img" src="http://placekitten.com/250/370" alt="Catz!">
<div class="thumb-gradient"></div>
<div class="thumb-anim">
<h3 class="thumb-title">The movie title</h3>
<p class="thumb-description">
Text lenghts of Title and Author or even Description do not matter. They will all perfectly accommodate into .thumb on hover
</p>
</div>
<div class="thumb-author">Yep. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate sequi aspernatur cumque saepe incidunt enim, nihil dolores ipsam numquam architecto velit labore quod laboriosam aliquam distinctio tempora unde ad totam.</div>
</div>
<div class="thumb">
<img class="thumb-img" src="http://placekitten.com/290/340" alt="Catz!">
<div class="thumb-gradient"></div>
<div class="thumb-anim">
<h3 class="thumb-title">The movie title</h3>
<p class="thumb-description">
Text lenghts of Title and Author or even Description do not matter. They will all perfectly accommodate into .thumb on hover
</p>
</div>
<div class="thumb-author">Published by super long some Author</div>
</div>
</div>
Pretty easy with CSS transform...
.thumbnail-component {
width: 240px;
border: 1px solid red;
overflow: hidden;
cursor: pointer;
}
.thumbnail-component .text {
display: inline-block;
position: relative;
text-align: center;
transform: translateY(70%);
transition: all 1s ease;
}
.thumbnail-component:hover .text {
transform: translateY(0%);
}
<div class="thumbnail-component">
<img class="thumbnail-component__background" src="background.jpg" alt="">
<div class="thumbnail-component__gradient"></div>
<div class="text">
<div class="text__content">
<p class="text__title">The movie author</p>
<div class="text__separator"></div>
<p class="text__description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
<p class="text__author">Published by Author</p>
</div>
</div>
</div>
You can transition on the flex property, which could be useful here. To reveal the description during the hover, I set its opacity to 0 and position it absolutely safely inside its relative parent container. Finally, I removed the text__separator div because it wasn't useful to be as a flex child.
.text__content {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.text__content__top {
position: relative;
margin-top: auto;
transition: 0.5s flex ease-in-out;
}
.text__description {
position: absolute;
opacity: 0;
transition: 0.4s opacity ease-in-out 0.1s;
}
.text__title {
border-bottom: 2px solid red;
}
.thumbnail-component:hover .text__content__top {
flex: 1;
}
.thumbnail-component:hover .text__content__top > * {
pointer-events: none;
}
.thumbnail-component:hover .text__description {
opacity: 1;
}
<div class="thumbnail-component">
<div class="text">
<div class="text__content">
<div class="text__content__top">
<p class="text__title">The movie title</p>
<p class="text__description">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
<div class="text__content__bottom">
<p class="text__author">Published by Author</p>
</div>
</div>
</div>
</div>
jsFiddle
I am trying to create a shopping cart page. This is my goal:
I though about using Flexbox since this is one dimensional layout, but wanted to get some practice with CSS Grid. I think CSS Grid is a good solution because I can see 6 unequal sized columns. I think I'm close, but my spacing is way off. This is what I have so far:
.shopping-cart .product-row {
display: grid;
grid-template-columns: repeat(6, auto);
border-bottom: 1px solid #eee;
}
.shopping-cart .product-row .product-image img {
width: 100px;
}
.shopping-cart .product-row .product-details {
display: inline-block;
grid-column-start: 2;
grid-column-end: 3;
}
.shopping-cart .product-row .product-details .product-description {
display: inline-block;
margin: 5px 20px 0px 0;
width: 50%;
line-height: 1.4em;
}
.shopping-cart .product-row .product-quantity input {
width: 40px;
}
<div class="shopping-cart">
<div class="product-row">
<div class="product-image">
<img src="https://www.drivencoffee.com/wp-content/uploads/2016/03/Scandinavian-Blend-coffee.jpg" />
</div>
<div class="product-details">
<div class="product-title">Coffee</div>
<div class="product-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim </div>
</div>
<div class="product-price">12.99</div>
<div class="product-quantity">
<input type="number" value="2" min="1" />
</div>
<div clas="product-removal">
<button class="remove-product">
Remove
</button>
</div>
<div class="product-total-price">
25.98
</div>
</div>
</div>
Here's a code pen of the same code
I think my problem is with grid-template-columns: repeat(6, auto). It's creating 6 columns and each column is only as big as the content inside of it. I'm just not sure how to achieve for accurate positioning.
Thank you for any help.
As per my comments to this question, you can try creating an 8-column layout using grid-template-columns: repeat(8, 1fr) and use grid-column: span 3 for product-details element - see demo below:
.shopping-cart .product-row {
display: grid;
grid-template-columns: repeat(8, 1fr); /* CHANGED */
border-bottom: 1px solid #eee;
}
.shopping-cart .product-row .product-image img {
width: 100px;
}
.shopping-cart .product-row .product-details {
display: inline-block;
grid-column: span 3; /* CHANGED */
}
.shopping-cart .product-row .product-details .product-description {
display: inline-block;
margin: 5px 20px 0px 0;
width: 50%;
line-height: 1.4em;
}
.shopping-cart .product-row .product-quantity input {
width: 40px;
}
<div class="shopping-cart">
<div class="product-row">
<div class="product-image">
<img src="https://www.drivencoffee.com/wp-content/uploads/2016/03/Scandinavian-Blend-coffee.jpg" />
</div>
<div class="product-details">
<div class="product-title">Coffee</div>
<div class="product-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim </div>
</div>
<div class="product-price">12.99</div>
<div class="product-quantity">
<input type="number" value="2" min="1" />
</div>
<div clas="product-removal">
<button class="remove-product">
Remove
</button>
</div>
<div class="product-total-price">
25.98
</div>
</div>
</div>
Why not try to use the old methods:
Want to use the grid ?
.row {
display: block;
}
img, input {
max-width: 100%;
}
.img {
width: 64px;
}
.amount {
width: 56px;
}
.details {
width: calc(100% - 64px * 5);
}
.col {
display: inline-block;
vertical-align: middle;
border: 1px solid red;
}
<div class="shopping-cart">
<div class="row">
<div class="col img"><img src="https://www.drivencoffee.com/wp-content/uploads/2016/03/Scandinavian-Blend-coffee.jpg"/></div>
<div class="col details">
<div class="product-title">Coffee</div>
<div class="product-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim </div>
</div>
<div class="col">12.99</div>
<div class="col amount"><input type="number" value="2" min="1" /></div>
<div class="col"><button class="remove-product"> Remove </button></div>
<div class="col">25.98</div>
</div>
</div>
I have used bootstrap to handle the issue.
Bootstrap is very response across various display sizes, take a look over the code below
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-2">
<img style="width: 100%;" src="https://www.drivencoffee.com/wp-content/uploads/2016/03/Scandinavian-Blend-coffee.jpg" />
</div>
<div class="col-xs-2">
<div class="product-title">Coffee</div>
<div class="product-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim </div>
</div>
<div class="col-xs-2">12.99</div>
<div class="col-xs-2">
<input type="number" value="2" min="1" />
</div>
<div class="col-xs-2">
<button class="remove-product">
Remove
</button>
</div>
<div class="col-xs-2">
25.98
</div>
</div>
I know you are asking about a solution for css grid, but I think your first idea was better. A shopping cart is a LIST of elements from which some have a more or less fixed size and position and another, the description, needs to adapt depending on the width. That for me is a list of flex items with flex-flow: row nowrap adding a flex: auto to the description.
Also, there is no need for a headers row, as concepts are clear if you order them properly: Photo > description > Price x [Quantity] > Total > Actions.
I forked your pen to show you an example: https://codepen.io/jesuke/pen/aMYGdv
However if you think Headers are required, then what you are looking for is a data table with fixed layout I believe. The fixed Layout will give you that accurate positioning you are looking for.
This solution uses grid template column names and assigning them where required. Some of the template settings use minmax() to allow for some flexibility. Of course, you should adjust these to fit your specifications.
The product-details section is set to flex with a column layout.
Included as well is the header portion from OP's image of the desired layout. This is set as a grid as well and the appropriate column names are assigned to the header labels.
Furthermore, some slight enchancements, are a slight indent on product-title (as shown in the supplied image from OP) and also pre-prending a $ to the product-price value.
Benefits to named grid templates is that assignment is made easy as well as setting the grid cell values are easily edited without much thought to which numbered column am I editing, for example.
.shopping-cart,
.product-row > div {
display: flex;
justify-content: center;
}
.shopping-cart {
flex-direction: column;
}
.shopping-cart__header,
.shopping-cart .product-row {
display: grid;
grid-template-columns: [product-image] 6rem [product-details] minmax(11rem, 24rem) [product-price] 5rem [product-quantity] 5rem [product-removal] 6rem [product-total-price] 5rem;
grid-column-gap: 0.5rem;
grid-template-rows: 1fr;
border-bottom: 1px solid #eee;
align-items: center;
}
[class*="shopping-cart__header__label"] {
text-align: center;
}
.shopping-cart__header__label-price {
grid-column-start: product-price;
}
.shopping-cart__header__label-quantity {
grid-column-start: product-quantity;
}
.shopping-cart__header__label-total {
grid-column-start: product-total-price;
}
.shopping-cart .product-row .product-image img {
width: 100%;
}
.shopping-cart .product-row .product-image {
grid-column-start: product-image;
}
.shopping-cart .product-row .product-details {
grid-column-start: product-details;
display: flex;
flex-direction: column;
padding: 0.625rem;
}
.shopping-cart .product-row .product-details .product-title {
padding-left: 0.635rem;
}
.shopping-cart .product-row .product-price {
grid-column-start: product-price;
}
.shopping-cart .product-row .product-quantity {
grid-column-start: product-quantity;
}
.shopping-cart .product-row .product-quantity input {
width: 2.5rem;
}
.shopping-cart .product-row .product-removal {
grid-column-start: product-removal;
}
.shopping-cart .product-row .product-total-price {
grid-column-start: product-total-price;
}
.shopping-cart .product-row .product-total-price:before {
content: '$';
}
<div class="shopping-cart">
<header class="shopping-cart__header">
<span class="shopping-cart__header__label-price">Price</span>
<span class="shopping-cart__header__label-quantity">Quantity</span>
<span class="shopping-cart__header__label-total">Total</span>
</header>
<div class="product-row">
<div class="product-image">
<img src="https://www.drivencoffee.com/wp-content/uploads/2016/03/Scandinavian-Blend-coffee.jpg" />
</div>
<div class="product-details">
<div class="product-title">Coffee</div>
<div class="product-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim </div>
</div>
<div class="product-price">12.99</div>
<div class="product-quantity">
<input type="number" value="2" min="1" />
</div>
<div clas="product-removal">
<button class="remove-product">
Remove
</button>
</div>
<div class="product-total-price">
25.98
</div>
</div>
</div>
I have 3 divs, each with width:100%, placed under each other.
Here's how it looks:
My code is:
<div class="welcome">
<h1>Welcome</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>
</div>
<div class="welcome2">
<h1>About</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.<small>
</div>
<div class="welcome3">
<h1>Why choose us?</h1>
<div class="row">
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
</div>
</div>
CSS
.welcome
{
text-align: center;
width: 100%;
background-color: #3BA666;
background-image: linear-gradient(60deg, #4DAC71 50%, #3BA666 50%);
padding: 50px;
}
.welcome2
{
text-align: center;
width: 100%;
background-color: #FF61E7;
background-image: linear-gradient(60deg, #FF61E7 50%, #FF61D0 50%);
padding: 50px;
}
.welcome3
{
text-align: center;
width: 100%;
background-color: #32C8DE;
background-image: linear-gradient(60deg, #32D0DE 50%, #32C8DE 50%);
padding: 50px;
}
.why
{
/** text-align: left; **/
padding: 15px;
}
.why-icon
{
color: #0E495C;
display: block;
}
I want it to be like that - first two are normal height, and the last one always fill the empty white space. Is this possible?
Here is the Fiddle: https://jsfiddle.net/21dydo07/1/
Yes, with CSS3.
Give the design's parents (body, html, ...) a height of 100%. Then set some height to .welcome and .welcome2, e.g. 200px each. After that, set .welcome3 to take the rest, like this:
html, body {height: 100%}
.welcome, .welcome2 {height: 200px}
.welcome3 {height: calc(100% - 400px)}
Another solution would be to set specific height for every element (that would also be CSS2 comapatible), but that wouldn't allow you to always fill 100% of the screen height and have the third div with a variable height.
If you need the first solution, but you also need CSS2 compliance (e.g. for IE8), then you might need a javascript fallback, that will set the height to .welcome3 accordingly at pageload, something like this (needs jQuery):
$(document).ready(function() {
$(".welcome3").css("height",$(window).height()-400);
});
If the sentences in the first two blocks can be wrapped to single-line, use this:
You could use calc().
Make sure that the wrapper for these three has a height style.
For .welcome and .welcome2, set padding and line-height either in px or in em. For example, if the calculated height comes out to be 300px use height: calc(100% - 300px) for .welcome3. Note: The spaces around the operator - are important.
You can do this with Flexbox, set min-height: 100vh; on wrap div and flex: 1; on welcome3 so it will always take free space of viewport
html, body {
margin: 0;
padding: 0;
}
.wrap {
display: flex;
min-height: 100vh;
flex-direction: column;
text-align: center;
}
.welcome {
background: #3CA666;
padding: 20px;
}
.welcome2 {
background: #FF61D0;
padding: 20px;
}
.welcome3 {
background: #32C9DE;
flex: 1;
padding: 20px;
}
<div class="wrap">
<div class="welcome">
<h1>Welcome</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>
</div>
<div class="welcome2">
<h1>About</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>small>
</div>
<div class="welcome3">
<h1>Welcome 3</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua</small>
</div>
</div>