Centering bootstrap images for tablets and smartphones - image

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).

Related

fill a div with an image in a responsive way

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>

Validation error in AMP page using Umbraco 7 template

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

Forcing image to be in same line as column of text

I'm not sure what I'm doing wrong here. I'm trying to force an image to be in the same line as a few columns of text, but it keeps shifting down like in this image: http://imgur.com/Hs43rXF. The left image is what I want it to look like, but I get the right image.
I've already tried display:inline and floats, but neither works. This is my code:
.page {
margin-top:50px;
padding-left:50px;
padding-right:50px;
position:relative;
width:1000px;
height:450px;
}
.leftcolumn {
margin-top:50px;
margin-left:0px;
width: 250px;
}
.middlecolumn {
margin-left:300px;
margin-right:320px;
margin-top:50px;
float:left;
display:inline;
}
.verticalimage {
margin-right:0;
margin-top:0;
float:right;
display:inline;
vertical-align:middle;
}
<div class="page">
<div class="leftcolumn">text <br> text <br> text</div>
<div class="middlecolumn">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet lorem velit. Nullam et metus eget nunc egestas laoreet et quis ligula. Vivamus lobortis sodales pulvinar. Nunc malesuada pretium ornare. Aliquam ut erat at magna pellentesque elementum. Fusce facilisis lorem et tortor euismod bibendum.</div>
<img class="rightverticalimage" src="picture1.png"/>
</div>
Thanks.
I tried this for ya. I took stuff out just so you understand the code. You can edit at your liking.
CSS
.page {
margin:5%;
width:100%;
height:450px;
}
div {
width:25%;
margin-left:3%;
float:left;
background-color:red;}
I made the BG red just so you can see where the div starts and stops
HTML
<div class="page">
<div>text <br /> text <br /> text</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet lorem velit. Nullam
et metus eget nunc egestas laoreet et quis ligula. Vivamus lobortis sodales pulvinar. Nunc
malesuada pretium ornare. Aliquam ut erat at magna pellentesque elementum. Fusce facilisis lorem
et tortor euismod bibendum.</div>
<div>
<img class="rightverticalimage" src="picture1.png"/>
</div>
</div>
Put the IMG in a div to help control it better.
Id also download FIREBUG onto Firefox cuz it helps with that stuff.
You're mixing a couple of different methods here. Firstly as you may have noticed with your leftcolumn, if you make a div display:inline it won't hold its width. This is because in order to render with a width or margins, an element must be block level (which divs are by default). Additionally, setting the left margin on the middlecolumn with the left div already there will set its left hand side to be at 550px within the container (250 for the leftcolumn and an additional 300 for left margin), margins and widths are cumulative.
So then two ways to do this are (I've left out your extra margins for brevity):
Using floats:
.leftcolumn
{
width: 250px;
float:left;
}
.middlecolumn
{
width: 250px;
float:left;
}
This will leave the two divs as block elements allowing them to behave as they normally would, setting the width on the two columns and continue the flow around them, since the image is an inline element, it will continue to flow as well. What this approach does do however is leave the container only as high as the image element since a floated element doesn't sit in the page flow in the same way.
Using display: inline-block
.leftcolumn
{
display: inline-block;
width: 250px;
}
.middlecolumn
{
display: inline-block;
width: 250px;
}
This will set the divs as inline-block allowing you to set a width on them, but rendering them as an inline element. The benefit of this is that the .page element will get the height of the divs automatically. It does, however break in ie7 since that doesn't render inline-block elements correctly.
I've intentionally left adding the width onto the image element since it will be the same across both approaches (just set display:block and float it, or set display: inline-block)

Scroll one vertically centered DIV without scrolling the other in the same box

Been working on this all night, had no idea it would be so hard. My goal is explained in words within this fiddle, if you just wanna skip to that: http://jsfiddle.net/6VZeD/
Basically, I want a floated, fixed-size testimonial box to contain two elements, a.part and .full, both of which are vertically centered, even with multiple lines. When .full overflows, causing a scrollbar, I want to scroll .full while a.part remains vertically centered. I can't absolutely position a.part because it needs to center vertically at any size. So I wrapped a.part in an absolutely positioned element, but that scrolls along with .full. No bueno.
I left some elements out of the fiddle for simplicity, but in case it matters, I'm using jQuery isotope to position the fixed-size boxes, and I'm expanding the boxes (width, height, top-margin, and left-margin change) on hover. So I'm happy to add divs within .testimonial, but I can't wrap anything around .testimonial (though I can add classes to it). I started exploring jQuery solutions involving .hide() and .offset() but things started to get messy, especially because I'm using CSS transitions heavily. So I'm hoping to avoid Javascript if possible.
Here's the fiddle HTML:
<div class="box praise testimonial">
<div class="abs1">
<a class="part" href="#">stay vertically centered!<br/>even if you scroll!</a>
</div>
<div class="abs2">
<div class="full">
<p>This text is larger than its containing box, and I want a scrollbar to appear. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vitae nisl at justo sodales congue. Praesent sed arcu sit amet dolor molestie venenatis. Curabitur et consequat libero. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed posuere lectus nec est viverra faucibus scelerisque massa fermentum. Donec ultricies bibendum tincidunt. Sed sit amet mi massa, a egestas arcu. Maecenas vitae libero metus. Proin dolor lorem, molestie ut ullamcorper sit amet, varius sit amet urna. Nunc aliquet scelerisque dui, et tristique quam molestie vitae. Etiam ac justo sapien. Etiam ipsum ante, porttitor posuere placerat id, congue quis neque. Nunc et elementum odio. Sed vulputate semper erat, a lobortis dolor porttitor ut.</p>
</div>
</div>
</div>
<div class="box praise testimonial">
<div class="abs1">
<a class="part" href="#">stay vertically centered!<br/>even if you scroll!</a>
</div>
<div class="abs2">
<div class="full">
<p>this<br/>should<br/>stay<br/>centered<br/>too!</p>
</div>
</div>
</div>​
And the CSS:
body {
    color: #fff;
}
a { color: #fff; font-size: 18px; font-weight: bold; text-decoration: none; }
.box {
    display: inline-block;
    position: relative;
    float: left;
    overflow: hidden;
    margin: 20px;
    background: #777;
}
.testimonial, .testimonial .abs1, .testimonial .abs2, .testimonial a.part, .testimonial .full {
    height: 250px;
    width: 250px;
}
.testimonial:hover {
    overflow: auto !important;
}
.testimonial a.part {
    display: table-cell;
    vertical-align: middle;
    text-align: right;
}
.testimonial .abs1 {
    position: absolute;
    top: 0;
    left: 0;
}
.testimonial .abs2 {
    position: absolute;
    top: 0;
    left: 0;
}
.testimonial .full {
    display: table-cell;
    vertical-align: middle;
    opacity: 0.5
}
Any help would earn my undying appreciation.
Try out the solution in this fiddle which also centers mulitple lines of text over images.

Max width doesn't work in a flexible box model in firefox?

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...

Resources