symfony フレームワークを使用してイメージタグのスタイルを適応させる最も適切な方法は何ですか? これが私の例です:
<?php echo link_to(image_tag('/design/fb.png'), 'https://www.facebook.com') ?>
fb.png画像のスタイルを設定する方法、たとえば、使用したいmargin-top: 5px;
.
さて、ここには多くのオプションがあります。
AssetHelper.php
symfony の内部をチェックすることでそれらを見ることができます:
/**
* 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
またはas 属性を定義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;
}