I have a two-part issue. First, I'm struggling to implement a card flip animation to cards in an existing flexbox grid layout since all of the solutions I've come across apply position: absolute on the cards, which breaks the layout and makes the rows overlap each other as they have almost no height. I also can't manually set the heights as it's based on variable content/viewports.
Secondly, I also can't get the animation itself working. I'm going for CSS approach triggered in jQuery. I tried the plugin jQuery Flip, but that also had the positioning issue.
Basically, I'm looking for a card flip animation solution that doesn't need the cards to be set to position: absolute, or does, but allows for multiple rows that don't have a fixed height. I don't mind using jQuery.
CSS:
.events-row {
display: flex;
justify-content: space-between;
margin: 0 auto;
max-width: 1280px;
}
.card {
flex-basis: 31.3%;
position: relative;
padding: 15px 0;
}
.card .card-flip-cont {
padding: 15px;
-webkit-transform-style: preserve-3d;
-webkit-transition: 0.5s;
}
.card .card-front,
.card .card-back {
position: absolute; /* Need to get rid of */
-webkit-backface-visibility: hidden;
}
.card .card-back {
-webkit-transform: rotatex(-180deg);
}
.card-flip-cont .card-flipped {
-webkit-transform: rotatex(-180deg);
}
Layout:
<div class="events-row">
<div class="card">
<div class="card-flip-cont">
<div class="card-face card-front">
<div class="card-img four-three-img">
<img src="http://i.imgur.com/gsnJi.jpg" />
</div>
<div class="card-info">
<h2>Event title</h2>
<h3>Event date</h3>
<h3>Event venue</h3>
<p>
Cu cum quem eros periculis, volutpat tractatos accommodare eu has, ex singulis assueverit usu.
</p>
<div class="button-cont">
<div class="button purple-button">Buy Tickets</div>
</div>
</div>
</div>
<div class="card-face card-back">
<div class="card-img four-three-img">
<img src="http://i.imgur.com/gsnJi.jpg" />
</div>
<div class="card-info">
<h2>Event title2</h2>
<h3>Event date2</h3>
<h3>Event venue2</h3>
<p>
Cu cum quem eros periculis, volutpat tractatos accommodare eu has, ex singulis assueverit usu.
</p>
<div class="button-cont">
<div class="button purple-button">Buy Tickets</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
jQuery:
$('.card-front .button').on('click', function() {
$(this).parents('.card-flip-cont').addClass('flipped');
});
Demo: http://codepen.io/ourcore/pen/oBeXzq
Related
I working in a page builder
For a shop, I am creating. I can change the CSS which is great.
I’m struggling to get a responsive resize of the images in this 4 column row. Since the images are different heights I have to have to set a height and have responsive width. Is there any way to get it to scale correctly?
The width is auto and the height is a set height based on the size of the screen.
You can see that when I resize it separates from the box and then sometimes get squished.
object-fit property
I did your design by using display : flex; and object-fit : cover; properties. I think that this object-fit property directly on the image is the only lacking property to make your images still looking good despite the screen resolution.
Notice the use of object-position : center; which makes the resizing always axed on the center of the image.
index.html
<div class="foo">
<div class="bar">
<img src="https://picsum.photos/200/300" alt="">
<div>
<h4>Lorem, ipsum dolor sit amet consectetur adipisicing.</h1>
<p>$42</p>
</div>
</div>
<div class="bar">
<img src="https://picsum.photos/500/200" alt="">
<div>
<h4>Lorem, ipsum dolor sit amet consectetur adipisicing.</h1>
<p>$42</p>
</div>
</div>
<div class="bar">
<img src="https://picsum.photos/200/700" alt="">
<div>
<h4>Lorem, ipsum dolor sit amet consectetur adipisicing.</h1>
<p>$42</p>
</div>
</div>
<div class="bar">
<img src="https://picsum.photos/500/400" alt="">
<div>
<h4>Lorem, ipsum dolor sit amet consectetur adipisicing.</h1>
<p>$42</p>
</div>
</div>
</div>
style.css
body {
background-color: #f7f7f7;
font-family: Arial, Helvetica, sans-serif;
}
.foo {
width: 100%;
display: flex;
gap: 20px;
}
.bar {
background-color: #ffffff;
display: flex;
flex-direction: column;
width: 100%;
border-radius: 15px;
overflow: hidden;
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
}
.bar > img {
width: 100%;
height: 200px;
object-fit: cover;
object-position: center;
}
h4 {
color:#9ccf74;
}
.bar > div {
padding: 10px;
height: 100px;
}
With mobile-first in mind, I have an html structure that stacks 3 divs (when on mobile) vertically.
JSFiddle: https://jsfiddle.net/danbrellis/mozez66k/1/
<div class="row">
<div class="small-12 large-3 columns">
<div class="panel small-12 columns googleMapFormContainer">
<h3 class="googleMapFormContainer-title">Find a Group Near You</h3>
<form class="googleMapForm" id="near-group-search">
<div class="row">
<div class="small-6 large-6 columns">
<label>ZIP Code
<input id="zip" type="text" name="zip" placeholder="ZIP Code" />
</label>
</div>
<div class="small-6 large-6 columns">
<label>Radius (mi)
<select id="radius" name="radius">
<option value=10>10</option>
</select>
</label>
</div>
</div>
<div class="row">
<div class="small-12 columns googleMapForm-submitButtonContainer">
Search
</div>
</div>
</form>
</div>
</div>
<div class="small-12 large-9 columns">
<div style="margin-bottom: 20px;">
<img src="http://via.placeholder.com/1071x520" />
</div>
</div>
<div class="small-12 large-3 large-pull-9 columns ">
<div class="panel">
<p class="small-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sodales ex risus, ac lacinia tellus lobortis ut. Suspendisse quis tellus eget neque varius pretium. Praesent rutrum luctus volutpat</p>
<p class="small-text">Quisque sit amet pulvinar urna. Praesent at convallis libero. Ut egestas ac orci quis sollicitudin.</p>
</div>
</div>
</div>
Mobile display:
However, when on desktop, I need the middle div to be in a right column. Here's what I want:
I'm using foundation's pull-large-9 class on div 3 to get it to the left, but it clears div 2 so I end up with div 3 spaced too far below div 1.
What I'm getting:
Btw, I'm using Foundation 5 and compiling the scss. I appreciate any thoughts or input. Open to using JS but would prefer a css/html solution if possible.
When I had a similar issue (shown below),
This is what I did to fix it:
.wrapper {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
flex-direction: column;
height: 312px;
}
.box1 {
background-color: red;
width: 555px;
height: 312px;
}
.box2 {
background-color: blue;
width: calc(100% - 555px);
height: 200px;
}
.box3 {
background-color: green;
width: calc(100% - 555px);
height: 112px;
;
}
/* MOBILE RWD */
#media all and (max-width: 750px) {
.wrapper {
flex-direction: row;
}
.wrapper .box1 {
width: 100%;
order: 0;
}
.wrapper .box2 {
width: 100%;
order: -1;
}
.wrapper .box3 {
width: 100%;
}
}
<div class="wrapper">
<div class="box box1"></div>
<div class="box box2"></div>
<div class="box box3"></div>
</div>
I'm trying to keep a couple of lists aligned to the left with some text and un-wrapping around an image on desktop/tablet and mobile but don't seem to be making a lot of progress.
Here's the Codepen: http://codepen.io/carlos_serrano/pen/ikjeg
and here the code for what I have so far:
HTML:
<div class="content">
<img src="any 100x 100 image.gif">
<h3>Heading</h3>
<p>Just random text here.</p>
</div>
<div class="linkcontainer">
<div class="linkleft">
<ul>
<li>Left Item 1</li>
<li>Left Item 2</li>
<li>Left Item 3</li>
</ul>
</div>
<div class="linkright">
<ul>
<li>Right Item 1</li>
<li>Right Item 2</li>
<li>Right Item 3</ul>
</div>
Here's the CSS:
p{
overflow: hidden;
}
img{
float:left;
margin: 0 25px;
}
.linkcontainer {
width: 50%;
padding-bottom: 25px;
clear: both;
}
.linkleft, .linkright {
width: 100%;
float: right;
}
#media only screen and (min-width: 481px) {
.linkleft, .linkright {
display: inline-block;
width: 30%;
float: left;
}
}
Ok, if I understood your question (and clarification in your comment) correctly, this is what you need to do:
First, move the heading and the text into the linkcontainer:
<div class="content">
<img src="http://www.labyrinth.net.au/~toonist/flash_goodies/graphics/image_sizes/rotate_circle_100.gif" />
</div>
<div class="linkcontainer">
<h3>Heading</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Provident deserunt architecto quasi quaerat cupiditate quis harum ipsum ipsa veritatis suscipit iure velit asperiores ipsam vitae reiciendis quos aliquam doloribus repellendus.</p>
<div class="linkleft">
<!-- ... -->
</div>
</div>
Then ensure content and linkcontainer are both floated left:
.content {
float:left;
margin:0 25px
}
.linkcontainer {
float:left;
padding-bottom: 25px;
}
I updated your pen: http://codepen.io/anon/pen/aAiqj
EDIT: Upon further clarification, there is a better solution that will help prevent wrapping the heading, text and menus on smaller screens: make sure you wrap the 2 main divs into a wrapper div and set the width of this one to the total of the inner divs (plus margins).
#wrapper {
width: 750px
}
.content {
float: left;
margin: 0 25px;
width: 200px;
}
.linkcontainer {
float: left;
padding-bottom: 25px;
width: 500px;
}
<div id="wrapper">
<div class="content">
<img src="http://www.labyrinth.net.au/~toonist/flash_goodies/graphics/image_sizes/rotate_circle_100.gif">
</div>
<div class="linkcontainer">
<!-- ... -->
</div>
</div>
Here is your newest pen: http://codepen.io/anon/pen/hJbmr
I am working on getting a two column layout that extends to the bottom of my page.
However, my sidebar cuts off at the container-fluid height even though I am trying to get it to extend to the whole page.
What is weird is that my content column works fine.
HTML:
<div class="container-fluid">
<div class="row-fluid columns no-margin fill">
<div id="sidebar" class="span2 columns no-margin right-edge"></div>
<div id="contentWrapper" class="span10 columns no-margin pull-right"></div>
</div>
</div>
CSS:
html, body, form {
height: 100%;
min-height: 100%;
background-image:url("../../images/lightGreyBackground.png");
background-repeat: repeat;
font-family:"Segoe UI", Helvetica, Arial, Sans-Serif;
}
.container-fluid {
margin: 0 auto;
height: auto;
padding: 0px;
}
.columns {
height: 100%;
min-height:100%;
margin: 0px;
width: 100%;
}
.fill {
position: absolute;
height: 100%;
min-height: 100%;
}
.no-margin {
margin-left: 0%;
width: 100%;
}
.right-edge {
border-right: 1px;
border-right-style: solid;
border-right-color: #CCCCCC;
}
#sidebar {
background-color: White;
padding-top:15px;
}
For have 2 column :
<html>
<head>
<style type="text/css">
.container-fluid { width: 100%;}
.float {
float: left;
width: 50%; /* Size colonne */
margin: 1em 0; /* Margin colonne */
}
.spacer { clear: both; }
</style>
</head>
<body>
<div class="container-fluid">
<div class="float">Colonne 1</div>
<div class="float">Colonne 2</div>
<div class="spacer"></div>
</div>
</body>
</html>
Use the framework bootstrap or 960.gs, powerful front-end framework for faster and easier web development.
With bootstrap 3 :
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-lg-4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus.</p>
<p><a class="btn btn-default" href="#">View details »</a></p>
</div>
<div class="col-lg-4">
<h2>Heading</h2>
<p>Donec id elit non mi porta gravida at eget metus.</p>
<p><a class="btn btn-default" href="#">View details »</a></p>
</div>
<div class="col-lg-4">
<h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in.</p>
<p><a class="btn btn-default" href="#">View details »</a></p>
</div>
</div>
</div>
I'm trying to center a Div that will have varying width's (based on content of a website).
I read about a relative positioning technique here:
http://www.tightcss.com/centering/center_variable_width.htm
But I thought there has to be an easier way to do it?
That's a pretty solid method that should work well in most browsers. It's not really that complex when you break it down. Here's a basic example:
<style type="text/css">
#hideoverflow { overflow: hidden; }
#outer { position: relative; left: 50%; float: left; }
#inner { position: relative; left: -50%; float: left; }
</style>
<div id="hideoverflow">
<div id="outer">
<div id="inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id velit vel augue fringilla rhoncus at et odio. Suspendisse potenti. Aliquam justo libero, commodo ut iaculis in, placerat vel purus.
</div>
</div>
</div>
#Talon; you can do it like this http://jsfiddle.net/sandeep/7PXQF/
CSS:
.container{
background-color:red;
text-align:center;
}
.center{
background-color:yellow;
display:inline-block;
text-align:left;}
HTML:
<div class="container">
<div class="center">
<p>This is a div with an much wider width, to make the yellow div go off the page to the right. We'll type a bit more to be sure.</p>
<p>Most people will see a horizontal scroll bar on the bottom, unless their screen is very wide.</p>
</div>
</div>
Well, it can't get any simpler than this and has full support on all browsers; doesn't even need a container:
.centered {
display:table;
margin:0 auto;
}
<div class="centered">
content
</div>
Here is a working fiddle: https://jsfiddle.net/1tnprnoz/
Now with flex-box you can easily achieve this with justify-content: center;.
#container{
background: gray;
display: flex;
justify-content: center;
}
<div id="container">
<div id="content" style="width: 200px; padding: 5px; background: #ffa637;">
This is a centered div This is a centered div This is a centered div This is a centered div
</div>
</div>
This can also be achieved by applying margin: auto to the containers child selector #container>*.
#container{
background: #c7c7c7;
}
#container>*{
margin: auto;
}
<div id="container">
<div id="content" style="width: 200px; padding: 5px; background: #ffa637;">
This is a centered div This is a centered div This is a centered div This is a centered div
</div>
</div>
Note: content div is styled inline as these styles are generated styles and are out of the scope of this question.