symfony 1图像样式正确的方式

时间:2013-06-04 15:44:08

标签: css image symfony1 styles

使用symfony框架在image-tag上调整样式的最恰当方法是什么。 这是我的例子:

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

如何设置fb.png图像的样式,例如我想使用margin-top: 5px;

1 个答案:

答案 0 :(得分: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定义为属性并在css文件中创建class

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

你css:

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