Conceal the pseudo element when clicked

Running a WordPress site, I have a button on the home page that is set to load more posts when clicked. I wanted to add a touch of design by including an upside-down caret next to the text "load more posts" using pseudo-elements. While I successfully achieved the desired look, I encountered an issue - the caret does not disappear along with the rest of the button when it's pressed. I attempted to address this problem by applying an ::active class, but the caret still persists. What steps should I take to ensure the caret disappears upon clicking the button?

Here is an example of the button:

https://i.sstatic.net/OI2y3.png

This is how the button looks after being clicked (I don't want the caret to be visible):

https://i.sstatic.net/Zfu5l.png

Below is the current CSS code:

.elm-button::before {
    content: "v"; 
    font-size:11px;
    float: right;
    margin: 6px 0 0 14px;
    font-family: 'Days One', sans-serif;
}
.elm-button::active {
    display: none;
    visibility: hidden; 
}

Answer №1

It seems like there is a mistake in your code snippet. The pseudo-class :active should only have one colon because it is a pseudo-class, not a pseudo-element.
What do you think about this updated version?

.elm-button {
  background:none; border:none; font:inherit;
 }
.elm-button::before {
    content: "v"; 
    font-size:11px;
    float: right;
    margin: 6px 0 0 14px;
    font-family: 'Days One', sans-serif;
}
.elm-button:active {
display: none;
    visibility: hidden; 
}
<button class="elm-button" type="button>">Load more posts</button>

(By the way, you might also want to consider adding .elm-button:focus, but that depends on the specific requirements.)

Answer №2

NEW UPDATE

Upon further investigation, I discovered that a similar solution was provided earlier. Despite this, it seems the initial suggestion did not work for the user (OP). Here is an alternative approach sourced from W3Schools, which offers greater flexibility in controlling each element separately using CSS variables and pseudo-elements.

var clickedToLoad = false;
$('.elm-button').on('mousedown',
    function(){
      document.documentElement.style.setProperty('--before-display', 'none');
    }
  )
$(document).on('mouseup',
    function() {
      document.documentElement.style.setProperty('--before-display', 'block');
    }
);
:root {
  --before-display: block;
}
.elm-button {
  display: var(--before-display);
}
.elm-button:before {
  content: "v";
  float: right;
  margin-left: 6px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<BUTTON class="elm-button">LOAD MORE POSTS</BUTTON>


REVISED ORIGINAL SOLUTION

Just to clarify, altering CSS pseudo-elements via JavaScript or JQuery is not feasible. Nonetheless, there are alternative solutions available. Please refer back to the previous query provided for more insights.

However, correcting your issue should be relatively simple by fixing a typo in your existing code (introduced double dots before the active keyword):

.elm-button::before {
  content: "v"; 
  font-size:11px;
  float: right;
  margin: 6px 0 0 14px;
  font-family: 'Days One', sans-serif;
}
.elm-button:active {
  display: none;
  visibility: hidden;
}

/* Added only to match your output*/

.elm-button {
  background: inherit;
  border: none;
}
<BUTTON class="elm-button">LOAD MORE POSTS</BUTTON>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Evaluate One Input Value to Determine Another Input Value

Hey there, I've made an update to the fiddle but let me clarify what I'm trying to achieve. My goal is not to implement form validation as I already have that covered with the HTML5 "required" attribute. What I'm aiming for is to customize t ...

Positives and negatives images for accordion menu

I have successfully created an accordion list using HTML, CSS, and JavaScript. However, I would like to enhance it by adding a plus and minus picture in the left corner of the heading. Is there a way to achieve this functionality? I have two images that I ...

Mozilla Firefox does not have the capability to support preloading

I am having an issue with preloading CSS sheets. I attempted to preload the CSS sheet using the preload attribute in HTML. It works fine on Google Chrome, but unfortunately, it does not work on Firefox. <head> <link href=assets/css/master.c ...

The callback function in WordPress is executed twice

I've been working on a custom WordPress plugin that includes a form for sending data to a database. However, I've encountered an issue where every time I click the submit button, the callback function runs twice, resulting in duplicate entries in ...

Design a dynamic table using JavaScript

After spending hours working on my first JavaScript code, following the instructions in my textbook, I still can't get the table to display on my webpage. The id="eventList" is already included in my HTML and I've shortened the arrays. Here' ...

Safari not updating Angular ng-style properly

I created a simple carousel using Angular and CSS animations which works well in Chrome. However, I recently tested it in Safari and noticed that the click and drag functionality does not work. I've been trying to fix this issue for days and could use ...

Preventing ReactJS tooltips from exceeding the boundaries of the screen

Here is a simple demo showcasing blocks with tooltips that appear when hovered over. However, there seems to be an issue with the functionality. The tooltip should ideally be displayed either from the left or right side of the block. To determine the size ...

The viewport scaling issue occurs when transitioning from landscape to portrait orientation

While developing a mobile version of my website, I have encountered an issue with the behavior when rotating my iPhone device. Everything looks fine in landscape orientation, but upon rotation back to portrait, the viewport remains stuck at the landscape s ...

The functionality of my website is not optimized for viewing on iPhones

While designing a responsive website that looks great on most devices, I noticed some issues with iPhones. The layout breaks in two specific ways on these devices. View Galaxy Screenshot View Sony Screenshot The menu doesn't scale properly on iPho ...

What is the best way to add color to a Table Header?

I'm working on a HTML/CSS table and I want the header row to have a specific background color. Below is my code: <table class="contentTable"> <tr class="contentTableHeader"> <th>No.< ...

Adsense ad unit is not responsive and fails to display properly at dimensions of 320x50 px

I have a unique banner ad that I want to display as the footer on my responsive website. Using media queries recommended in the advertising documentation, I am adjusting the size based on different screen widths. Check out the CSS code below: <style&g ...

Changing the styling frameworks for Components

Into my UI application developed using Angular, I have the option to select from various CSS frameworks such as: Bootstrap 4 Foundation Angular Material ng-bootstrap or ngx-bootstrap. A pre-built template available for purchase. And many o ...

Expanding beyond the dimensions of the webpage, HTML CSS Height set to 100% creates a unique

I'm struggling with the CSS on a page I'm working on. I have a header and main content each enclosed in div tags, with the header set to a height of 250px and the main content set to a height of 100%. I've also set the html and body heights ...

Using jQuery to update the input value when the mouse hovers over a div

Attempting to update an input value using jQuery mouseover. Situation: There are 5 divs with different colors and usernames. When hovering over a div, the input text (and background color for the color input) changes based on database values. Each time a ...

How can I use ontouchstart and ontouchend events in jQuery?

Currently, I am using the following code to change the class of elements on touch: ontouchstart="$(this).addClass('select');" ontouchend="$(this).removeClass('select');" I was wondering if there is a more efficient way to achieve this ...

The enigma of CSS: How is the width mysteriously set to 0px with no visible CSS styling

Take a look at this snapshot of a webpage I'm currently designing in Chrome Developer Tools: https://i.sstatic.net/SB00j.png The primary rule in the 'Matched CSS Rules' section indicates that the width of the element should be 160px. Howe ...

How to Align Navigation Bar Items to the Right in Bootstrap 4

I need some help with bootstrap. I've looked at various discussions on this topic and tried numerous solutions, but I still can't get it right. I want the logo to be on the left and the navigation links aligned to the right. Here's what I&ap ...

What's the best way to display two checkboxes on a single line?

I am working with checkbox filters in WooCommerce and I want to organize them so that two checkboxes appear in one row, followed by the next two in the second row, and so on. The issue can be seen at this URL. I also want this style to apply to "Product Co ...

How to use JQuery to retrieve multiple background image URLs from CSS styling

Initially, here is the CSS code that I am working with: background-image: url(/style_elements/img/first.png), url(/style_elements/img/second.png); I am trying to specifically target the second background image URL using jQuery: var item_img_url = item_i ...

Styling CSS variables uniquely

I have limited knowledge of HTML and CSS, so I am unsure how to search for a similar post on StackOverflow. My apologies if this is a duplicate question. I am looking to achieve the following: margin-horizontal { margin-left: value; margin-right: va ...