# Link\_to\_image - Remove Border

**URL:** <https://www.ruby-forum.com/t/link-to-image-remove-border/52276>\
**Category:** Rails\
**Created:** [January 12, 2006, 1:35pm UTC](https://www.ruby-forum.com/t/link-to-image-remove-border/52276 "2006-01-12T13:35:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [January 12, 2006, 1:35pm UTC](https://www.ruby-forum.com/t/link-to-image-remove-border/52276/1 "2006-01-12T13:35:50Z")

</div>

Hi All,

I am new to both Ruby and Rails, so please be patient with me. I am  
currently working on a view for a controller and I have used the  
following excerpt:

\<%= link\_to\_image "b\_edit", :action =\> 'edit', :id =\> part\_prefix %\>

The image is being displayed and the link is working. However, the  
formatting of image rendered produces and thick (1 or 2px) black box  
around the image. Is there a method of controlling this border aroung  
the image, I would prefer that it be transparent?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [January 12, 2006, 1:44pm UTC](https://www.ruby-forum.com/t/link-to-image-remove-border/52276/2 "2006-01-12T13:44:49Z")

</div>

On 1/12/06, Richard B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The image is being displayed and the link is working. However, the  
> formatting of image rendered produces and thick (1 or 2px) black box  
> around the image. Is there a method of controlling this border aroung  
> the image, I would prefer that it be transparent?

you can specify it in the img tag itself, or modify it with CSS (border:  
0px)

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [January 12, 2006, 1:44pm UTC](https://www.ruby-forum.com/t/link-to-image-remove-border/52276/3 "2006-01-12T13:44:50Z")

</div>

That’s not a Ruby on Rails issue, but a CSS styling problem.

Use:

img {  
border: 0;  
}

in your CSS stylesheet.

Am 12.01.2006 um 13:35 schrieb Richard B.:

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [January 12, 2006, 1:48pm UTC](https://www.ruby-forum.com/t/link-to-image-remove-border/52276/4 "2006-01-12T13:48:07Z")

</div>

Hi, Richard,

further than the other comments that you might (and probably should out  
of elegancy reasons) control this behaviour with CSS. You should have a  
look at:

[http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000334](http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000334)

There you’ll find an example of specifying :border =\> 0 and will realise  
that link\_to\_image which is an alias to link\_image\_to is deprecated.  
Please use the notation that is exampled on the link page.

Best regards  
Jan P.

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [January 12, 2006, 1:51pm UTC](https://www.ruby-forum.com/t/link-to-image-remove-border/52276/5 "2006-01-12T13:51:40Z")

</div>

On 12.1.2006, at 14.35, Richard B. wrote:

> formatting of image rendered produces and thick (1 or 2px) black box  
> around the image. Is there a method of controlling this border aroung  
> the image, I would prefer that it be transparent?

Richard,

First of all, link\_to\_image is deprecated. According to the api docs:

“This tag is deprecated. Combine the link\_to and  
AssetTagHelper::image\_tag yourself instead, like:  
link\_to(image\_tag(“rss”, :size =\> “30x45”, :border =\> 0), “http://  
[www.example.com](http://www.example.com)”)”

That said, you can get rid of the border by just using css:

a img {  
border: 0;  
}

If you only want this to apply to certain linked images, give them a  
class like this:  
link\_to(image\_tag(“rss”, :size =\> “30x45”, :border =\> 0, :class =\>  
“yourclass”), “[http://www.example.com](http://www.example.com)”)

…and then

img.yourclass {  
border: 0;  
}

hth,  
//jarkko

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [January 12, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/link-to-image-remove-border/52276/6 "2006-01-12T15:20:40Z")

</div>

Jarkko L. wrote:

> On 12.1.2006, at 14.35, Richard B. wrote:
> 
> > formatting of image rendered produces and thick (1 or 2px) black box  
> > around the image. Is there a method of controlling this border aroung  
> > the image, I would prefer that it be transparent?
> 
> Richard,
> 
> First of all, link\_to\_image is deprecated. According to the api docs:
> 
> “This tag is deprecated. Combine the link\_to and  
> AssetTagHelper::image\_tag yourself instead, like:  
> link\_to(image\_tag(“rss”, :size =\> “30x45”, :border =\> 0), “http://  
> [www.example.com](http://www.example.com)”)”
> 
> That said, you can get rid of the border by just using css:
> 
> a img {  
> border: 0;  
> }
> 
> If you only want this to apply to certain linked images, give them a  
> class like this:  
> link\_to(image\_tag(“rss”, :size =\> “30x45”, :border =\> 0, :class =\>  
> “yourclass”), “[http://www.example.com](http://www.example.com)”)
> 
> …and then
> 
> img.yourclass {  
> border: 0;  
> }
> 
> hth,  
> //jarkko

Thanks for the quick responce:

I did see that the form that I was using was deprecated. However in the  
example provided they are linking to a page, will this still work with  
an action and controller? If so do you replace the hard link with the  
action and controller id strings?

I still need to review the link that Jan suggested!

Regards

Richard

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [January 12, 2006, 3:47pm UTC](https://www.ruby-forum.com/t/link-to-image-remove-border/52276/7 "2006-01-12T15:47:17Z")

</div>

Hi, Richard,

yes you are combining link\_to and image\_tag. Therefore you’ll get the  
possibilities of link\_to which include linking to actions:  
[http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000332](http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000332)

Regards  
Jan
