Expand height of an element on smaller screens - html

https://jsfiddle.net/7v0dyfo3/
This is (not exactly, without styling) what i'm trying to do for a listing.
It's all good but it does not resize properly.
I would like the div episode-box to expand its height for smartphone screens, so the text can be shown vertically, below the image.
It's not very correctly coded, but can you tell me what are my mistakes for the bad resizing ?
<article class="full-width">
<div class="post-box">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="guide-art-container">
<div class="episode-content">
<div class="saga">
<div class="row">
<div class="col-md-12">
<div class="episode-box">
<div class="episode-img">
<img class="thumbnail-ep" src="http://image.noelshack.com/fichiers/2015/35/1440684992-img.jpg"/>
</div>
<span class="episode-nb"> <p>001</p></span>
<div class="episode-single- content">
<div class="episode-single-title">
<h5><b>Lorem Ipsum Title</b></h5>
</div>
<div class="episode-single- desc">
<p><b>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b>
<br> Sed interdum luctus erat, in Sed interdum luctus erat, in</p>
<hr2>
<span class="cast"><p> <b>Scénario:</b> Sed interdum · <b>Art:</b> Sed interdum · <br>
<b>Animation:</b> Sed interdum · <b>Réalisation:</b> Sed interdum</p></span>
</div>
</div>
</div>
<div class="episode-box">
<div class="episode-img">
<img class="thumbnail-ep" src="http://image.noelshack.com/fichiers/2015/35/1440684992-img.jpg"/>
</div>
<span class="episode-nb"><p>001</p></span>
<div class="episode-single-content">
<div class="episode-single-title">
<h5><b>Lorem Ipsum Title</b></h5>
</div>
<div class="episode-single-desc">
<p><b>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b>
<br> Sed interdum luctus erat, in Sed interdum luctus erat, in</p>
<hr2>
<span class="cast"><p> <b>Scénario:</b> Sed interdum · <b>Art:</b> Sed interdum · <br>
<b>Animation:</b> Sed interdum · <b>Réalisation:</b> Sed interdum</p></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!--.post-box-->
</article>

You need to use media queries
Something like this: (Minimize your browser to see the effect)
.full-width {
margin: 0 0 30px;
padding: 0;
}
.container {
max-width: 1170px;
width: 100%;
}
.row {
margin-right: -15px;
margin-left: -15px;
}
#media (min-width: 1200px)
.col-md-12 {
width: 100%;
}
.guide-art-container {
padding: 25px;
}
.saga-title {
margin-top: 15px;
}
.episode-box {
width: auto;
background-color: #F9F9F9;
margin-top: 7px;
box-shadow: inset 0px 100px 150px -150px rgba(204,204,204,1);
height: 150px;
border: 1px solid #E8E8E8;
position: relative;
}
.episode-img {
float: left;
}
.episode-box img {
float: left;
margin-right: 10px;
padding: 5px;
}
span.episode-nb {
position: absolute;
bottom: 2px;
left: 5px;
background-color: #FC8A19;
max-width: 100px;
width: 100%;
opacity: 0.8;
text-align: center;
color: #fff;
font-weight: bold;
font-size: 15pt;
}
.episode-single-content {
padding: 10px 10px 10px 0px;
max-height: 150px;
}
.episode-single-desc {
max-height: 150px;
font-size: 9pt;
padding-right: 4px;
padding-left: 5px;
padding-top: 5px;
}
span.cast {
font-size: 7.4pt !important;
font-family: 'Roboto', Arial, Tahoma, Sans-serif;
line-height: 19px;
}
.thumbnail-ep {
float: left;
margin-right: 10px;
position: relative;
max-width: 260px;
width: 100%;
padding: 2px;
}
span.episode-nb {
position: absolute;
bottom: 2px;
left: 5px;
background-color: #FC8A19;
max-width: 100px;
width: 100%;
opacity: 0.8;
text-align: center;
color: #fff;
font-weight: bold;
font-size: 15pt;
}
.episode-single-title h5 {
margin-top: 2px !important;
}
#media only screen and (max-width : 480px) {
.episode-img {
float:none;
position:relative;
}
.episode-box img {
float:none;
}
.thumbnail-ep {
float:none;
}
.episode-box {
height:auto;
}
}
<article class="full-width">
<div class="post-box">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="guide-art-container">
<div class="episode-content">
<div class="saga">
<div class="row">
<div class="col-md-12">
<div class="episode-box">
<div class="episode-img">
<img class="thumbnail-ep" src="http://image.noelshack.com/fichiers/2015/35/1440684992-img.jpg"/>
<span class="episode-nb"><p>001</p></span>
</div>
<div class="episode-single-content">
<div class="episode-single-title">
<h5><b>Lorem Ipsum Title</b></h5>
</div>
<div class="episode-single-desc">
<p><b>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b>
<br> Sed interdum luctus erat, in Sed interdum luctus erat, in</p>
<hr2>
<span class="cast"><p><b>Scénario:</b> Sed interdum · <b>Art:</b> Sed interdum · <br>
<b>Animation:</b> Sed interdum · <b>Réalisation:</b> Sed interdum</p></span>
</div>
</div>
</div>
<div class="episode-box">
<div class="episode-img">
<img class="thumbnail-ep" src="http://image.noelshack.com/fichiers/2015/35/1440684992-img.jpg"/>
<span class="episode-nb"><p>001</p></span>
</div>
<div class="episode-single-content">
<div class="episode-single-title">
<h5><b>Lorem Ipsum Title</b></h5>
</div>
<div class="episode-single-desc">
<p><b>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b>
<br> Sed interdum luctus erat, in Sed interdum luctus erat, in</p>
<hr2>
<span class="cast"><p><b>Scénario:</b> Sed interdum · <b>Art:</b> Sed interdum · <br>
<b>Animation:</b> Sed interdum · <b>Réalisation:</b> Sed interdum</p></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!--.post-box-->
</article>
JS Fiddle

You need media query.
Suppose we have .high-height-in-xs-device
#media screen and (max-width:767px) {
.high-height-in-xs-device {
height: 800px;
}
}
The above CSS will only work in screen with width narrower than 767px, which is a bootstrap standard for xs screen widths.

Related

Responsive footer design - wrapping footer items

I am trying to write a responsive footer. The footer items are separated by vertical bar (|). When we decrease the screen size, the footer items are wrapping to second line. Vertical bar (|) needs to be only between the footer items. Also facebook logo needs to be on the same line with the footer items for bigger screen sizes and on the center for smaller screen sizes. I used float:right but now they wrap from the beginning. How can I make them wrap from the end and hide vertical bar (|) if it is not between the footer items?
Here is my source code: https://jsfiddle.net/6kcdvteo/
body {
font-family: 'Calibri';
}
.text {
font-size: 1rem;
padding: 1rem 1rem 2rem 2rem;
color: #666666;
background-color: #f4f4f4;
}
.footer {
font-size: 0.85rem;
padding: 2rem 1rem 2rem 2rem;
background-color: #303741;
color: white;
}
.footer_company {
float: right;
padding-right: 2rem;
}
.footer_links {
font-size: 0.85rem;
background-color: #303741;
color: white;
padding-bottom: 2rem;
padding-right: 2.5rem;
}
.footer_links_span span {
background-color: #303741;
padding-right: 0.5rem;
float: right;
}
img {
height: 3rem;
width: 3rem;
}
.img {
padding-left: 1rem;
display: inline-block;
}
<div class="text">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ac cursus felis, ut egestas lacus. Sed nec elementum ipsum. Morbi metus est, venenatis at libero pharetra, suscipit posuere dolor. Proin a auctor nulla, sed tincidunt tellus. Nullam bibendum
luctus elit, sed porttitor lectus varius in. Cras venenatis rutrum urna at ultrices. Sed in luctus ligula.
</p>
</div>
<div class="footer">
<span class="footer_company">© My Company Name</span>
</div>
<div class="footer_links">
<div class="img">
<img src="https://image.flaticon.com/icons/png/512/124/124010.png">
</div>
<div class="footer_links_span">
<span>Sed metus</span>
<span>|</span>
<span>Aenean ultricies</span>
<span>|</span>
<span>Praesent vitae</span>
<span>|</span>
<span>Donec auctor</span>
<span>|</span>
<span>Vestibulum lobortis</span>
</div>
</div>
As part of your question you can use this
<div class="footer_links">
<div class="img">
<img src="https://image.flaticon.com/icons/png/512/124/124010.png" alt="">
</div>
<div class="footer_links_span">
<span><b>|</b> Sed metus</span>
<span><b>|</b> Aenean ultricies</span>
<span><b>|</b> Praesent vitae</span>
<span><b>|</b> Donec auctor</span>
<span><b>|</b> Vestibulum lobortis <b>|</b></span>
</div>
</div>
with this css
/* container */
.footer_links {
padding: 0.75rem 1.5rem;
font-size: 0.85rem;
background-color: #303741;
color: white;
}
/* clearfix floats */
.footer_links::after {
display: block;
clear: both;
content: "";
}
/* facebook img */
.img {
float: left;
}
.img img {
width: 3rem;
height: auto;
border: 0;
}
/* links */
.footer_links_span {
float: right;
width: calc(100% - 3.5rem);
text-align: right;
}
.footer_links_span span {
display: inline-block;
white-space: nowrap;
background-color: #303741;
}
.footer_links b {
padding: 0 0.2rem;
font-weight: inherit;
}
.footer_links_span span:first-child b {
padding-left: 0;
}
.footer_links_span span:last-child b {
padding-right: 0;
}
Maybe it will help you in the right direction.
This will solve your problem, but it's Bootstrap :) All your responsive screenshotes are implemented in this code. No extra css for the layout required.
EDIT: The included style is for the width of the links block and for hiding the pipe symbool on small screens.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Page</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style type="text/css">
#footerSocial img { width: 3rem; margin-bottom: 0.5rem; }
#footerLinks > div { max-width: 350px; margin: auto; }
#footerLinks .dv { font-weight: inherit; display: none; }
#media (min-width: 576px) {
#footerSocial img { margin-bottom: 0; }
#footerLinks > div { max-width: none; padding-left: 100px; }
}
#media (min-width: 768px) {
#footerLinks > div { padding-left: 0; }
#footerLinks .dv { display: inline; }
}
</style>
</head>
<body>
<div class="container-fluid bg-secondary text-white">
<div class="row py-3">
<div class="col-12 text-center">
<h1 class="mb-2">Company Name</h1>
</div>
</div>
</div>
<div class="container">
<div class="row py-3">
<div class="col-12 ">
<h2>Article</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ac cursus felis, ut egestas lacus.
Sed nec elementum ipsum. Morbi metus est, venenatis at libero pharetra, suscipit posuere dolor.
Proin a auctor nulla, sed tincidunt tellus. Nullam bibendum luctus elit, sed porttitor lectus
varius in. Cras venenatis rutrum urna at ultrices. Sed in luctus ligula.</p>
</div>
</div>
</div>
<div class="container-fluid bg-dark text-white">
<div class="row px-2 py-3">
<div id="footerSocial" class="col-12 col-sm-2 text-center text-sm-left">
<img class="img-fluid bg-white" src="https://image.flaticon.com/icons/png/512/124/124010.png" alt="FB">
</div>
<div id="footerLinks" class="col-12 col-sm-10 text-center text-sm-right">
<div>
© Company Name<br>
<span class="text-nowrap">Sed metus</span>
<span class="text-nowrap">| Aenean ultricies</span>
<span class="text-nowrap">| Praesent vitae</span>
<span class="text-nowrap"><b class="dv">| </b>Donec auctor</span>
<span class="text-nowrap">| Vestibulum lobortis</span>
</div>
</div>
</div>
</div>
</body>
</html>

The boxes on the mobile view of this page aren't centered and full width

The boxes on the services page aren't centered and aren't full width.
I have tried changing the margin to 0 auto location, I have also tried align-content: center:
ul#services li {
list-style: none;
padding: 20px;
border: #cccccc solid 1px;
margin-bottom: 5px;
background: #e6e6e6;
}
.page-title {
font-family: Playfair Display;
font-size: 18px;
}
#media (max-width: 768px) {
header#bradning,
header nav,
header nav li,
#newsletter h1,
#newsletter h1,
#newsletter form,
#boxes .box,
article#main-col,
aside#sidebar,
ul#services,
main {
float: none;
text-align: center;
width: 100%;
font-size: 14px;
margin: 0 auto;
}
header {
padding-bottom: 20px;
}
#showcase h1 {
margin-top: 40px;
}
#newsletter h1 {
text-align: center;
font-size: 24px;
}
#newsletter button,
#sidebar-quote button {
display: block;
width: 100%;
}
#newsletter form input[type="email"],
#sidebar-quote input,
#sidebar-quote textarea {
width: 100%;
margin-bottom: 5px;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<section id="main">
<div class="container">
<article id="main-col">
<h1 class="page-title">Services</h1>
<ul id="services">
<li>
<h3>Website Design</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mi augue, viverra sit amet ultricies at, vulputate id lorem. Nulla facilisi.</p>
<p>Pricing: $1,000 - $3,000</p>
</li>
<li>
<h3>Website Maintenance</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mi augue, viverra sit amet ultricies at, vulputate id lorem. Nulla facilisi.</p>
<p>Pricing: $250 per month</p>
</li>
<li>
<h3>Website Hosting</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mi augue, viverra sit amet ultricies at, vulputate id lorem. Nulla facilisi.</p>
<p>Pricing: $25 per month</p>
</li>
</ul>
</article>
<aside id="sidebar">
<div class="dark">
<h3>Get A Quote</h3>
<form class="quote">
<div>
<label>Name</label><br>
<input type="text" placeholder="Name">
</div>
<div>
<label>Email</label><br>
<input type="email" placeholder="Emial Address">
</div>
<div>
<label>Message</label><br>
<textarea placeholder="Message"></textarea>
</div>
<button class="button_1" type="submit">Send</button>
</form>
</div>
</aside>
</div>
</section>
I expect the boxes to be centered and the same width as the get a quote section.
If anyone can help with this issue that would be great I am not sure what to do next, the site is functional as is but doesn't look as good as I was hoping.
you want it like this right?
I just set some css property to ul#services see below
#services{padding: 0;display: block; margin: 0 auto;}
ul#services li {
list-style: none;
padding: 20px;
border: #cccccc solid 1px;
margin-bottom: 5px;
background: #e6e6e6;
}
#services {
padding: 0;
display: block;
margin: 0 auto;
}
.page-title {
font-family: Playfair Display;
font-size: 18px;
}
#media (max-width: 768px) {
header#bradning,
header nav,
header nav li,
#newsletter h1,
#newsletter h1,
#newsletter form,
#boxes .box,
article#main-col,
aside#sidebar,
ul#services,
main {
float: none;
text-align: center;
width: 100%;
font-size: 14px;
margin: 0 auto;
}
header {
padding-bottom: 20px;
}
#showcase h1 {
margin-top: 40px;
}
#newsletter h1 {
text-align: center;
font-size: 24px;
}
#newsletter button,
#sidebar-quote button {
display: block;
width: 100%;
}
#newsletter form input[type="email"],
#sidebar-quote input,
#sidebar-quote textarea {
width: 100%;
margin-bottom: 5px;
}
}
<section id="main">
<div class="container">
<article id="main-col">
<h1 class="page-title">Services</h1>
<ul id="services">
<li>
<h3>Website Design</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mi augue, viverra sit amet ultricies at, vulputate id lorem. Nulla facilisi.</p>
<p>Pricing: $1,000 - $3,000</p>
</li>
<li>
<h3>Website Maintenance</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mi augue, viverra sit amet ultricies at, vulputate id lorem. Nulla facilisi.</p>
<p>Pricing: $250 per month</p>
</li>
<li>
<h3>Website Hosting</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mi augue, viverra sit amet ultricies at, vulputate id lorem. Nulla facilisi.</p>
<p>Pricing: $25 per month</p>
</li>
</ul>
</article>
<aside id="sidebar">
<div class="dark">
<h3>Get A Quote</h3>
<form class="quote">
<div>
<label>Name</label><br>
<input type="text" placeholder="Name">
</div>
<div>
<label>Email</label><br>
<input type="email" placeholder="Emial Address">
</div>
<div>
<label>Message</label><br>
<textarea placeholder="Message"></textarea>
</div>
<button class="button_1" type="submit">Send</button>
</form>
</div>
</aside>
</div>
</section>

Margin creating white space on page [duplicate]

This question already has answers here:
CSS margin terror; Margin adds space outside parent element [duplicate]
(7 answers)
Closed 4 years ago.
I am trying to create a space above "Affordable Professional Web Design" in the image below, so that it creates a space which is occupied by the image
However when I do so, it only seems to push the image down and leaves white space (indicated in red). I am trying to do this by applying margin-top although cannot find a resolution. Any ideas how to resolve?
Web Page Image
/* Global */
.container {
width: 80%;
margin: auto;
overflow;
hidden;
}
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0;
}
ul {
margin: 0;
padding: 0;
}
/* Header */
header {
background-color: #35424a;
border-bottom: orange solid;
min-height: 70px;
padding-top: 30px;
color: #ffffff;
}
header #branding {
float: left;
}
header #branding h1 {
margin: 0;
}
header li {
float: left;
list-style: none;
padding: 0 10px 0 10px;
}
header nav {
float: right;
text-transform: uppercase;
}
header a {
text-decoration: none;
color: #ffffff;
}
#highlight,
#current a {
color: #e8491d;
}
nav a:hover {
color: orange;
}
/* Showcase */
#showcase {
min-height: 400px;
background: url('../countryside.jpg') no-repeat;
background-size: cover;
text-align: center;
color: #ffffff;
}
#showcase h1 {
margin-top: 100px;
padding: 30px;
text-align: center;
color: #ffffff;
font-size: 50px;
}
#showcase p {
text-align: center;
color: #ffffff;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>My Website</title>
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" width="device-width" />
</head>
<body>
<header>
<div class="container">
<div id="branding">
<h1><span id="highlight">Test</span> Web Design</h1>
</div>
<nav>
<ul>
<li id="current">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
<section id="showcase">
<div class="container">
<h1>Affordable Professional Web Design</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eget nulla molestie, dictum purus vel, dapibus turpis. Aliquam malesuada laoreet ante. Integer dictum ipsum sed arcu commodo laoreet ultrices ac est. Nullam sagittis eget arcu nec
mollis.
</p>
</div>
</section>
<section id="newsletter">
<div class="container">
<form>
<h2>Subscribe to our newsletter</h2>
<input type="email" placeholder="Enter email..." />
<button type="submit">Submit</button>
</form>
</div>
</section>
<section class="boxes">
<div class="container">
<div class="box">
<img src="HTML.png" alt="" />
<h3>HTML Markup</h3>
<p>In a orci nec nunc posuere placerat. Etiam imperdiet libero ac enim faucibus, ac commodo lacus mollis.</p>
</div>
<div class="box">
<img src="css.png" height="200px" alt="" />
<h3>CSS3 Styling</h3>
<p>In a orci nec nunc posuere placerat. Etiam imperdiet libero ac enim faucibus, ac commodo lacus mollis.</p>
</div>
<div class="box">
<img src="graphic_design.svg" height="300px" alt="" />
<h3>Graphic Design</h3>
<p>In a orci nec nunc posuere placerat. Etiam imperdiet libero ac enim faucibus, ac commodo lacus mollis.</p>
</div>
</div>
</section>
</body>
Instead of margin try using padding:
#showcase h1{
padding:100px 30px 30px 30px;
text-align:center;
color:#ffffff;
font-size:50px;
}

Adding number in top left corner of Div

I want to add a number to the top left corner of my div's, but whatever I have tried so far has not worked properly.
Here is what I currently have:
Here is what I would like:
Here is the code:
#Office365, #OneDrive {
height: 100px;
width: 16.259%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 5px;
background-color: #F2F2F2;
}
<div class="row" id="firstAppRow">
<div class="col-sm-2" id="Office365" style="padding-top: 20px; font-weight: bold;">
<span>1</span>
<div><img src="/TrainingResourceCenter/O365Training/PublishingImages/OVbiWcG.png" height="50px" width="50px" />
<p>Office365</p>
</div>
</div>
<div class="col-sm-2" id="OneDrive" style="padding-top: 20px; font-weight: bold;">
<div><img src="/TrainingResourceCenter/O365Training/PublishingImages/wJAtQYP.png" height="40px" width="40px" />
<p>OneDrive</p>
</div>
</div>
</div>
He, the solution will be to use absolute position for the numbers.
Note that the blocks containing the tag with the number will need to be positioned relative so that the numbers are absolute to that block. Here is a sample code
#Office365,#OneDrive{
display: inline-block;
margin-right: 2px;
background-color: #F2F2F2;
position:relative;
border:1px solid black;
padding: 0 50px;
text-align: center;
}
#Office365 img,#OneDrive img{
width:100px;
height: auto;
}
.num{
position: absolute;
top: 5px;
left: 5px;
}
<div class="row" id="firstAppRow">
<div class="col-sm-2" id="Office365" style="padding-top: 20px; font-weight: bold;">
<div><img src="https://png.icons8.com/color/1600/office-365.png" height="50px" width="50px" />
<p>Office365</p>
<span class="num">1</span>
</div>
</div>
<div class="col-sm-2" id="OneDrive" style="padding-top: 20px; font-weight: bold;">
<div><img src="https://bcpsodl.pbworks.com/f/1477585037/onedrive.png" height="40px" width="40px" />
<p>OneDrive</p>
<span class="num">2</span>
</div>
</div>
</div>
Try assigning
position: relative;
to the #Office365 and #OneDrive. Also put the images inside those divs.
Then assign
position: absolute;
left: 1px;
top: 1px;
to #Office365 span and #OneDrive span.
absolute vs float
.a {
width: 200px;
position: relative;
border: 1px solid gray;
margin-right:20px;
display:inline-block;
vertical-align:top;
}
.viaAbsolute {
position: absolute;
top:0;
left: 0;
padding: 3px;
border: 1px solid red;
}
.viaFloat {
float: left;
padding: 3px;
border: 1px solid red;
}
<div class="a">
<span class="viaAbsolute">
1
</span> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tempus rhoncus quam quis vestibulum. Cras eu mollis nisl. Pellentesque semper tincidunt placerat.
</div>
<div class="a">
<span class="viaFloat">
1
</span> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tempus rhoncus quam quis vestibulum. Cras eu mollis nisl. Pellentesque semper tincidunt placerat.
</div>

Display flex a few block with text in the same line

I am trying to create a few block/box with image and two text - headline and subtext, but headline sometimes has one sentence, but another more, so if one has one and second one has two I would like to center vertically this first one.
For subtext I would like to vertically to the top.
Here is code which I am trying to use:
<div class="row row-home">
<div class="col-sm-4">
<img src="/images/home-1.png" alt="Schody" class="center-block img-responsive" />
<div class="text">
<h2>Schody</h2>
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit. Nulla volut pat sem id turpis tempus efficitur. Maecenas eu bibendum sem.</h3>
</div>
</div>
<div class="col-sm-4">
<img src="/images/home-2.png" alt="Balustrady" class="center-block img-responsive" />
<div class="text">
<h2>Balustrady i ogrodzenia</h2>
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit. Nulla volut pat sem id turpis tempus efficitur. Maecenas eu bibendum sem.</h3>
</div>
</div>
<div class="col-sm-4">
<img src="/images/home-3.png" alt="Meble" class="center-block img-responsive" />
<div class="text">
<h2>Meble</h2>
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit. Nulla volut pat sem id turpis tempus efficitur. Maecenas eu bibendum sem.</h3>
</div>
</div>
</div>
Here is CSS:
#home .text {
display: flex;
flex-direction: column;
-ms-flex-direction: column;
position: relative;
text-align: center;
padding: 10px 20px 30px;
margin: 0px auto 40px;
width: 100%;
height: 100%;
max-width: 236px;
z-index: 1;
}
#home .text h2 {
display: flex;
flex-direction: column;
-ms-flex-direction: column;
justify-content: center;
flex: 1 0 auto;
position: relative;
color: white;
font-size: 14px;
font-weight: bold;
text-transform: uppercase;
margin-top: 40px;
margin-bottom: 0px;
z-index: 2;
}
#home .text h3 {
position: relative;
color: white;
font-size: 12px;
text-align: justify;
text-transform: uppercase;
text-align-last: center;
z-index: 2;
}
It almost work, but if h3 has less text in one of blocks this text align to the bottom and h2 goes down.
Here is live website to test
I create picture to show how it should work
Since the h2 elements aren't aware of each other, I suggest you give them a height, or else you will need a extensive markup change
Here I added height: 28px; to the .row-home .text h2 rule
.row-home .text {
display: flex;
flex-direction: column;
-ms-flex-direction: column;
position: relative;
text-align: center;
padding: 10px 20px 30px;
margin: 0px auto 40px;
width: 100%;
height: 100%;
max-width: 236px;
z-index: 1;
}
.row-home .text h2 {
display: flex;
flex-direction: column;
-ms-flex-direction: column;
justify-content: center;
flex: 1 0 auto;
position: relative;
color: white;
font-size: 14px;
height: 28px;
font-weight: bold;
text-transform: uppercase;
margin-top: 40px;
margin-bottom: 0px;
z-index: 2;
}
.row-home .text h3 {
position: relative;
color: white;
font-size: 12px;
text-align: justify;
text-transform: uppercase;
text-align-last: center;
z-index: 2;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row row-home">
<div class="col-sm-4">
<img src="http://malykowal.linuxpl.eu/images/home-1.png" alt="Schody" class="center-block img-responsive" />
<div class="text">
<h2>Schody</h2>
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit. Nulla volut pat sem id turpis tempus efficitur. Maecenas eu bibendum sem.</h3>
</div>
</div>
<div class="col-sm-4">
<img src="http://malykowal.linuxpl.eu/images/home-1.png" alt="Balustrady" class="center-block img-responsive" />
<div class="text">
<h2>Balustrady i ogrodzenia</h2>
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit. Nulla volut pat sem id turpis tempus efficitur. Maecenas eu bibendum sem.</h3>
</div>
</div>
<div class="col-sm-4">
<img src="http://malykowal.linuxpl.eu/images/home-1.png" alt="Meble" class="center-block img-responsive" />
<div class="text">
<h2>Meble</h2>
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit. Nulla volut pat sem id turpis tempus efficitur. Maecenas eu bibendum sem.</h3>
</div>
</div>
</div>
</div>
Updated with a second version based on a comment
If you want this to be really dynamic, you'll need to break it down like this, where you make the col-sm-4 flex items
Updated again, with a media query, to utilize Flexbox's order property and re-position the elements on smaller screens
.row-home {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.row-home .col-sm-4 {
min-width: 0;
flex-basis: 33%;
padding: 10px 20px 30px;
}
.row-home .col-sm-4.vcentered {
align-self: center;
}
.row-home .col-sm-4 h2 {
font-size: 14px;
font-weight: bold;
text-transform: uppercase;
}
.row-home .col-sm-4 h3 {
font-size: 12px;
text-align: justify;
text-transform: uppercase;
text-align-last: center;
}
#media (max-width: 600px) {
.row-home .col-sm-4 {
flex-basis: 51%;
}
.row-home .col-sm-4 * {
text-align: center;
}
.row-home .col-sm-4:nth-child(3n+1) {
order: 1;
}
.row-home .col-sm-4:nth-child(3n+2) {
order: 2;
}
.row-home .col-sm-4:nth-child(3n+3) {
order: 3;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row row-home">
<div class="col-sm-4">
<img src="http://malykowal.linuxpl.eu/images/home-1.png" alt="Schody" class="center-block img-responsive" />
</div>
<div class="col-sm-4">
<img src="http://malykowal.linuxpl.eu/images/home-1.png" alt="Balustrady" class="center-block img-responsive" />
</div>
<div class="col-sm-4">
<img src="http://malykowal.linuxpl.eu/images/home-1.png" alt="Meble" class="center-block img-responsive" />
</div>
<div class="col-sm-4 vcentered">
<h2>Schody this is some extra text I added for test</h2>
</div>
<div class="col-sm-4 vcentered">
<h2>Balustrady i ogrodzenia</h2>
</div>
<div class="col-sm-4 vcentered">
<h2>Meble</h2>
</div>
<div class="col-sm-4">
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit.</h3>
</div>
<div class="col-sm-4">
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit. Nulla volut pat sem id turpis tempus efficitur. Maecenas eu bibendum sem.</h3>
</div>
<div class="col-sm-4">
<h3>Lorem ipsum dolor sit amet, consectetur adipi scing elit. Nulla volut pat sem id turpis tempus efficitur. Maecenas eu bibendum sem.</h3>
</div>
</div>
</div>