php - 多彩多姿的div

标签 php css

我的网站是一个搜索引擎,它使用 foreach 循环返回许多结果,如下所示:

foreach ($xml->channel->item as $result) {
    $ltitle = $result->title;
    $ldesc = $result->description;
    $url = $result->displayUrl;
    $link = $result->link;

    if (strlen($ltitle) > 60)
    {
$title = substr($ltitle,0,60).'...' ;
    }
    else
    {
    $title = $ltitle;
    }

if (strlen($ldesc) > 195)
    {
$desc = substr($ldesc,0,195).'...' ;
    }
    else
    {
    $desc = $ldesc;
    }


    echo "

<br>


<div class='resultbox'>

<a class='normal' style='text-decoration:none;font-size:huge;font-weight:bold' href='$link'>$title</a><br>
<div style='padding-top:3px;padding-bottom:4px;width:580px;'>
<font style='text-decoration:none;font-size:small;font-family:Arial;'>$desc<br></font></div>
<a style='text-decoration:none;' href='$link'><font style='text-decoration:none;font-size:small;color:green;font-weight:bold;'>$url<br></font></a>

</div>
";
}

上面的 resultbox 类使用此样式设置所有结果

.resultbox
{
height:auto;
width:600px;
background-color:transparent;
font-size:19px;
padding:10px;
padding-left: 30px;
padding-right: 30px;
border-left: 6px solid #333;
}
.resultbox:hover
{
border-left: 8px solid #555;
}

左边框颜色是我想要改变的,我希望它从颜色代码列表中随机生成或样式化,这样结果就可以是#333 #555 #999,而不是全部#333等等......有什么想法吗?

最佳答案

如果你使用 JS 没有问题,你当然可以这样做:

$(document).ready(function () {

    $('.resultbox').mouseenter(function() {
        var randomColor = Math.floor(Math.random()*16777215).toString(16);
     $('.resultbox').css("border-left", " 8px solid #"+randomColor);    
    });
});

关于php - 多彩多姿的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16396601/

相关文章:

html - 如何缩放一行图像以适合容器宽度?

javascript - 如何仅更改表格中一行的颜色 (HTML/JavaScript)

php - Laravel 表单不会更新数据库中的值,而是删除它们

PHP/MySQL 查询不起作用

php - Where 条件不适用于 IN 子句

php - 你好,我如何向我的页面显示来自 2 个不同表的数据

html - 鼠标悬停在菜单按钮外显示菜单

html - 为什么我的 div 不是 float 的 :right working?

css - ASP :button styling issue - only taking part of the css

php - PHP 中带有 PDO 语句的 print_r 应该返回什么?