css - symfony 1图像风格的正确方法

标签 css image symfony1 styles

使用 symfony 框架调整图像标签样式的最合适方法是什么。 这是我的例子:

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

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

最佳答案

好吧,这里有很多选择。

您可以通过检查 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;
}

关于css - symfony 1图像风格的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16922079/

相关文章:

svn - 如何为具有多个 svn 的大型项目配置 Netbeans subversion :externals

当鼠标提前离开元素时,CSS 过渡步骤失败

html - 使用媒体查询和断点操作网格列布局

html - 在 div 问题中将边距设置为单个 header 标签

html - float 元素和 "non floated"元素之间的交互

jquery - 单击时显示特定图像

testing - 如何编写带有用户身份验证的功能测试?

php - 当数据库离线时 symfony 会发生什么?

javascript - 背景图像下方的白色区域

jquery - 使用 jquery 更改 Src 并获取新高度