CSS 如何将类添加到 CodeIgniter 锚点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/754256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:31:13  来源:igfitidea点击:

How Do I Add a Class to a CodeIgniter Anchor

csscodeigniter

提问by Tisch

I have the following:

我有以下几点:

'.anchor('','Home').'

and I want to add the following CSS class to it:

我想向其中添加以下 CSS 类:

class="top_parent"

This is so that when it's rendered in the browser, the code will look something like the following:

这样当它在浏览器中呈现时,代码将如下所示:

<a href="#" class="top_parent">Home</a>

Thanks in advance, and any help is greatly appreciated.

提前致谢,非常感谢任何帮助。

--

——

Tom

汤姆

回答by Mahtar

anchor('#', 'Home', array('class' => 'top_parent'));

回答by IEnumerator

The Codeignitor function is defined as such:

Codeignitor 函数定义如下:

function anchor($uri = '', $title = '', $attributes = '')

I would try sending an array with a class key and value first.

我会尝试先发送一个带有类键和值的数组。

These functions are found inside the \system\helpers\ folder.

这些函数位于 \system\helpers\ 文件夹中。

回答by Whitey

You can specify an associative array of attributes for your Anchor. So, for example:

你可以为你的锚指定一个关联的属性数组。因此,例如:

anchor('', 'Home', array('class' => 'top_parent'));

anchor('', 'Home', array('class' => 'top_parent'));

回答by Asif Jafri Mohammad Fahim

Try this:

尝试这个:

$myClass = array('class' => 'top_parent');

echo anchor('#', 'Home', $myClass);

Hope it will be clear to you.

希望你能清楚。

回答by Zamir

From Codeigniter's manual:

anchor()has three optional parameters:

来自 Codeigniter 的手册

anchor()有三个可选参数:

anchor(uri segments, text, attributes)

Simple example:

简单的例子:

anchor(url,text,array('class'=>'class1'));

回答by Joe

It can also be used like this:

它也可以像这样使用:

<?php echo anchor('#', 'Home', 'class="top_parent"' ); ?>

And if you want extra attributes like title for example, it can be done like this:

如果你想要额外的属性,比如标题,可以这样做:

<?php echo anchor('#', 'Home', 'class="top_parent" title="Home"' ); ?>

回答by kaysums

For example if you have a css classcalled btn, and a button called submit, to submit (call a submit controller class called sub) You can do it this way

例如,如果您有一个名为css 的btn和一个名为 submit 的按钮来提交(调用一个名为 sub 的提交控制器类)您可以这样做

<?php echo anchor('sub', 'submit', 'class="btn" ');? >