Having trouble achieving specific CSS Grid layout - html

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>

Related

My text is wrapping around my icon and I don't know to stop that, also I can't use fill on my SVG logo

Basically I have a 4 col grid and a <ul> , inside of it I have an icon and a <span>, but I don't know how to repair the text to not go under the icon and stay inline with my icon like this: https://imgur.com/a/I6Ue09D. Mine look like this : https://imgur.com/a/sAMVlgj.
Also the logo is a problem, fill doesn't work on it.
Here is the HTML code :
<footer class="huddle-footer">
<div class="contacting-details">
<img class="footer-logo" src="images/logo.svg" alt="huddle logo" />
<ul class="detail flex-gap">
<li>
<ion-icon class="address-icon" name="location-outline"></ion-icon>
<span class="location mg-left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua
</span>
</li>
<li class="info">
<ion-icon class="address-icon" name="call-outline"></ion-icon>
<span class="phone-number"> +1-543-123-4567</span>
</li>
<li class="info">
<ion-icon class="address-icon" name="mail-outline"></ion-icon>
<span class="email-address">example#huddle.com</span>
</li>
</ul>
</div>
and here is the CSS code:
.footer-logo {
margin-bottom: 3.6rem;
}
.huddle-footer {
display: grid;
grid-template-columns: 1fr 1fr 1fr 2fr;
background-color: var(--Very-Dark-Cyan);
height: 50vh;
align-items: center;
justify-items: center;
padding: 9.6rem 9.6rem 6.4rem 9.6rem;
}
.address-icon {
width: 2.4rem;
height: 2.4rem;
fill: hsl(193, 100%, 96%);
}
ul {
list-style-type: none;
}
.info {
display: flex;
gap: 1.6rem;
}
.flex-gap {
display: flex;
gap: 2.4rem;
flex-direction: column;
}

Only one item's elements in flex row is selectable

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;
}

CSS does not work and DOM structure from HTML

.empty-space{
width: 30%;
float: left;
}
.download-information{
width: 70%;
float: left;
}
.download-thumbnail img {
height: 30px;
width: 30px;
float: left;
}
.download-profile{
float: left;
}
<div class="download-content">
<div class="download-information">
<div class="empty-space"></div>
<div class="information">
<div class="download-thumbnail"><img src="https://media.istockphoto.com/photos/cloud-computing-picture-id1087885966" alt="Sample image"></div>
<div class="download-profile">
<b><div class="img-title">Demo title</div></b>
<div class="img-description">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div>
</div>
</div>
</div>
<div class="download-link-content">
<div class="download-link-content">
<div class="download-icon"><i class="fas fa-download"></i></div>
<div class="link-to-download">Download</div>
<div class="download-link-information">
<span>(
<span class="download-filesize">3,2 MB,</span>
<span class="download-filestype">PDF</span>
)
</span>
</div>
</div>
<div class="empty-space"></div>
</div>
</div>
I have the following mockup which I am now trying to model.
I have thought of the following HTML framework and associated CSS:
<div class="download-content">
<div class="download-information">
<div class="empty-space"></div>
<div class="information">
<div class="download-thumbnail"></div>
<div class="download-profile">
<b><div class="img-title"></div></b>
<div class="img-description"></div>
</div>
</div>
</div>
<div class="download-link-content">
<div class="download-link-content">
<div class="download-icon"><i class="fas fa-download"></i></div>
<div class="link-to-download"></div>
<div class="download-link-information">
<span>(
<span class="download-filesize">,</span>
<span class="download-filestype"></span>
)
</span>
</div>
</div>
<div class="empty-space"></div>
</div>
</div>
.empty-space{
width: 30%;
float: left;
}
.download-information{
width: 70%;
float: left;
}
.download-thumbnail {
height: 30px;
width: 30px;
float: left;
}
.download-profile{
float: left;
}
Unfortunately it doesn't work and frontend is not my strength at all and unfortunately I don't know anyone who can help me here how to do it. Can someone here help me how it should look or how I would have to style the CSS?
Add 1:
Is my idea of the HTML DOM wrong or is it possible to implement this so that the image can also be displayed correctly
Add 2:
Add snippet to my post. I don't get it. It's only a privat project but don't get the frontend styling.
I would not use all these floats, but to stay as close to what you did as possible, here's what you can do:
Move .download-profile into the .information div.
Create an additional wrapper div around .thumbnail and the div which follows after it (which contains the image title and description). (To only have two child elements in .download-profile which will be placed beside each other)
Apply display: flex to .download-profile
.empty-space {
width: 30%;
float: left;
}
.download-information {
width: 70%;
float: left;
}
.download-thumbnail img {
height: 30px;
width: 30px;
float: left;
margin: 0 10px 6px 0;
}
.download-profile {
float: left;
display: flex;
}
<div class="download-content">
<div class="download-information">
<div class="empty-space"></div>
<div class="information">
<div class="download-profile">
<div class="download-thumbnail"><img src="https://media.istockphoto.com/photos/cloud-computing-picture-id1087885966" alt="Sample image"></div>
<div>
<b><div class="img-title">Demo title</div></b>
<div class="img-description">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div>
</div>
</div>
</div>
</div>
<div class="download-link-content">
<div class="download-link-content">
<div class="download-icon"><i class="fas fa-download"></i></div>
<div class="link-to-download">Download</div>
<div class="download-link-information">
<span>(
<span class="download-filesize">3,2 MB,</span>
<span class="download-filestype">PDF</span> )
</span>
</div>
</div>
<div class="empty-space"></div>
</div>
</div>
It looks as though the CSS grid property will help here as it will work out how much space to leave between items tso you don't need to worry about floats or having empty space divs.
Here's a snippet to get you started. Obviously you'll want to look at the exact proportions you want for each part. You may also want to have a media query so that narrow devices use the full width of the screen for example.
You could also review your HTML structure as, with thinking of it in grid terms, it might be possible to simplify it.
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100vw;
height: 100vh;
}
.download-content {
display: grid;
grid-template-columns: 2fr 1fr;
width: 70%;
margin: 0 auto 0 auto;
}
.information{
width: 70%;
display: grid;
grid-template-columns: 1fr 6fr;
}
.download-thumbnail img {
width: 100%;
height: auto;
}
.download-link-info div {
display: inline-block;
}
</style>
</head>
<body>
<div class="download-content">
<div class="download-information">
<div class="information">
<div class="download-thumbnail"><img src="https://media.istockphoto.com/photos/cloud-computing-picture-id1087885966" alt="Sample image"></div>
<div class="download-profile">
<b><div class="img-title">Demo title</div></b>
<div class="img-description">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et</div>
</div>
</div>
</div>
<div class="download-link-content">
<div class="download-link-info">
<div class="download-icon"><i class="fa fa-download" aria-hidden="true"></i></div>
<div class="link-to-download">Download</div>
<div class="download-link-information">
<span>(
<span class="download-filesize">3,2 MB,</span>
<span class="download-filestype">PDF</span>
)
</span>
</div>
</div>
</div>
</div>
</body>

Image should not use full-width in element

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>

Line separator in css [duplicate]

In CSS, I can do something like this:
But I've no idea how to change that to something like:
Is this possible with CSS?
If yes, how can I do it without explicitly specifying the height (let the content grow)?
Grid
Nowadays, I prefer grid because it allows keeping all layout declarations on parent and gives you equal width columns by default:
.row {
display: grid;
grid-auto-flow: column;
gap: 5%;
}
.col {
border: solid;
}
<div class="row">
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</div>
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.</div>
</div>
Flexbox
Use Flexbox if you want children to control column width:
.row {
display: flex;
justify-content: space-between;
}
.col {
flex-basis: 30%;
box-sizing: border-box;
border: solid;
}
<div class="row">
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</div>
<div class="col">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.</div>
</div>
Give overflow: hidden to the container and large (and equal) negative margin and positive padding to columns. Note that this method has some problems, e.g. anchor links won't work within your layout.
Markup
<div class="container">
<div class="column"></div>
<div class="column"></div>
<div class="column"></div>
</div>
CSS
.container {
overflow: hidden;
}
.column {
float: left;
margin-bottom: -10000px;
padding-bottom: 10000px;
}
The Result
Yes.
Here is the completed CSS the article uses. It is well worth reading the entire article, as the author goes step by step into what you need to make this work.
#container3 {
float:left;
width:100%;
background:green;
overflow:hidden;
position:relative;
}
#container2 {
float:left;
width:100%;
background:yellow;
position:relative;
right:30%;
}
#container1 {
float:left;
width:100%;
background:red;
position:relative;
right:40%;
}
#col1 {
float:left;
width:26%;
position:relative;
left:72%;
overflow:hidden;
}
#col2 {
float:left;
width:36%;
position:relative;
left:76%;
overflow:hidden;
}
#col3 {
float:left;
width:26%;
position:relative;
left:80%;
overflow:hidden;
}
This isn't the only method for doing it, but this is probably the most elegant method I've encountered.
There is another site that is done completely in this manner, viewing the source will allow you to see how they did it.
You can do this easily with the following JavaScript:
$(window).load(function() {
var els = $('div.left, div.middle, div.right');
els.height(getTallestHeight(els));
});
function getTallestHeight(elements) {
var tallest = 0, height;
for(i; i < elements.length; i++) {
height = $(elements[i]).height();
if(height > tallest)
tallest = height;
}
return tallest;
};
You could use CSS tables, like so:
<style type='text/css">
.container { display: table; }
.container .row { display: table-row; }
.container .row .panel { display: table-cell; }
</style>
<div class="container">
<div class="row">
<div class="panel">...text...</div>
<div class="panel">...text...</div>
<div class="panel">...text...</div>
</div>
</div>
Modern way to do it: CSS Grid.
HTML:
<div class="container">
<div class="element">{...}</div>
<div class="element">{...}</div>
<div class="element">{...}</div>
</div>
CSS:
.container {
display: grid;
grid-gap: 10px;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.element {
border: 2px solid #000;
}
Live example is here.
repeat(auto-fit, minmax(200px, 1fr)); part sets columns width. Every column takes 1 fraction of available space, but can't go less than 200px. Instead of shrinking below 200px it wraps below, so it's even responsive. You can also have any number of columns, not just 3. They'll all fit nicely.
If you need exactly 3 columns, use grid-template-columns: repeat(3, 1fr); instead. You can still have more elements, they will wrap, be responsive, but always be placed in 3 column layout.
More on CSS Grid on MDN or css-tricks.
It's clean, readable, maintainable, flexible and also that simple to use!
You ca try it... it works for me and all browser compatible...
<div id="main" style="width:800px; display:table">
<div id="left" style="width:300px; border:1px solid #666; display:table-cell;"></div>
<div id="right" style="width:500px; border:1px solid #666; display:table-cell;"></div>
</div>
Another option is to use a framework that has this solved. Bootstrap currently doesn't have an equal height option but Foundation by Zurb does, and you can see how it works here: http://foundation.zurb.com/sites/docs/v/5.5.3/components/equalizer.html
Here's an example of how you'd use it:
<div class="row" data-equalizer>
<div class="large-6 columns panel" data-equalizer-watch>
</div>
<div class="large-6 columns panel" data-equalizer-watch>
</div>
</div>
Basically they use javascript to check for the tallest element and make the others the same height.
So, if you want just css this would add more code, but if you are already using a framework then they have already solved this.
Happy coding.
Use Flexbox to create equal height columns
* {box-sizing: border-box;}
/* Style Row */
.row {
display: -webkit-flex;
-webkit-flex-wrap: wrap;
display: flex;
flex-wrap: wrap;
}
/* Make the columns stack on top of each other */
.row > .column {
width: 100%;
padding-right: 15px;
padding-left: 15px;
}
/* When Screen width is 400px or more make the columns stack next to each other*/
#media screen and (min-width: 400px) {
.row > .column {
flex: 0 0 33.3333%;
max-width: 33.3333%;
}
}
<div class="row">
<!-- First Column -->
<div class="column" style="background-color: #dc3545;">
<h2>Column 1</h2>
<p>Some Text...</p>
<p>Some Text...</p>
</div>
<!-- Second Column -->
<div class="column" style="background-color: #ffc107;">
<h2>Column 2</h2>
<p>Some Text...</p>
<p>Some Text...</p>
<p>Some Text...</p>
<p>Some Text...</p>
<p>Some Text...</p>
<p>Some Text...</p>
<p>Some Text...</p>
</div>
<!-- Third Column -->
<div class="column" style="background-color: #007eff;">
<h2>Column 3</h2>
<p>Some Text...</p>
<p>Some Text...</p>
<p>Some Text...</p>
</div>
</div>
Responsive answer:
CSS flexbox is cute, but cutting out IE9 users today is a little insane. On our properties as of Aug 1 2015:
3% IE9
2% IE8
Cutting those out is showing 5% a broken page? Crazy.
Using a media query the way Bootstrap does goes back to IE8 as does display: table/table-cell. So:
http://jsfiddle.net/b9chris/bu6Lejw6/
HTML
<div class=box>
<div class="col col1">Col 1<br/>Col 1</div>
<div class="col col2">Col 2</div>
</div>
CSS
body {
font: 10pt Verdana;
padding: 0;
margin: 0;
}
div.col {
padding: 10px;
}
div.col1 {
background: #8ff;
}
div.col2 {
background: #8f8;
}
#media (min-width: 400px) {
div.box {
display: table;
width: 100%;
}
div.col {
display: table-cell;
width: 50%;
}
}
I used 400px as the switch between columns and a vertical layout in this case, because jsfiddle panes trend pretty small. Mess with the size of that window and you'll see the columns nicely rearrange themselves, including stretching to full height when they need to be columns so their background colors don't get cut off part-way down the page. No crazy padding/margin hacks that crash into later tags on the page, and no tossing of 5% of your visitors to the wolves.
Here is an example I just wrote in SASS with changeable column-gap and column amount (variables):
CSS:
.fauxer * {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; }
.fauxer {
overflow: hidden; }
.fauxer > div {
display: table;
border-spacing: 20px;
margin: -20px auto -20px -20px;
width: -webkit-calc(100% + 40px);
width: -moz-calc(100% + 40px);
width: calc(100% + 40px); }
.fauxer > div > div {
display: table-row; }
.fauxer > div > div > div {
display: table-cell;
width: 20%;
padding: 20px;
border: thin solid #000; }
<div class="fauxer">
<div>
<div>
<div>
Lorem column 1
</div>
<div>
Lorem ipsum column 2 dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et
dolore magna aliquyam erat, sed diam voluptua.
</div>
<div>
Lorem column 3
</div>
<div>
Lorem column 4
</div>
<div>
Lorem column 5
</div>
</div>
</div>
</div>
Note: I only found the time to test it in some new browsers. Please test it well before you will use it :)
The editable example in SCSS you can get here: JSfiddle