I'm having trouble obtaining equal height bootstrap cards with differing length body content with a slick carousel. I've looked at similar answers on here and none of them appear to work in my scenario.
I've managed get equal height slides but for some reason I cannot get the cards within the slides to be 100% height of the slide (parent container). I'm trying to achieve what the Bootstrap class 'card-deck' achieves but in a carousel.
HTML
<div class="container">
<div class="row">
<div class="col-10 mx-auto s_container">
<div class="slider">
<div class="card">
<img class="card-img-top" src="img-ph.jpg" alt="place holder">
<div class="card-body">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Voluptates, rem?</div>
<div class="card-footer">
More Info
</div>
</div>
<div class="card">
<img class="card-img-top" src="img-ph.jpg" alt="place holder">
<div class="card-body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Rem, quasi soluta dolorum pariatur hic porro.</div>
<div class="card-footer">
More Info
</div>
</div>
<div class="card">
<img class="card-img-top" src="img-ph.jpg" alt="place holder">
<div class="card-body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto magnam esse molestiae est. Nisi aliquam libero dolorem? Qui, enim nam.</div>
<div class="card-footer">
More Info
</div>
</div>
<div class="card">
<img class="card-img-top" src="img-ph.jpg" alt="place holder">
<div class="card-body">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Voluptates, rem?</div>
<div class="card-footer">
More Info
</div>
</div>
<div class="card">
<img class="card-img-top" src="img-ph.jpg" alt="place holder">
<div class="card-body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Rem, quasi soluta dolorum pariatur hic porro.</div>
<div class="card-footer">
More Info
</div>
</div>
<div class="card">
<img class="card-img-top" src="img-ph.jpg" alt="place holder">
<div class="card-body">Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto magnam esse molestiae est. Nisi aliquam libero dolorem? Qui, enim nam.</div>
<div class="card-footer">
More Info
</div>
</div>
</div>
</div>
</div>
</div>
CSS
.s_container{
margin: 0 auto;
padding: 0 40px 0 40px;
width: 100%;
}
.slider{
border: 2px solid red;
}
.slick-track {
display: flex !important;
}
.slick-slide{
margin: 12px;
height: auto;
border: 2px solid green;
}
.slick-frame {
visibility: hidden;
}
An example of running can be found here:
Example
Equal height has been a problem for a lot of developers over the years.
In my opinion you can choose between 2 different solutions:
Javascript solution
You loop over all the cards and save the biggest height. Set all cards to this height with JS after biggest one has been defined.
https://www.bootply.com/LnwZjxWe7L
// Get cards
var cards = $('.card-body');
var maxHeight = 0;
// Loop all cards and check height, if bigger than max then save it
for (var i = 0; i < cards.length; i++) {
if (maxHeight < $(cards[i]).outerHeight()) {
maxHeight = $(cards[i]).outerHeight();
}
}
// Set ALL card bodies to this height
for (var i = 0; i < cards.length; i++) {
$(cards[i]).height(maxHeight);
}
CSS only solution
This one is a bit more complex to explain so here is an example how to do it:
#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;
}
<div id="container3"> <!-- added -->
<div id="container2"> <!-- added -->
<div id="container1">
<div id="col1">Column 1</div>
<div id="col2">Column 2</div>
<div id="col3">Super long text! Wow looks at this text, it is so long it needs to break on multiple lines!</div>
</div>
</div> <!-- added -->
</div> <!-- added -->
I got this solution from here:
https://matthewjamestaylor.com/equal-height-columns
Related
I'm trying to layer the top row of cards on top of the header using z-index on a project using Materialize CSS. Since the cards are now using relative positioning, it causes some of them to move when the card-action is hovered upon (the result is less visible on mobile view since there's only one card per row). I also didn't intend on the card-action text moving to the center when hovered, though I'm okay with that effect. I've tried using absolute positioning as well as changing which element the positioning is applied to. How can I prevent the cards from shifting and still use z-index? Here is my code and link to my (codepen):
#import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght#300;400&display=swap');
:root {
--primary-color: #c31432;
--primary-text-color: rgba(0,0,0,0.5);
--primary-text: "Open Sans", sans-serif;
}
* {
font-family: "Open Sans", sans-serif;
font-weight: 400;
}
#works-header {
position: absolute;
height: 500px;
width: 100vw;
z-index: 10;
}
#works-header h1 {
font-size: 3rem;
letter-spacing: 1px;
margin: 0 auto;
}
#cards {
position: relative;
top: 400px;
z-index: 1000;
}
.card-image {
cursor: pointer;
transition: all .3s ease;
}
.card-image:hover {
border: 3px solid var(--primary-color);
opacity: 0.85;
}
.card-image:hover .card-title {
display: none;
}
.card-action {
width: 50%;
cursor: pointer;
font-size: 1.2rem;
transition: all .3s ease;
}
.card-action:hover {
width: 100%;
position: absolute; /* this prevents cards from shifting due to relative positioning on the card element */
opacity: 0.7;
border-bottom: 2px solid var(--primary-color);
}
.card-tags {
display: none;
}
.card-image:hover .card-tags {
display: block;
position: absolute;
left: 1rem;
bottom: 2rem;
letter-spacing: 2px;
font-weight: 300;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet"/>
<!-- Todos: fix all cards aligned on the right side (card-action does not work properly) -->
<section class="center" id="works">
<div id="works-header" class="black valign-wrapper">
<h1 class="white-text center-align">Check out some of my latest projects</h1>
<p></p>
</div>
<div class="container row" id="cards">
<div class="col s12 m6 l4">
<div class="card z-depth-3">
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
</div>
<div class="card-content flow-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium nesciunt repellat consequatur autem! Laboriosam dignissimos rerum eum ea cum quibusdam!</p>
</div>
<div class="card-action">
View project
</div>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card z-depth-3">
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
</div>
<div class="card-content flow-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium nesciunt repellat consequatur autem! Laboriosam dignissimos rerum eum ea cum quibusdam!</p>
</div>
<div class="card-action">
View project
</div>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card z-depth-3">
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
</div>
<div class="card-content flow-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium nesciunt repellat consequatur autem! Laboriosam dignissimos rerum eum ea cum quibusdam!</p>
</div>
<div class="card-action">
View project
</div>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card z-depth-3">
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
</div>
<div class="card-content flow-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium nesciunt repellat consequatur autem! Laboriosam dignissimos rerum eum ea cum quibusdam!</p>
</div>
<div class="card-action">
View project
</div>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card z-depth-3">
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
</div>
<div class="card-content flow-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium nesciunt repellat consequatur autem! Laboriosam dignissimos rerum eum ea cum quibusdam!</p>
</div>
<div class="card-action">
View project
</div>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card z-depth-3">
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
</div>
<div class="card-content flow-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium nesciunt repellat consequatur autem! Laboriosam dignissimos rerum eum ea cum quibusdam!</p>
</div>
<div class="card-action">
View project
</div>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card z-depth-3">
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
</div>
<div class="card-content flow-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium nesciunt repellat consequatur autem! Laboriosam dignissimos rerum eum ea cum quibusdam!</p>
</div>
<div class="card-action">
View project
</div>
</div>
</div>
<div class="col s12 m6 l4">
<div class="card z-depth-3">
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
</div>
<div class="card-content flow-text">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium nesciunt repellat consequatur autem! Laboriosam dignissimos rerum eum ea cum quibusdam!</p>
</div>
<div class="card-action">
View project
</div>
</div>
</div>
</div>
</div>
</section>
One solution is to add a border to card-image, so that you are transitioning just the opacity and color, and not the border size (which in turn recalculates the size of the image and causes the flicker). It's a lot for the browser to process all at once.
.card-image {
cursor: pointer;
transition: all .3s ease;
border: 3px solid black;
}
Codepen.
EDIT:
Sorry, I realised there were two issues.
Ok so you don't need absolute positioning on the header - absolute takes items out of the flow of the page. No need to do that here. Take off the relative from the cards and use a negative margin:
#cards {
top: 400px;
z-index: 1000;
margin-top: -100px;
}
I've removed the absolute positioning from the hover as it's not a good idea. Absolute positioning comes into it's own when you need to finely control an elements positioning. No need for that here. I've also taken the 50% width off and added a default border to prevent flicker on the card action.
The main reason it's happening - because of the border on hover. If you really need this look - add empty div inside card-image and add inset box-shadow for it.
<div class="card-image">
<img src="https://i.imgur.com/vxaE0nK.png">
<span class="card-tags white-text">HTML, CSS, Javascript</span>
<span class="card-title white-text">Netflix Clone</span>
<div class="hover-shadow"></div>
</div>
and for CSS:
.card-image .hover-shadow {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.card-image:hover .hover-shadow {
box-shadow: inset 0 0 0 2px (--primary-color);
}
Full example at codepen
How can I place an image that goes from end of .col-md-4 to the end of the screen?
Here is what I have to do by design - red lines are .container boundaries, text is aligned to the left, and on the right is an image (or slider). I can't do .col-md-8 since the image needs to go as far as the screen is wide.
Can I combine .container and .container fluid somehow? What would you suggest? Image must be visible full width across all desktop sizes.
I currently did this with position absolute but this way the image is cut out and this is not desirable. https://codepen.io/ivan-topi/pen/pGYYjj
If I remove position: relative from .row and place it on .content then I can position image nicely with right: 0 to the end of the screen, but in that case I am not sure how can I position it without overlapping text on the left?
<div class="content">
<div class="container">
<div class="row">
<div class="col-md-4">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Id odio assumenda nobis recusandae voluptates itaque possimus provident libero et earum.</p>
</div>
<div class="img-wrapper">
<img src="https://via.placeholder.com/1300x450">
</div>
</div>
</div>
</div>
.content {
overflow: hidden;
height: 450px;
position: relative;
}
.row {
position: relative;
}
p {
font-size: 20px;
}
.img-wrapper {
left: 435px;
position: absolute;
width: 100%;
height: 450px;
overflow: hidden;
}
img {
width: 100%;
}
You can consider negative margin while using col-md-8. The trick is to add the amount space on the right as a negative margin to the container inside col-md-8 to create the overflow you want:
.content {
overflow: hidden;
height: 450px;
position: relative;
}
.row {
position: relative;
}
p {
font-size: 20px;
}
img {
width:100%;
}
#media (min-width: 768px) {
.negative {
margin-right: calc((720px - 100vw)/2 - 15px);
}
}
#media (min-width: 992px) {
.negative {
margin-right: calc((960px - 100vw)/2 - 15px);
}
}
#media (min-width: 1200px) {
.negative {
margin-right: calc((1140px - 100vw)/2 - 15px);
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<div class="content">
<div class="container">
<div class="row">
<div class="col-md-4">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Id odio assumenda nobis recusandae voluptates itaque possimus provident libero et earum.</p>
</div>
<div class="col-md-8">
<div class="negative">
<img src="https://via.placeholder.com/1300x450" class="d-block">
</div>
</div>
</div>
</div>
</div>
If i understand you, you need this:
<div class="content">
<div class="container">
<div class="row">
<div class="col-md-4 p-0 d-flex align-items-center">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Id odio assumenda nobis recusandae voluptates itaque possimus provident libero et earum.</p>
</div>
<div class="col-md-8 p-0">
<img class="img-fluid" src="https://via.placeholder.com/1300x450">
</div>
</div>
</div>
</div>
And from .img-wrapper remove position:absolute and left: 435px;
Check it here: https://codepen.io/gionic/pen/QYoPqq
I hope it helps you.
How can I have this header 'full width'. So that the image is on the left side of the screen. But that the content inside (President Jean ...) is in the grid?
I was thinking about creating a new container.
.container--full { max-width: 1400px; width: 100%; }
My .container grid has a max-width of 1170px. So my new container is wider than .container.
And then set a background-image, position left and background color grey.
Inside that .container--full, create .container
<div class="container--full">
<div class="container">
</div>
</div>
Test with container-fluid.
<div class="container-fluid" style="background-image: url('<?php bloginfo('template_directory'); ?>/images/commission-header.png');">
<div class="container">
<div class="col-sm-3">
<div class="info">
President
</div>
</div>
<div class="col-sm-9">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime obcaecati consequatur illum dolor quasi labore molestiae voluptatum consectetur laborum vel, modi nulla totam blanditiis quam sapiente, suscipit laudantium. Necessitatibus, eos.
</div>
</div>
</div>
CSS
.commission-business {
.container-fluid {
background-color: $grey--lighter;
background-position: left top;
background-repeat: no-repeat;
}
.info {
background: red;
display: block;
padding: 1rem 2rem;
}
}
Just use bootstraps 'container-fluid' class. (learn more)
<div class="container-fluid">
<div class="row>
...
</div>
</div>
How is possible to fill-in the height of a row with a cell in the following >>JSFiddle:
.x { height: 50px; }
.row { background: #eee; }
.row>:nth-child(odd) { background: lightblue; }
.row>:nth-child(even) { background: pink; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-3">fill height v</div>
<div class="col-xs-9"> <div class="x"> unknown height </div> </div>
</div>
PS. in order to be mobile compatible and also IE 11, I can't use flex
add .row{display: flex}
.x { height: 50px; }
.row {background: #eee; display: flex;}
.row>:nth-child(odd) {
background: lightblue;
}
.row>:nth-child(even) {
background: pink;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-3 cell">fill height v</div>
<div class="col-xs-9 cell">
<div class="x"> unknown height </div>
</div>
</div>
width absolute position jsfiddle.net/kth9vqhf
with display: table jsfiddle.net/kth9vqhf/1
with jQuery https://jsfiddle.net/kth9vqhf/3/
Using jQuery you can calculate the height of .x on the fly and set that as the minimum height for the cell.
$('.col-xs-3.cell').css("min-height", $('.x').height() + "px");
.x {
height: 50px;
}
.row {
background: #eee;
}
.row>:nth-child(odd) {
background: lightblue;
}
.row>:nth-child(even) {
background: pink;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-xs-3 cell">fill height v</div>
<div class="col-xs-9 cell">
<div class="x"> unknown height </div>
</div>
</div>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fill Row Height </title>
<style>
.WrapperRow{float: left; display: table; table-layout: fixed; vertical-align: top; width: 100%;}
.WrapperRow > div{display: table-cell; float: none; vertical-align: top; padding: 10px;}
.bgblue{background-color: blue;}
.cell.bgblue{width: 30%;}
.bgpink{background-color: pink;}
</style>
</head>
<body>
<div class="WrapperRow">
<div class="cell bgblue">
</div>
<div class="cell bgpink">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. In ipsa natus, vel non earum, distinctio iusto reprehenderit alias quisquam possimus, at qui nostrum ad enim totam repudiandae consectetur eius iste? Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum illum, aut sunt molestias tempora amet maxime ipsum? Vero animi beatae, dicta? Ut repudiandae fugit alias quasi esse culpa. Facere, dolore?
</div>
</div>
</body>
</html>
I'm trying to create a page with two divs inside a content div to act as columns. While I understand that this is a question that is often asked here, the difference is, I need the left side to be a title for the corresponding content on the right, but the content on the right will differentiate in height, and I need this to affect where the next title below on the left will appear.
Below is an image of how I want this to work, and how I'm guessing it can be done?
http://i.stack.imgur.com/aY8bt.png
Currently I'm doing this with HTML tables, which we all know is messy!
Many thanks in advance!
Dylan
without table, we can do it like this:
<div id="master">
<div class="title">TITLE A</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ac velit risus. Donec et libero erat. Pellentesque eros libero, lobortis eu diam accumsan, commodo tincidunt diam. Integer nec tincidunt dui.</div>
<div class="magicClear"></div>
<div class="title">TITLE B</div>
<div class="content">Tiny content with tiny height</div>
<div class="magicClear"></div>
<div class="title">TITLE C</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ac velit risus. Donec et libero erat. Pellentesque eros libero, lobortis eu diam accumsan, commodo tincidunt diam. Integer nec tincidunt dui.</div>
<div class="magicClear"></div>
</div>
css :
#master {
width: 650px;
margin: auto;
}
.title {
float: left;
width: 100px;
}
.content {
width: 450px;
padding-left: 100px;
margin-bottom: 20px;
}
.magicCLear {
clear: both;
}
http://jsfiddle.net/djedjex/GU7RW/1/
try this one
table
{
border:none;
}
table td:first-child
{
border-right:2px solid #000;
text-align:right;
}
table td
{
padding:10px;
vertical-align:top;
min-width:100px;
}
http://jsfiddle.net/GRX99/2/
if you used table tags, you can turn them into regular tags and use display:table / table-cell :
demo : http://codepen.io/anon/pen/aEBkA
HTML BLOCK for your title > content . use as many as needed.
<article>
<h1>titre</h1>
<div>
<p>text</p>
<p>and text again</p>
</div>
</article>
and minimal CSS:
article {
display:table;
table-layout:fixed;
/* tune next 2 rules */
width:80%;
margin:auto;
}
article h1,
article div {
display:table-cell;
padding:0.5em;
}
article h1 {
width:15%;
border-right:solid;
}
You can also do something fluid, Bootstrap inspired.
<div>
<div class="row">
<div class="span2">
<p>Title A</p>
</div>
<div class="span10">
<p>Very long content</p>
</div>
</div>
<div class="row">
<div class="span2">
<p>Title B</p>
</div>
<div class="span10">
<p>Another very long content</p>
</div>
</div>
</div>
And the CSS:
[class*="span"] {
float: left;
}
.span2 {
width: 20%;
}
.span10 {
width: 80%;
}
.span2 p {
float: right;
}
You have to adjust margins/paddings, but that's it.