I'm trying to create a BEM spacing helper mixin that contains the name of the screen in the class name. An example output: .marSm0 .marSm0__t .marSm0__b .marSm0__x
$emMd0: 1em !default;
$emMd1: 1.5em !default;
$emMd2: 2em !default;
$emMd3: 4em !default;
$emMdSpacing: ($emNone, $emMd0, $emMd1, $emMd2, $emMd2 );
#mixin spacingHelper($screenSize, $spacingValues){
#each $space in $spaceValues {
.mar#{screenSize}#{$space} {
margin: #{$space}rem;
}
.mar#{screenSize}#{$space}__x {
margin-left: #{$space}rem;
margin-right: #{$space}rem;
}
.mar#{screenSize}#{$space}__y {
margin-top: #{$space}rem;
margin-bottom: #{$space}rem;
}
.mar#{screenSize}#{$space}__l {
margin-left: #{$space}rem;
}
.mar#{screenSize}#{$space}__r {
margin-right: #{$space}rem;
}
.mar#{screenSize}#{$space}__b {
margin-bottom: #{$space}rem;
}
.mar-#{screenSize}#{$space}__t {
margin-top: #{$space}rem;
}
.pad#{screenSize}#{$space} {
padding: #{$space}rem;
}
.pad#{screenSize}#{$space}__x {
padding-left: #{$space}rem;
padding-right: #{$space}rem;
}
.pad#{screenSize}#{$space}__y {
padding-top: #{$space}rem;
padding-bottom: #{$space}rem;
}
.pad#{screenSize}#{$space}__l {
padding-left: #{$space}rem;
}
.pad#{screenSize}#{$space}__r {
padding-right: #{$space}rem;
}
.pad#{screenSize}#{$space}__b {
padding-bottom: #{$space}rem;
}
.pad#{screenSize}#{$space}__t {
padding-top: #{$space}rem;
}
}
}
The problem I'm having is that the $screenSize mixin argument isn't working in the each loop. How do I fix this? I'm sure if the each loop is having a scope issue. Code
Ignore for question validation
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin quis vehicula tellus, id ultrices massa. Suspendisse dignissim in odio non rutrum. Vestibulum dapibus eget eros at aliquet. Quisque vitae vulputate massa, ac laoreet orci. Vestibulum vestibulum ante quis eros sollicitudin euismod. Cras eget orci turpis.
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 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)
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.