我编写了一个创建 3 个 div 的代码,其中包含图像和超链接。但是,每个 div 应该有一个 200px 的 padding-right,这不能在 CSS 中完成,因为我试过了,但奇怪的是它不起作用。所以这 3 个 div 相互堆叠,而它们之间应该有 200px 的空间。请帮忙
代码:
<?php
define('RANDOM_IMAGES_COUNT2',3);
define('RANDOM_IMAGES_FORMAT2', '<div id="rand%s" style="width:170px;height:1px; float:left;text-align:center;top"><img src="%s" style="border-style:solid;border-width:2px;border-color:black;"/><a href="%s" alt="%s" title2="%s">%s</a></div>');
#------------------------------------------------------------------------------
$images = array (
array ( 'title2' => 'Test 2', 'src2' => 'pic2.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic7.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic9.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic5.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic3.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello3' )
);
#------------------------------------------------------------------------------
if ( count($images) < RANDOM_IMAGES_COUNT2 ) {
trigger_error('Not enough images given', E_USER_WARNING);
exit;
}
#------------------------------------------------------------------------------
for ($i = 0; $i < RANDOM_IMAGES_COUNT2; $i++) {
shuffle($images);
$tmp = array_shift($images);
printf( RANDOM_IMAGES_FORMAT2,$i, $tmp['src2'], $tmp['href2'], $tmp['title2'], $tmp['title2'],$tmp['text2'] ); }
?>