Follow Along as I Stumble on the Path to Learning RoR

Posts tagged “image

CSS Only Image Overlay

While this isn’t a Rails solution, it was one that was so helpful to me that I wanted to post about it.  I needed a tinted/filtered image overlay with text.  After Binging the internet, I found the solution courtesy of Koren Leslie Cohen.

You can read her post here to see a demo, but you wrap your image, like this:

  <div id=“outer-box”>
    <img src=“cartagena.jpg”>
    <div id=“inner-box”>
      <p>This is the overlay!</p>
    </div>
  </div>
and then add this CSS,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#outer-box {
  width: 300px;
  height: 194px;
  display: block;
  position: relative;
}
#outer-box img {
  width: 300px;
  height: auto;
}
#outer-box #inner-box {
  background: #FD8698;
  height: 100%;
  width: 100%;
  opacity: 0;
  top: 0;
  left: 0;
  position: absolute;
  padding: 0;
  transition: opacity .5s;
}
#outer-box #inner-box p {
  color: #fff;
  lineheight: 150px;
  fontfamily: ‘arial’;
  textalign: center;
}
#outer-box:hover #inner-box {
  opacity: .9;
  transition: opacity .5s;
}

This will show the overlay when the image is hovered over.  For me, I wanted to show the overlay without the hover, so I changed line 33 to be:

#outer-box #inner-box {

Advertisements

Facebook not Showing Open Graph Images

My image tags were right for Open Graph, but my images weren’t showing when when people tried to share on Facebook.

I found my answer on Stack Overflow here.

Apparently, if Facebook doesn’t already know of a page, it will not know about the image until after it is shared once (at which time it becomes aware of the page).

However, there’s a work around.  You have to specify additional attributes about the image – the height and the width (where the content value is the number of pixels for width and height, respectively):

<meta property=”og:image:width” content=”450″/>
<meta property=”og:image:height” content=”298″/>

 


Referencing an Image from CSS File in Asset Pipeline

In order to reference an image from the CSS file, I added .scss at the end of the .css file and referenced the image using this syntax:

background: url(asset-path(“example.png”,image)) no-repeat; 


Rounded Image Corners

I wondered how Twitter made all of the uploaded images have rounded corners. I found a wonderful jQuery script, jQuery corners which does just this:

http://jquery.malsup.com/corner/

apply an id to your picture, like so

:id=>”rounded_corners”

then add this script:

$(‘#rounded_corners’).corner();