Related
I have a container and an element withing it.
<div id="container">
<div class="myEm">
...
</div>
</div>
I need to assign width and hight to that element. It should be a square. I can calculate the width relative to the parent container, but how do I pass the same value to the height:
#container .myEm {
width: calc(100% - 20px);
height: ???
}
One way is to make the myEm resize using padding bottom (or top) to maintain its aspect ratio. This makes myEm strictly a sizing element and you'll need an element inside that will size to itself. Here's what I mean for example:
myEm becomes:
.myEm {
height: 0;
padding-bottom: calc(100% - 20px);
position: relative;
width: calc(100% - 20px);
}
Then you need an element inside with the actual content:
.myEm-inner {
background: red;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
Example: https://jsfiddle.net/dgmyxs9v/1/
You can save yourself the wrapping div by using pseudo elements.
This solution will create the same effect – but also make the div stretch to fit content – should it become too large to be contained by the square.
/* sane box-sizing */
html { box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }
/* box styling */
.box {
margin: 10px;
padding: 10px;
width: calc(100% - 20px);
background-color: tomato;
font-size: 10px;
float: left;
max-width: 150px;
}
/* ––––––––––––––––––––––––––––––––––––-
This is the aspect ratio part
––––––––––––––––––––––––––––––––––––- */
.box::before {
/* aspect ratio keeper – 100% = square */
padding-bottom: 100%;
float: left;
}
.box::before,
.box::after {
content: '';
display: table;
clear: both;
}
/* second box */
.box:nth-of-type(2) { background-color: olive; }
<div class="box">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita labore iusto vero perspiciatis ex fuga natus cum molestiae ut, dolor facere maxime voluptatem nesciunt nihil repellendus culpa eligendi laudantium velit.</p>
</div>
<div class="box">
<h2>Will stretch to content</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita labore iusto vero perspiciatis ex fuga natus cum molestiae ut, dolor facere maxime voluptatem nesciunt nihil repellendus culpa eligendi laudantium velit. Expedita labore iusto vero perspiciatis ex fuga natus cum molestiae ut, dolor.</p>
</div>
I am looking for a css3 responsive technique to have two side-by-side divs (stacked on smaller screens), one with text, the other one filled entirely with an image. At minimum, the image aspect ratio must be maintained; ideally both divs should always be squares of the same size (even when stacked).
Edit - fiddle:
https://jsfiddle.net/marekjedlinski/zdwdhLmg/
html:
<div class="outer outer-left">
<div class="inner inner-text inner-text-left block-orange">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas pharetra lorem in ligula volutpat euismod. Nullam eu lorem tellus. Donec luctus lacus in felis blandit quis accumsan nulla imperdiet. Phasellus lorem quam, egestas et scelerisque ac, consequat nec diam. Nunc elit elit, venenatis at eleifend eget, feugiat eu elit.</p>
</div>
<div class="inner inner-img">
<img src="image-1-300.jpg" />
</div>
</div>
<div class="outer outer-right">
<div class="inner inner-img">
<img src="image-2-300.jpg" />
</div>
<div class="inner inner-text inner-text-right block-green">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas pharetra lorem in ligula volutpat euismod. Nullam eu lorem tellus. Donec luctus lacus in felis blandit quis accumsan nulla imperdiet. Phasellus lorem quam, egestas et scelerisque ac, consequat nec diam. Nunc elit elit, venenatis at eleifend eget, feugiat eu elit.</p>
</div>
</div>
css:
* {
box-sizing: border-box;
}
html, body {
width: 100%;
font-size: 18px;
margin: 0;
}
.outer {
display: flex;
flex-direction: row;
}
.outer-left {
flex-wrap: wrap-reverse; /* when wrapped, image must sit on top of text */
}
.outer-right {
flex-wrap: wrap;
}
.inner {
flex: 1 1 300px; /* grow, shrink, basis */
}
.inner-img {
background: #563D7C;
text-align: right;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden
}
.inner-img img {
flex-shrink: 0;
min-width: 100%;
min-height: 100%
}
/* below only text styling for text divs, not relevant */
I can get some of the way using flexbox. This is the starting point, the ideal situation:
When the browser window grows however, the images get stretched:
At minimum, I want the aspect ratio to be maintained. It's OK if the image gets clipped, but ideally I would like the squares to grow as squares (both for image and text), so that the image would be proportionally resized.
Now, when horizontal space shrinks and the divs get stacked, the images are again stretched:
Here i still want the image divs and the text divs to remain perfect squares, but at the very least the aspect ratio must be maintained
Ideally, like this:
I can use flexbox or any earlier techniques, but I need this to be fairly compatible, not bleeding-edge (object-fit seems too futuresque, for example).
There are similar questions here and here, and they come close, but do (not solve this specific issue.)
edit ?? your fiddle works fine ?!
if background and object-fit is not the answer and you 'd like to use flex, i believe best is to start with square image and center content aside it.
You can use mediaquery to switch display behavior of divs and reset order.
here is an example:
/* ================================== */
/* DEMO USING A SINGLE FLEX CONTAINER */
/* ================================== */
/* use your own tags, class and sizes */
/* ================================== */
div {
display: flex;
flex-wrap: wrap;
width: 80%;
min-width: 300px;
max-width: 800px;
margin: auto;
}
div > * {
flex: 1 1 340px;
min-width: 50%;
}
div > div {
background: green;
display:flex;
align-items:center;
padding: 1em;
margin: 0;
box-sizing: border-box;
color:white;
}
div div:first-of-type {
order: -1;
background:rgb(148, 98, 39);
}
div:before {
content: "";
display:inline-block;
vertical-align:middle;
padding-top: 100%;
width:0;
}
div p {
display:inline-block;
vertical-align:middle;
max-width:99%;
}
#media screen and (max-width:866px) {
div div , div div:first-of-type {display:block;order:0;}
}
<div>
<img src="http://lorempixel.com/300/300/cats">
<div><p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo.</p></div>
<img src="http://lorempixel.com/300/300/animals">
<div><p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus
lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor,
facilisis luctus, metus</p></div>
</div>
Same question and symptoms as this question but maybe a different cause (the answer didn't offer any clues for me), plus I have to create a new question because I've just signed up... now hoping for help :o)
I get this validation error when validating an AMP page:
The mandatory text (CDATA) inside tag 'head > style : boilerplate' is missing or incorrect.
I've followed all the guidelines here, including adding the AMP boilerplate code in the head section.
The validator points to this chunk of code, which is as prescribed by the AMP project:
<noscript><style amp-boilerplate>
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}
</style></noscript>
I can't see a problem with the above... Can anybody else offer any advice or pointers please?
I'm creating the AMP page in an Umbraco 7 template if that makes a difference...
EDIT:
Here's the HTML output...
UPDATE: I just found and ran this markup through https://developers.google.com/structured-data/testing-tool/ and it produced a different error Missing ',' or '}' in object declaration. which I can't spot... maybe problem relates to my JSON-LD...?
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<title>Blah shortlisted at Awards for Excellence 2015</title>
<link rel="canonical" href="http://somedomain.local/news-media/news-media-headlines/2015/oct/blah-shortlisted-at-awards-for-excellence-2015/" />
<link href='https://fonts.googleapis.com/css?family=Roboto:500,400italic,300,700,400|PT+Sans:700' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "NewsArticle",
"mainEntityOfPage": "http://somedomain.local/news-media/news-media-headlines/2015/oct/blah-shortlisted-at-awards-for-excellence-2015/",
"headline": "Blah shortlisted at Awards for Excellence 2015",
"description": "We're delighted to announce that Blah has been shortlisted for the 'Blah & blah blah' award at the...",
"datePublished": "10/28/2015 9:43:57 AM",
"author": {
"#type": "Organization",
"name": "Name here"
},
"publisher": {
"#type": "Organization",
"name": "Name here",
"logo": {
"#type": "ImageObject",
"url": "https://www.somedomain.com/img/logo.png",
"width": 600,
"height": 60
},
"image": {
"#type": "ImageObject",
"url": "https://www.somedomain.com/img/logo.png",
"height": 50,
"width": 165
}
}
</script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}#-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript><style amp-boilerplate>
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}
</style></noscript>
<style amp-custom>
body {
font-family: 'Roboto', sans-serif;
}
.sub-heading {
padding-left: 1rem;
padding-top: 0;
padding-bottom: 1em;
margin: 0;
color: #fff;
}
body > div {
padding: 1rem;
}
h1, h2 {
color: #fff;
padding: 1rem;
margin: 0;
}
h1, .sub-heading {
background-color: #009ed4;
}
h2 {
background-color: #00618e;
font-weight: 400;
font-size: 1.25em;
}
amp-img {
max-width: 100%;
}
.logo {
margin: 1em;
}
</style>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<amp-img width="165" height="50" class="logo" src="https://www.somedomain.com/img/logo.png" alt="Logo"></amp-img>
<h1>Blah shortlisted at Awards for Excellence 2015</h1>
<p class="sub-heading">26 October 2015</p>
<h2>We're delighted to announce that...</h2>
<div><p>This year is the 16th... </p>
<p ><amp-img layout="responsive" width="500"height="281" src="/media/9348/et.jpg?width=500&height=281" /></amp-img></p>
<p><a href="http://www.google.co.uk/" target="_blank" title="blah">blah blah</p>
<p ><amp-img layout="responsive" width="500"height="281" src="/media/9349/som.jpg?width=500&height=281" /></amp-img></p>
<p>orem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque augue nibh, congue eu dictum at, interdum et libero. Etiam malesuada vehicula felis, vel varius odio semper sit amet. Phasellus quis sapien sed turpis porta lobortis. Aenean rutrum risus ut scelerisque mollis. Suspendisse id feugiat erat.</p>
<p><amp-img layout="responsive" width="500"height="306.452" src="/media/9350/the_shining.jpg?width=500&height=306.4516129032258" alt="alt text here" /></amp-img></p>
<p>"quote here." orem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque augue nibh, congue eu dictum at, interdum et libero. Etiam malesuada vehicula felis, vel varius odio semper sit amet. Phasellus quis sapien sed turpis porta lobortis. Aenean rutrum risus ut scelerisque mollis. Suspendisse id feugiat erat.</p>
<p> </p>
<div>
<div>orem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque augue nibh, congue eu dictum at, interdum et libero. Etiam malesuada vehicula felis, vel varius odio semper sit amet. Phasellus quis sapien sed turpis porta lobortis. Aenean rutrum risus ut scelerisque mollis. Suspendisse id feugiat erat.</div>
</div></div>
</body>
</html>
You need to have full amp boilerplate code.
Replace your multiline boilerplate code:
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}#-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
<noscript><style amp-boilerplate>
body {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}
</style></noscript>
with this:
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}#-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
Allways up to date code is here: https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md
You have json syntax error in Publisher part.
"publisher": {
"#type": "Organization",
"name": "Name here",
"logo": {
"#type": "ImageObject",
"url": "https://www.somedomain.com/img/logo.png",
"width": 600,
"height": 60
} // You forget to close logo object.
},
Your AMP syntax errors:
Required:
The width of the image, in pixels. Images should be at least 696 pixels wide.
Recommended (and if added pass the test):
The date and time the article was most recently modified, in ISO 8601 format. If the article has never been modified, you can omit this property or use the same date as datePublished.
Another important thing is that URL's for images shouldn't be relative paths.
Here is your (modified - i replaced boilerplate code and images links) html:
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<title>Blah shortlisted at Awards for Excellence 2015</title>
<link rel="canonical" href="http://somedomain.local/news-media/news-media-headlines/2015/oct/blah-shortlisted-at-awards-for-excellence-2015/" />
<link href='https://fonts.googleapis.com/css?family=Roboto:500,400italic,300,700,400|PT+Sans:700' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "NewsArticle",
"mainEntityOfPage": "http://somedomain.local/news-media/news-media-headlines/2015/oct/blah-shortlisted-at-awards-for-excellence-2015/",
"headline": "Blah shortlisted at Awards for Excellence 2015",
"description": "We're delighted to announce that Blah has been shortlisted for the 'Blah & blah blah' award at the...",
"datePublished": "10/28/2015 9:43:57 AM",
"dateModified": "10/28/2015 9:43:57 AM",
"author": {
"#type": "Organization",
"name": "Name here"
},
"publisher": {
"#type": "Organization",
"name": "Name here",
"logo": {
"#type": "ImageObject",
"url": "https://www.somedomain.com/img/logo.png",
"width": 600,
"height": 60
}
},
"image": {
"#type": "ImageObject",
"url": "https://www.somedomain.com/img/logo.png",
"height": 50,
"width": 700
}
}
</script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}#-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}#keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
body {
font-family: 'Roboto', sans-serif;
}
.sub-heading {
padding-left: 1rem;
padding-top: 0;
padding-bottom: 1em;
margin: 0;
color: #fff;
}
body > div {
padding: 1rem;
}
h1, h2 {
color: #fff;
padding: 1rem;
margin: 0;
}
h1, .sub-heading {
background-color: #009ed4;
}
h2 {
background-color: #00618e;
font-weight: 400;
font-size: 1.25em;
}
amp-img {
max-width: 100%;
}
.logo {
margin: 1em;
}
</style>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<amp-img width="165" height="50" class="logo" src="http://i.kinja-img.com/gawker-media/image/upload/s--pEKSmwzm--/c_scale,fl_progressive,q_80,w_800/1414228815325188681.jpg" alt="Logo"></amp-img>
<h1>Blah shortlisted at Awards for Excellence 2015</h1>
<p class="sub-heading">26 October 2015</p>
<h2>We're delighted to announce that...</h2>
<div><p>This year is the 16th... </p>
<p ><amp-img layout="responsive" width="500"height="281" src="http://i.kinja-img.com/gawker-media/image/upload/s--pEKSmwzm--/c_scale,fl_progressive,q_80,w_800/1414228815325188681.jpg" /></amp-img></p>
<p><a href="http://www.google.co.uk/" target="_blank" title="blah">blah blah</p>
<p ><amp-img layout="responsive" width="500"height="281" src="http://i.kinja-img.com/gawker-media/image/upload/s--pEKSmwzm--/c_scale,fl_progressive,q_80,w_800/1414228815325188681.jpg" /></amp-img></p>
<p>orem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque augue nibh, congue eu dictum at, interdum et libero. Etiam malesuada vehicula felis, vel varius odio semper sit amet. Phasellus quis sapien sed turpis porta lobortis. Aenean rutrum risus ut scelerisque mollis. Suspendisse id feugiat erat.</p>
<p><amp-img layout="responsive" width="500"height="306.452" src="http://i.kinja-img.com/gawker-media/image/upload/s--pEKSmwzm--/c_scale,fl_progressive,q_80,w_800/1414228815325188681.jpg" alt="alt text here" /></amp-img></p>
<p>"quote here." orem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque augue nibh, congue eu dictum at, interdum et libero. Etiam malesuada vehicula felis, vel varius odio semper sit amet. Phasellus quis sapien sed turpis porta lobortis. Aenean rutrum risus ut scelerisque mollis. Suspendisse id feugiat erat.</p>
<p> </p>
<div>
<div>orem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque augue nibh, congue eu dictum at, interdum et libero. Etiam malesuada vehicula felis, vel varius odio semper sit amet. Phasellus quis sapien sed turpis porta lobortis. Aenean rutrum risus ut scelerisque mollis. Suspendisse id feugiat erat.</div>
</div></div>
</body>
</html>
Very useful and relevant advice from Pawel on the image URLs and JSON-LD error, which I used to correct my markup. In addition to that, the precise, final cause of my specific issue was a result of cutting/pasting the correct boilerplate code into Visual Studio... VS automatically reformatted the code and added spaces to the styles in the <noscript> tag. This is the reason validation still failed. So, make sure VS doesn't 'helpfully' reformat - there shouldn't be any space characters. Sigh...
You are missing a closing } in the JSON-LD script. Add the } after publisher height
I'm currently building a site with bootstrap on which I combine an image and a text block in each section and switch left/right every time. It looks like this and I used pull-left and pull-right for the images to keep them on the outer border aligned with the text below:
<div class="container-fluid standard-element">
<div class="row">
<div class="col-xs-6 col-md-6"><img src="./img/Placeholder_wideIcon.svg" class="img-responsive pull-left" alt="Responsive image"></div>
<div class="col-xs-12 col-md-6">
<h2>Headline</h2>
<p>Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Maecenas faucibus mollis interdum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean lacinia bibendum nulla sed consectetur. Cras mattis consectetur purus sit amet fermentum. Maecenas faucibus mollis interdum.</p>
</div>
</div>
</div>
<div class="container-fluid standard-element">
<div class="row">
<div class="col-xs-12 col-md-6">
<h2>#Agile</h2>
<p>Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Maecenas faucibus mollis interdum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean lacinia bibendum nulla sed consectetur. Cras mattis consectetur purus sit amet fermentum. Maecenas faucibus mollis interdum.</p>
</div>
<div class="col-xs-6 col-md-6"><img src="./img/Placeholder_wideIcon.svg" class="img-responsive pull-right" alt="Responsive image"></div>
</div>
</div>
The problem is now that the images are alway left aligned as soon as they hit the tablet portrait breakpoint when they stack over the text blocks. How can I center the images as soon as they are now longer next to the texts but stacked above/below them?
Thanks in advance,
Tim
you'll need to use media queries to target the desired cutting-point, like (say) 768px. Then add something like this (in this case, I'm cutting for iPad)
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
.pull-left, .pull-right{margin:0 auto /* change the 0 to your liking */; display:block; float: none}
}
EDIT: while the above could be useful for you on certain situations, I have noticed your problem is the HTML markup, and can be easily solved (plus a couple CSS lines).
HTML:
<div class="container-fluid header">
<div class="col-xs-12 col-md-12">
<img src="http://herbigt.com/doyouevenproduct/img/Placeholder_HeaderIcon.svg" class="img-responsive center-block header-image" alt="Responsive image" />
</div>
<div class="row">
<h1>Lorem Ipsum</h1>
<p class="lead">Nulla vitae elit libero, a pharetra augue. Aenean eu leo quam.
<br />Pellentesque ornare sem lacinia quam venenatis vestibulum.</p>
</div>
</div>
<div class="container-fluid standard-element">
<div class="row">
<div class="col-xs-12 col-md-6 imagebox">
<img style="border:1px solid red" src="http://herbigt.com/doyouevenproduct/img/Placeholder_wideIcon.svg" class="img-responsive " alt="Responsive image" />
</div>
<div class="col-xs-12 col-md-6">
<h2>Headline</h2>
<p>Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Maecenas faucibus mollis interdum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean lacinia bibendum nulla sed consectetur. Cras mattis consectetur purus sit amet fermentum. Maecenas faucibus mollis interdum.</p>
</div>
</div>
</div>
<div class="container-fluid standard-element">
<div class="row">
<div class="col-xs-12 col-md-6">
<h2>#Agile</h2>
<p>Cras mattis consectetur purus sit amet fermentum. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Maecenas faucibus mollis interdum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean lacinia bibendum nulla sed consectetur. Cras mattis consectetur purus sit amet fermentum. Maecenas faucibus mollis interdum.</p>
</div>
<div class="col-xs-12 col-md-6 imagebox">
<img style="border:1px solid red" src="http://herbigt.com/doyouevenproduct/img/Placeholder_wideIcon.svg" class="img-responsive " alt="Responsive image" />
</div>
</div>
</div>
CSS:
/*Elements*/
.header {
background-color: #95d1c4;
text-align: center;
padding: 2.5em;
}
.header-image {
padding: 0.5em;
}
.lead {
padding-top: 1.0em;
font-size: 2.8rem;
}
.standard-element {
margin-top: 5.0em;
margin-bottom: 5.0em;
margin-left: 3.0em;
margin-right: 3.0em;
padding-bottom: 5.0em;
border-bottom: 2px solid;
border-color: #EEEEEE;
}
.img-section {
border: 1px solid red;
}
.last-element {
border-bottom: none;
}
.footer {
background-color: #95d1c4;
color: #ffffff;
text-align: center;
padding: 1.5em;
}
/*Typography*/
h1, h2, h3, h4, h5, h6 {
font-family:'Source Sans Pro', sans-serif;
color: #E85C41;
}
h1 {
font-size: 4.8rem;
font-weight: 900;
}
h2 {
font-size: 3.8rem;
line-height: 7.0rem;
font-weight: 700;
}
p {
font-family:"chaparral-pro", serif;
font-size: 2.0rem;
font-weight: light;
color: #464646;
}
a, a:visited {
font-family:"chaparral-pro", serif;
text-decoration: underline;
font-size: 2.0rem;
font-weight: light;
color: #464646;
}
a:hover {
font-family:"chaparral-pro", serif;
text-decoration: none;
font-size: 2.0rem;
font-weight: light;
color: #464646;
}
ul {
font-family:"chaparral-pro", serif;
font-size: 2.0rem;
font-weight: light;
line-height: color: #464646;
text-indent: none;
}
.imagebox {
text-align:center
}
.imagebox img {
margin:0 auto
}
/* Media Queries */
/* Tablet Portrait*/
#media (max-width: 768px) and (min-width: 481px) {
.pull-left, .pull-right {
margin:0 auto;
display:block;
float: none !important;
}
.standard-element {
border: 1px solid red;
}
}
/* Mobile */
#media (max-width: 480px) and (min-width: 0px) {
.pull-left, .pull-right {
margin:0 auto;
display:block;
float: none !important;
}
.standard-element {
margin-left: 0em;
margin-right: 0em;
border: 1px solid red;
}
h2 {
line-height: 3.5rem;
}
}
Explanation: we're removing the pull-left and right classes and simply using the default Bootstrap columns behavior. Then we simply add an .imagebox class so we can target it and center the images. As simple as that.
Note: while might look minor, I've noticed you're not closing some of your tags. To the very least, your pages will never validate (in case that is a problem for you), so remember to use tags the XHTML way so if you don't get errors in validation that aren't really there. Images should go like this: <img src="your_image.jpg" alt="" /> and BREAK goes like this <br/> (note the trailing slashes).
I'm trying to make a layout using the new css3 flexbox model. I want a page that occupies 100% of the height, using has a fixed footer and header and the remaining content is on a column in the middle. The content column should occupy 100% of the width up to a fixed maximun width. Also, everything should be aligned in the center.
I managed to build it exactly to spec in this demo wich works great in chrome or any webkit based browser. But it breaks in firefox, where adding the "max-width" property makes everything a fixed column aligned to the left.
Can anyone enlight me on why this is not working in firefox? Is it a different interpretation of the spec, or is it an error in my code?
This is the HTML of the demo:
<div class="container">
<div class="header">Header</div>
<div class="content">
<div class="fixed">
<h1>Title</h1>
<div class="someText">
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vehicula sodales risus quis rhoncus. Donec suscipit lorem ante. Nullam tempor, lorem sit amet faucibus dictum, est nisl aliquam felis, a tempor arcu massa sit amet felis. Donec a blandit mi. Sed posuere, lacus eu scelerisque porttitor, turpis sem aliquam nulla, ut rutrum sem libero a felis. Morbi nec sodales odio. Nulla facilisi. Sed consectetur pellentesque arcu, in laoreet nulla semper ac. Pellentesque vulputate sem eget eros condimentum in malesuada dui convallis. Vivamus tristique velit id justo laoreet vestibulum. Nulla orci nisl, vulputate vitae facilisis sit amet, ultricies id massa. Sed eget faucibus magna. Integer a leo sem, hendrerit fermentum libero.</p>
<p>In gravida faucibus dui, quis bibendum est ornare nec. Cras ac metus a dui rhoncus mattis. Nulla ut hendrerit est. Cras sed sem felis, venenatis tincidunt ipsum. Vestibulum id sodales ligula. Nunc sit amet neque vel ante aliquam commodo. Aenean elit felis, imperdiet sagittis lacinia ut, tincidunt accumsan arcu. Vivamus dapibus ligula a est convallis eget tincidunt libero interdum. Nunc mattis, odio et tincidunt egestas, orci ante pharetra nulla, hendrerit ultrices nunc ipsum nec sem. Vestibulum egestas leo pulvinar massa mollis sit amet dapibus velit venenatis. Etiam molestie posuere lacinia. Nam ut nulla elit, ac tincidunt tellus. Nulla mollis metus id ante accumsan et mattis est ultricies. Morbi nec nunc nulla. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</div>
<div class="footer">
<div class="fixed">Footer</div>
</div>
</div>
and this is the CSS:
body, html {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
background:black;
}
.container {
height: 100%;
width: 100%;
display: -webkit-box;
-webkit-box-orient: vertical;
display: -moz-box;
-moz-box-orient: vertical;
}
.header, .footer {
background-color: #32403C;
height: 40px;
width: 100%;
margin: 0;
line-height: 40px;
vertical-align: middle;
text-align: center;
color: #FFF;
-webkit-box-pack: center;
-moz-box-pack: center;
box-pack: center;
display: -moz-box;
display: -webkit-box;
-webkit-box-flex: 0;
}
.content {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-box-flex: 1;
display: -moz-box;
-moz-box-orient: vertical;
-moz-box-flex: 1;
-webkit-box-align:center;
-moz-box-align:center;
box-align:center;
-webkit-box-pack: center;
-moz-box-pack: center;
box-pack: center;
}
.fixed {
background:#787;
-moz-box-flex: 1;
-webkit-box-flex: 1;
box-flex: 1;
width:100%;
max-width:480px;
overflow:hidden;
display: -webkit-box;
display: -moz-box;
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
}
.someText {
-webkit-mask-image: -webkit-linear-gradient( black, black 75%, transparent 95%);
-moz-box-flex: 1;
-webkit-box-flex: 1;
box-flex: 1;
overflow:scroll;
}
.content { background: #876; }
.colorLight { background-color: #A6687B; }
.colorMedium { background-color: #8C605F; }
.colorDark { background-color: #735E5A; }
What you're using in Gecko there is the XUL flexbox model, which has nothing to do with the old CSS flexbox drafts you were apparently reading (which also have nothing to do with the current flexbox drafts, which use a totally different display value, etc).
In particular, display: -moz-box has been around for 10+ years and has whatever behavior it has, while the flexbox draft you were reading is much newer and has behavior that's quite different from the -moz-box behavior. The WebKit flexbox implementation postdates the first W3C drafts or is contemporaneous with them, so is closer to what those drafts talks about. But again, the current drafts are completely different from those early ones...