简体   繁体   English

如何在PHP代码中更改文本样式和颜色

[英]How to Change Text Style and Color Inside PHP code

I have IPSuite 4.1.11 which have "Similar Content" Block at the Sidebar. 我有IPSuite 4.1.11,其侧边栏具有“相似内容”块。 Im using Chameleon Theme, which can be found here 我正在使用变色龙主题,可以在这里找到

I wanted to style it with css but i got stuck- I cant change the style of the author name. 我想使用CSS设置样式,但遇到问题-我无法更改作者姓名的样式。 And i mean- the author name. 我的意思是-作者姓名。 I successeded to style name and other text- but i want to color only the author name. 我成功设置了名称和其他文本的样式,但是我只希望为作者名称加上颜色。

Here is the picture of the block: 这是该块的图片:

在此处输入图片说明

Here is what i want to change: 这是我要更改的内容:

在此处输入图片说明

Now here is the Relevant code of that author name: 现在,这里是该作者姓名的相关代码:

                    {{endif}}
                    <a href="{$topic->url()->setQueryString( 'do', 'getNewComment' )}" title='{lang="view_this_topic" sprintf="$topic->title"}' class='ipsDataItem_title ipsType_break'>{wordbreak="$topic->title"}</a>
                    <br>
                    <p class='ipsType_reset ipsType_medium ipsType_blendLinks'>
                        <span>{lang="byline_nodate" htmlsprintf="$topic->author()->link()"}</span>
                        <span class='ipsType_light'>{lang="topic_started_date" htmlsprintf="\IPS\DateTime::ts( $topic->mapped('date') )->html()"}</span>
                    </p>
                </div>
            </li>
        {{endforeach}}

Here is the Full "TopicFeed block" code: 这是完整的 “ TopicFeed块”代码:

{{if !empty( $topics ) }}
    <h3 class='ipsWidget_title ipsType_reset'>{$title}</h3>

    {{if $orientation == 'vertical'}}
        <div class='ipsPad_half ipsWidget_inner'>
            <ul class='ipsDataList ipsDataList_reducedSpacing'>
                {{foreach $topics as $topic}}
                    <li class='ipsDataItem{{if $topic->unread()}} ipsDataItem_unread{{endif}}{{if $topic->hidden()}} ipsModerated{{endif}}'>
                        <div class='ipsDataItem_icon ipsPos_top'>
                            {template="userPhoto" group="global" app="core" params="$topic->author(), 'tiny'"}
                        </div>
                        <div class='ipsDataItem_main'>
                            <div class="ipsCommentCount ipsPos_right {{if ( $topic->posts - 1 ) === 0}}ipsFaded{{endif}}" data-ipsTooltip title='{lang="replies_number" pluralize="$topic->posts - 1"}'>{expression="$topic->posts - 1"}</div>
                            {{if $topic->mapped('featured') || $topic->hidden() === -1 || $topic->hidden() === 1}}
                                <span>
                                    {{if $topic->hidden() === -1}}
                                        <span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_warning" data-ipsTooltip title='{$topic->hiddenBlurb()}'><i class='fa fa-eye-slash'></i></span>
                                    {{elseif $topic->hidden() === 1}}
                                        <span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_warning" data-ipsTooltip title='{lang="pending_approval"}'><i class='fa fa-warning'></i></span>
                                    {{endif}}
                                    {{if $topic->mapped('featured')}}
                                        <span class="ipsBadge ipsBadge_icon ipsBadge_small ipsBadge_positive" data-ipsTooltip title='{lang="featured"}'><i class='fa fa-star'></i></span>
                                    {{endif}}
                                </span>
                            {{endif}}
                            <a href="{$topic->url()->setQueryString( 'do', 'getNewComment' )}" title='{lang="view_this_topic" sprintf="$topic->title"}' class='ipsDataItem_title ipsType_break'>{wordbreak="$topic->title"}</a>
                            <br>
                            <p class='ipsType_reset ipsType_medium ipsType_blendLinks'>
                                <span>{lang="byline_nodate" htmlsprintf="$topic->author()->link()"}</span>
                                <span class='ipsType_light'>{lang="topic_started_date" htmlsprintf="\IPS\DateTime::ts( $topic->mapped('date') )->html()"}</span>
                            </p>
                        </div>
                    </li>
                {{endforeach}}
            </ul>
        </div>
    {{else}}
        <div class='ipsWidget_inner'>
            <ul class='ipsDataList'>
                {{foreach $topics as $topic}}
                    {template="row" group="global" app="forums" location="front" params="NULL, NULL, $topic, FALSE"}
                {{endforeach}}
            </ul>
        </div>
    {{endif}}
{{endif}}

I inserted css term into ipsuite that says: 我将css词插入ipsuite中,说:

.ipstlight_auther {font-weight: bold; color:red;}

and changed from: 并从以下更改:

<span>{lang="byline_nodate" htmlsprintf="$topic->author()->link()"}</span>

to: 至:

<span class='ipstlight_auther'>{lang="byline_nodate" htmlsprintf="$topic->author()->link()"}</span>

or to: 或者:

<span>{lang="byline_nodate" <span class='ipstlight_auther'>htmlsprintf="$topic->author()->link()"}</span></span>

But without success. 但是没有成功。

What do i miss? 我想念什么?

EDIT: 编辑:

When i try to use " spencerlarry " first css answer i got this: 当我尝试使用“ spencerlarry ”的第一个CSS答案时,我得到了:

在此处输入图片说明

and when i add the !important; 当我添加!important时; after each value i got that: 每个值后,我得到的是:

在此处输入图片说明

Why its acting like that? 为什么会这样呢?

Try adding the following to your css: 尝试将以下内容添加到CSS中:

p.ipsType_blendLinks span:nth-child(1) {
    font-weight: bold;
    color: red;
}

I think this is what you want: https://jsfiddle.net/aw8ycp0j/2/ 我认为这就是您想要的: https : //jsfiddle.net/aw8ycp0j/2/

I am using javascript to get the word "by" and changing it to black, that way only the authors name will be red. 我正在使用javascript来获取单词“ by”,并将其更改为黑色,这样,只有作者姓名才会是红色。 It is also getting the class names and iterating through to make the change, in case this is dynamically loaded content. 如果是动态加载的内容,它还会获取类名称并进行迭代以进行更改。

<body onload="highlight('by')">

<span class='ipstlight_auther'>by author</span>

<script>
    function highlight(text) {

    var x = document.getElementsByClassName("ipstlight_auther");
        var i;
        for (i = 0; i < x.length; i++) {
            var inputText = x[i];
        var innerHTML = inputText.innerHTML;
            var index = innerHTML.indexOf(text);

        if (index >= 0) {
        innerHTML = innerHTML.substring(0, index) + "<span class='black'>" + innerHTML.substring(index, index + text.length) + "</span>" + innerHTML.substring(index + text.length);
        inputText.innerHTML = innerHTML
      }
        }
}
</script>
</body>

CSS 的CSS

.ipstlight_auther {
  font-weight: bold;
  color: red;
}

.black {
  color: black;
}

Got IT! 得到它了!

I changed it via ACP -> languages. 我通过ACP->语言更改了它。

I searched in languages the term: "byline_nodate" 我用语言搜索了“ byline_nodate”一词

And changed it from : By %s 并将其更改By %s

to : By <span style="font-weight: bold; color:red;">%s</span> By <span style="font-weight: bold; color:red;">%s</span>

The result was: 结果是:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM