将CSS选择器与:first-child结合使用(Combining CSS Selectors with :first-child)
假设某些HTML包含以下
div
块:<div id="messages"> <div> <span>from user</span> <span>The content of the message</span> <time datetime="2017-02-15T19:21:20.848Z">10 hours ago</time> </div> </div>
我如何使用CSS选择器设置“来自用户”文本(以及该文本)的样式? 我尝试使用
#messages>div:first-child
选择div#messages
的子div
的first-child
元素,但这不起作用。编辑:
我的语法有一个小错误。
正确的CSS选择器规则应该是
#messages>div>:first-child
而不是我之前尝试过的(#messages>div:first-child
)。 不同之处在于我在div
之后错过了。Suppose some HTML contains the following
div
block:<div id="messages"> <div> <span>from user</span> <span>The content of the message</span> <time datetime="2017-02-15T19:21:20.848Z">10 hours ago</time> </div> </div>
How could I style the "from user" text (and just that text) using CSS selectors? I tried to select the
first-child
element of the childdiv
of div#messages
using#messages>div:first-child
, but that didn't work.EDIT:
There was a small mistake in my syntax.
The proper CSS selector rule should be
#messages>div>:first-child
rather than what I tried earlier (#messages>div:first-child
). The difference is in the>
I missed afterdiv
.
原文:https://stackoverflow.com/questions/42777276
最满意答案
在您的示例中,只有
$this->config
是一个对象。 属性是数组,因此您将使用:$this->config->reCaptcha['reCaptchaSecretKey']
该对象如下所示:
stdClass Object ( [host] => Array ( [URL] => https://thomas-smyth.co.uk ) [dbconfig] => Array ( [DBHost] => localhost [DBPort] => 3306 [DBUser] => thomassm_sqlogin [DBPassword] => SQLLoginPassword1234 [DBName] => thomassm_CadetPortal ) [reCaptcha] => Array ( [reCaptchaURL] => https://www.google.com/recaptcha/api/siteverify [reCaptchaSecretKey] => IWouldNotBeSecretIfIPostedItHere ) )
要拥有JSON编码然后解码的所有对象:
$this->config = json_decode(json_encode($this->config));
In your example only
$this->config
is an object. The properties are arrays, so you would use:$this->config->reCaptcha['reCaptchaSecretKey']
The object looks like this:
stdClass Object ( [host] => Array ( [URL] => https://thomas-smyth.co.uk ) [dbconfig] => Array ( [DBHost] => localhost [DBPort] => 3306 [DBUser] => thomassm_sqlogin [DBPassword] => SQLLoginPassword1234 [DBName] => thomassm_CadetPortal ) [reCaptcha] => Array ( [reCaptchaURL] => https://www.google.com/recaptcha/api/siteverify [reCaptchaSecretKey] => IWouldNotBeSecretIfIPostedItHere ) )
To have all objects you could JSON encode and then decode:
$this->config = json_decode(json_encode($this->config));
相关问答
更多-
我倾向于做类似的事情 if (isset($post)){ //action goes here } 所以只有在设置了帖子后才会执行操作。 I would tend to do something like if (isset($post)){ //action goes here } so the action is only performed if post has been set.
-
PHP错误发生在该行: printf('name": "%s",', $title2->title); 但你的问题出在你的while语句中: while ($title2 = mysqli_fetch_object($ptitles)); 你放置的方式; 意味着你只是在循环中没有任何代码循环。 尝试 while ($title2 = mysqli_fetch_object($ptitles)) printf('name": "%s",', $title2->title); // only code ...
-
看起来$test是一个关联数组 像这样访问它: echo $test['testcol']; It looks like $test is an associative array Access it like this: echo $test['testcol'];
-
您可能想要在$this->db->get_where('posts', array('id' => $id), 1)->row();添加值检查$this->db->get_where('posts', array('id' => $id), 1)->row(); 线。 看起来这行可能返回false或者没有行可用的东西,虽然我在文档中找不到确切的返回值。 $result = this->db->get_where('posts', array('id' => $id), 1)->row(); if (!$re ...
-
更好的是你可以检查isset public function isAllowed($perm) { $cando = 0; $groups = DB::table('group_user')->where('user_id', $this->id)->get(); if(isset($groups)&&count($groups)>0){ foreach ($groups as $mygroup) { if( ...
-
如果没有更多信息,很难确定它的来源。 可能性来自这条线: $name = $gxpath->query('b')->item(0)->nodeValue; 可能是query,item或nodeValue不存在。 尝试打印$ gxpath的内容,然后打印$ gxpath-> query('b')等,这样你就可以弄清楚发生了什么。 作为一个旁注,除了创建一个数组之外,你打印$ glist而不实际做任何事情。 Without any more information, it can be hard to pin ...
-
试图获得非对象的属性(Trying to get property of non-object)[2022-02-26]
$j->location仍然无效。 您可以通过以下两种方法获取位置 您的位置是$j->57237036d89c45e1e3fda94e->location $arr = '{"57237036d89c45e1e3fda94e":{"_id":{"$id":"57237036d89c45e1e3fda94e"},"location":[33.7715,72.7511]}}'; $j= json_decode($arr); $x = '57237036d89c45e1e3fda94e'; var_dump( ... -
在您的示例中,只有$this->config是一个对象。 属性是数组,因此您将使用: $this->config->reCaptcha['reCaptchaSecretKey'] 该对象如下所示: stdClass Object ( [host] => Array ( [URL] => https://thomas-smyth.co.uk ) [dbconfig] => Array ( [DB ...
-
Laravel无法理解为什么要尝试获取非对象的属性?(Laravel can't understand why Trying to get property of non-object is occurring?)[2022-06-28]
您不应该定义中间件。 使用构造函数。 但是,在控制器的构造函数中指定中间件更方便。 (文档) 您必须按如下方式执行此操作 public function __construct() { // this will only apply middleware to one action $this->middleware('auth')->only('indexPaid'); } UPD。 由于您定义的中间件不适用于正确的位置,因此出现错误。 访问操作时必须已定义它。 所以使用routes文件 ... -
$ products是一行,类型为std对象。 您试图像数组一样访问它。 删除foreach,因为它不是数组。 因此,在视图中,您可以访问: $products->image 代替 $product->image 如果你需要数组格式,你可以使用 return $hasil->result_array(); 代替 return $hasil->row(); 在模型功能中 $products is a single row which is of type std object. You tried t ...