我想知道是否有可能在特定的div中将背景图像放在html的所有img之上(就像一种掩码)。
我试过:
#content img{
position:relative;
background-image:url('./images/image-mask-2.png');
z-index:100;
}发布于 2013-09-18 11:12:58
首先,我创建了一个315 To *270 To的自定义映像大小。
add_action( 'after_setup_theme', 'image-size-setup' );
add_image_size( 'image-with-mask', 315, 270, true );
function image-size-setup() {
function custom_in_post_images( $args ) { $custom_images = array('image-with-mask' => 'Image with mask'); return array_merge( $args, $custom_images ); } add_filter( 'image_size_names_choose', 'custom_in_post_images' );
}最后,我使用add_filter函数(在wordpress中)将宽度为315 to、高度为270 to的标记替换为2个div(一个用于掩码,另一个用于图片)。
function some_filter_content($content) {
$result = array();
return preg_replace('/<img.class="(.*?)".src="(.*?)".width="315".height="270".\/>/i', '<div style="background: url($2); width:315px; height:270px; float:left;"><div class="mask"></div></div>', $content);
}
add_filter('the_content', 'some_filter_content');https://stackoverflow.com/questions/18700136
复制相似问题