2013-06-04 51 views
0

什麼是最適當的方式來適應風格的圖像標籤使用symfony框架。 這是我的例子:symfony 1圖像風格正確的方式

<?php echo link_to(image_tag('/design/fb.png'), 'https://www.facebook.com') ?> 

如何風格fb.png圖像,例如我想用margin-top: 5px;

回答

1

嗯,這裏有很多選擇。

您可以通過檢查裏面的symfony的AssetHelper.php看到他們:

/** 
* Returns an <img> image tag for the asset given as argument. 
* 
* <b>Options:</b> 
* - 'absolute' - to output absolute file paths, useful for embedded images in emails 
* - 'alt' - defaults to the file name part of the asset (capitalized and without the extension) 
* - 'size' - Supplied as "XxY", so "30x45" becomes width="30" and height="45" 
* 
* <b>Examples:</b> 
* <code> 
* echo image_tag('foobar'); 
* => <img src="images/foobar.png" alt="Foobar" /> 
* echo image_tag('/my_images/image.gif', array('alt' => 'Alternative text', 'size' => '100x200')); 
* => <img src="/my_images/image.gif" alt="Alternative text" width="100" height="200" /> 
* </code> 
* 
* @param string $source image asset name 
* @param array $options additional HTML compliant <img> tag parameters 
* 
* @return string XHTML compliant <img> tag 
* @see image_path 
*/ 
function image_tag($source, $options = array()) 

所以,你可以直接整合style屬性:

<?php echo link_to(
    image_tag(
     '/design/fb.png', 
     array('style' => 'margin-top: 5px;') 
    ), 
    'https://www.facebook.com' 
) ?> 

或定義class作爲屬性,並創建在class一個css文件

<?php echo link_to(
    image_tag(
     '/design/fb.png', 
     array('class' => 'img-fb') 
    ), 
    'https://www.facebook.com' 
) ?> 

而你的css:

.img-fb { 
    margin-top: 5px; 
}