简体   繁体   中英

Change CSS on one element when class is added on another element

I want to add a specific CSS attribute to my submit-button on my comments form when the user is logged in on Wordpress!

When my class .comment-form gets the p class="logged-in-as" instead of the "standard" p class="comment-notes" , I want my p.form-submit to get CSS { width: 50%; }

To be honest I'm not really sure if anyone more than me, the Admin, sees the "Logged in as xxx: Log out?" when they are at my site, which removes the commenters information thus messing up my design... but hey, better to be safe than sorry!

As requested I copied the code from the blog, I'm not sure how this helps but when the first p class , as stated earlier, changes due to the commenter being logged in I want to add a CSS value to another div.

<p class="logged-in-as">
  <a href="www.example.com/wp-admin/profile.php" aria-label="Logged in as Morgan. Edit your profile.">Logged in as Morgan</a>. <a href="www.example.com/wp-login.php?action=logout&amp;redirect_to=http%3A%2F%2FEXAMPLE.com%2Ftwo-days-in-budapest%2F&amp;_wpnonce=3fb7c78c29">Log out?</a>
</p>
<p class="comment-form-comment">
<label for="comment">Comment</label>

When you are logged in, WordPress automatically adds the "logged-in" class to the body tag. So you can use:

body.logged-in p.form-submit {width: 50%;}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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