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>
Related
I am building a stepper component using a CSS grid.
The grid has two rows and its column count is based on the number of steps in the stepper.
Each step has a header and a body.
Each step header lives in row 1 and takes exactly one column of the grid.
I've made each step header to be as big as its content and to stretch until it reaches the min-width of its siblings.
grid-template-columns: repeat(var(--steps-count), minmax(100px, auto));
The body of each step starts at row 2 and spans the number of columns in the first row, only the body of the selected step is visible, all others are hidden.
THE PROBLEM:
If the step body has short content the grid auto columns are working as expected, but if the body has a huge amount of content like in step 3 in example 1, all the columns in the grid look the same size, it's like the columns no longer respect the auto in the minmax() function and behave like they are all set to 1fr.
THE FIX:
The only fix I found is to explicitly set the width of the step body container to match the width of the entire stepper. I really want to avoid that, since the content of the step headers can be changed at runtime.
Example 1 - step with big body content
.stepper {
display: grid;
grid-template-columns: repeat(var(--steps-count), minmax(100px, auto));
row-gap: 8px;
font-family: "Roboto", sans-serif;
}
.step {
display: contents;
}
.step__header {
display: flex;
flex-direction: column;
align-items: center;
background: #000;
color: #fff;
padding: 8px;
gap: 8px;
cursor: pointer;
overflow: hidden;
border: 1px solid #fff;
}
.step__body {
display: none;
grid-row-start: 2;
grid-column: span var(--steps-count);
padding: 16px;
}
.step__content {
display: none;
}
.step__header-text {
width: 100%;
text-align: center;
}
.step__header-title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.step__header-indicator {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
background: #fff;
border-radius: 12px;
}
.step__header-indicator::after {
content: "🍻";
}
.step--selected {
color: #fff;
}
.step--selected .step__header {
background: purple;
}
.step--selected .step__body {
display: block;
background: purple;
}
.step--selected .step__content {
display: block;
}
<div class="stepper" style="--steps-count: 4">
<div class="step" style="--step-index: 0">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 1</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 1</div>
</div>
</div>
<div class="step" style="--step-index: 1">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 2</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 2</div>
</div>
</div>
<div class="step step--selected" style="--step-index: 2">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sapien arcu, imperdiet sed augue ut, rhoncus elementum urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut id ultricies libero, ac interdum
justo. Donec auctor quam in neque commodo, eget auctor turpis condimentum. Integer blandit urna vitae nisi bibendum luctus. Ut a laoreet purus, vel dictum nibh. Vestibulum non faucibus mi, eu tempor lectus. Mauris in varius lacus. Nullam pretium
at felis nec pharetra. Suspendisse dui ex, ullamcorper ac scelerisque ut, fermentum at urna. Aliquam efficitur, leo et egestas convallis, sapien tortor tincidunt velit, a faucibus ligula dui ac eros. Nunc sed sagittis orci. Fusce quam est, convallis
ac commodo eget, tincidunt non erat.</div>
</div>
</div>
</div>
<div class="step" style="--step-index: 3">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 4</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 4</div>
</div>
</div>
</div>
Example 2 - step with small body content
#charset "UTF-8";
.stepper {
display: grid;
grid-template-columns: repeat(var(--steps-count), minmax(100px, auto));
row-gap: 8px;
font-family: "Roboto", sans-serif;
}
.step {
display: contents;
}
.step__header {
display: flex;
flex-direction: column;
align-items: center;
background: #000;
color: #fff;
padding: 8px;
gap: 8px;
cursor: pointer;
overflow: hidden;
border: 1px solid #fff;
}
.step__body {
display: none;
grid-row-start: 2;
grid-column: span var(--steps-count);
padding: 16px;
}
.step__content {
display: none;
}
.step__header-text {
width: 100%;
text-align: center;
}
.step__header-title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.step__header-indicator {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
background: #fff;
border-radius: 12px;
}
.step__header-indicator::after {
content: "🍻";
}
.step--selected {
color: #fff;
}
.step--selected .step__header {
background: purple;
}
.step--selected .step__body {
display: block;
background: purple;
}
.step--selected .step__content {
display: block;
}
<div class="stepper" style="--steps-count: 4">
<div class="step" style="--step-index: 0">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 1</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 1</div>
</div>
</div>
<div class="step" style="--step-index: 1">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 2</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 2</div>
</div>
</div>
<div class="step step--selected" style="--step-index: 2">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">
<div>step 3 short content</div>
</div>
</div>
</div>
<div class="step" style="--step-index: 3">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 4</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 4</div>
</div>
</div>
</div>
As #MichaelBenjamin said, it's related to the content of the body. When it exceed a certain size the calculation of the column size behave differently.
I will try to grab the detail of such calculation but a solution is to make sure the body doesn't contribute to the grid size calculation by using width:0;min-width:100%;
.stepper {
display: grid;
grid-template-columns: repeat(var(--steps-count), minmax(100px, auto));
row-gap: 8px;
font-family: "Roboto", sans-serif;
}
.step {
display: contents;
}
.step__header {
display: flex;
flex-direction: column;
align-items: center;
background: #000;
color: #fff;
padding: 8px;
gap: 8px;
cursor: pointer;
overflow: hidden;
border: 1px solid #fff;
}
.step__body {
display: none;
grid-row-start: 2;
grid-column: span var(--steps-count);
padding: 16px;
width: 0;
min-width: 100%;
box-sizing: border-box;
}
.step__content {
display: none;
}
.step__header-text {
width: 100%;
text-align: center;
}
.step__header-title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.step__header-indicator {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
background: #fff;
border-radius: 12px;
}
.step__header-indicator::after {
content: "🍻";
}
.step--selected {
color: #fff;
}
.step--selected .step__header {
background: purple;
}
.step--selected .step__body {
display: block;
background: purple;
}
.step--selected .step__content {
display: block;
}
<div class="stepper" style="--steps-count: 4">
<div class="step" style="--step-index: 0">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 1</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 1</div>
</div>
</div>
<div class="step" style="--step-index: 1">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 2</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 2</div>
</div>
</div>
<div class="step step--selected" style="--step-index: 2">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sapien arcu, imperdiet sed augue ut, rhoncus elementum urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut id ultricies libero, ac interdum
justo. Donec auctor quam in neque commodo, eget auctor turpis condimentum. Integer blandit urna vitae nisi bibendum luctus. Ut a laoreet purus, vel dictum nibh. Vestibulum non faucibus mi, eu tempor lectus. Mauris in varius lacus. Nullam pretium
at felis nec pharetra. Suspendisse dui ex, ullamcorper ac scelerisque ut, fermentum at urna. Aliquam efficitur, leo et egestas convallis, sapien tortor tincidunt velit, a faucibus ligula dui ac eros. Nunc sed sagittis orci. Fusce quam est, convallis
ac commodo eget, tincidunt non erat.</div>
</div>
</div>
</div>
<div class="step" style="--step-index: 3">
<div class="step__header-wrapper">
<div class="step__header">
<div class="step__header-indicator"></div>
<div class="step__header-text">
<div class="step__header-title">Step 4</div>
</div>
</div>
</div>
<div class="step__body">
<div class="step__content">Step body 4</div>
</div>
</div>
</div>
width:0 will disable the size contribution and min-width:100% will make sure that your content fill all the available space (defined by the other content)
Few observations:
The columns break when the body content wraps. It's not just "a huge amount content" causing the problem, it's the wrap.
The body of the stepper preserves the column width until the moment the content wraps. The columns then start shrinking, and continue to shrink as more content is added, until the columns reach equal width.
Like you said, they "behave like they are all set to 1fr".
The problem is the auto value in the minmax argument in grid-template-columns. For some reason (I don't have time to look into this at the moment), the auto value resizes the columns on wrap.
Perhaps switch from auto to min-content.
(I'll ping #TemaniAfif. Maybe he can help.)
how do I align the quick view buttons horizontally?
I've tried css below but it doesn't work. Please advise. Thank you.
.woosq-btn {
display: flex;
justify-content: center;
}
I'm using WPC Smart Quick View plugin. Link https://wordpress.org/plugins/woo-smart-quick-view/
UPDATE - 3 MAY 2021
After using the CSS provided by #Ali Klein, it triggered another problem. All products are shown horizontally.
I fixed it by adding flex-wrap: wrap;
ul.products {
display: flex;
flex-wrap: wrap;
}
li.product {
display: flex;
flex-direction: column;
}
li.product > a {
flex: 1;
}
Final outcome:
The way I'd approach this is by applying display: flex; flex-direction: column on the individual cards, then wrapping all the content apart from the Quick View button in a container (it's already in a container a.woocommerce-loop-product__link), and give that container flex: 1 so it fills up the space of the card vertically.
.container {
display: flex;
}
.item {
display: flex;
flex-direction: column;
flex: 1;
margin: 10px;
background: lightblue;
}
.content {
flex: 1;
}
.image {
width: 100%;
height: 200px;
background-color: darkblue;
}
.description {
padding: 10px;
}
.btn {
margin: 10px;
}
<div class="container">
<div class="item">
<div class="content">
<div class="image"></div>
<p class="description">Suspendisse interdum consectetur libero id faucibus nisl tincidunt eget. Vitae sapien pellentesque habitant morbi tristique. </p>
</div>
<button class="btn">
Quick View
</button>
</div>
<div class="item">
<div class="content">
<div class="image"></div>
<p class="description">Sit amet nisl purus in mollis nunc sed id.</p>
</div>
<button class="btn">
Quick View
</button>
</div>
<div class="item">
<div class="content">
<div class="image"></div>
<p class="description">Diam phasellus vestibulum lorem sed risus ultricies. Elementum integer enim neque volutpat.</p>
</div>
<button class="btn">
Quick View
</button>
</div>
<div class="item">
<div class="content">
<div class="image"></div>
<p class="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua orci nulla pellentesque dignissim enim sit amet venenatis</p>
</div>
<button class="btn">
Quick View
</button>
</div>
</div>
With your markup, the css would look something like:
ul.products {
display: flex;
}
li.product {
display: flex;
flex-direction: column;
}
li.product > a {
flex: 1;
}
You'll end up with the following:
This question already has answers here:
vertical-align with Bootstrap 3
(26 answers)
Closed 7 years ago.
I'm using Twitter Bootstrap and am trying to vertically center text next to an image that is larger than the current text.
I can't use line-height because the text goes over more than one line and I also want to allow for possible additions to the text; so I went to the display: table; display: table-cell; method but it still refuses to work.
Here is my HTML for the respective section:
<div class="fs">
<div class="container">
<div class="wrapper row">
<div class="icon col-md-2">
<a href="" target="blank">
<img src="fs-icon.jpg" width="170" height="76" alt="Flying Solo Icon">
</a>
</div>
<div class="text col-md-10">
<span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tincidunt, lacus sed pharetra luctus, odio purus faucibus nunc, mattis molestie sapien libero sit amet leo.
</span>
</div>
</div>
</div>
<!-- Container Ends -->
</div>
<!-- FS Ends -->
CSS:
#about .fs {
padding: 30px 0;
}
#about .fs .wrapper {
display: table;
}
#about .fs .icon {
display: table-cell;
}
#about .fs .text {
display: table-cell;
min-height: 76px;
vertical-align: middle;
}
... and here it is on CodePen: http://codepen.io/anon/pen/XbdRXE
I think the CSS may be clashing with the behavior of the default Bootstrap CSS. However, you could bypass this method altogether and try using this as a custom class:
.vertical-center {
display: inline-block;
vertical-align: middle;
float: none;
}
Just apply it to your span element.
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.
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>