How can I change :hover to a clickable element instead?

I attempted to create a full-width accordion with the following code:

.page {
     margin: 0;
    padding: 0;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    height: 100vh;
}

.content {
    -webkit-box-flex: 0.4;
    -webkit-flex: 0.4;
    -ms-flex: 0.4;
    flex: 0.4;
    -webkit-transition: -webkit-box-flex 500ms ease-out;
    -webkit-transition: -webkit-flex 500ms ease-out;
    transition: -webkit-box-flex 500ms ease-out;
    transition: -ms-flex 500ms ease-out;
    transition: flex 500ms ease-out;
    padding: 20px;
}

.content:hover {
  -webkit-box-flex: 50;
    -webkit-flex: 50;
    -ms-flex: 50;
    flex: 50;
}
<div class="page">
  <div class="content one">Content</div>
  <div class="content two">New</div>
  <div class="content three">Div</div>
  <div class="content four">Tag</div>
  <div class="content five">Here</div>
</div>

However, I struggled to convert the hover effect into a click event using jQuery. Additionally, my attempts to utilize radio inputs to control the size of the "Content" div at the start were unsuccessful.

Answer №1

It appears that you are looking to activate certain CSS rules when content is clicked, although I may have misunderstood your question.

One solution could be to include an event listener like this:

 $(".content").click(function(){
    $(".content").toggleClass("when-clicked");
 });

You can then define the styling for the "when-clicked" class like so:

.content.when-clicked{
    -webkit-box-flex: 50;
    -webkit-flex: 50;
    -ms-flex: 50;
    flex: 50;
 }

Give that a try and see if it accomplishes what you need.

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

Failure to link style sheet to document

Experiencing some difficulties with a seemingly simple task that I can't figure out. When I check my code in the browser, none of my styles are being applied to the HTML elements. The style sheet is located in the same folder as the main document, and ...

Is there a method available to streamline the process of generating .json files for language translations?

Working with translation files can be a tedious task, especially when adding new keys for different languages. Making sure that each key is included in all the JSON files can lead to errors and repetitive editing. Is there a more efficient way to handle t ...

Utilize Jquery to create smooth animated scrolling within a specific div instead of the entire page

I am currently using an older script that utilizes jquery anchor links to animate the page to the anchor. While it is effective, I am looking to modify it to only animate the content of a specific div instead of the entire page. Are there any suggestions ...

Enhancing search results with data retrieved from a jSON response

At the moment, I am using a logic to generate a list of titles. Now, I would like to include data from the response along with the code for each title in the list. const title = responseData.map(item => { return { label: item.title, val ...

Exporting NativeModules for npm package in React Native

I'm attempting to convert my React Native App into a node module. The issue I'm facing is that the module consists mainly of a NativeModule. Thus, my index.js file appears like this: import { NativeModules } from 'react-native'; expo ...

How can you measure the length in jQuery?

Here is the code snippet in question: if ($('.course-chkbox:checked').length === 0) { alert('no course is selected'); } I'm having trouble getting this to work in certain browsers. Can someone confirm if this is the correct way t ...

Injecting PHP variables into CSS code right from a PHP file

$a = "ABCD"; ?> <link rel='stylesheet' type='text/css' href='others.php' /> <style> .page-title { text-indent: -9999px; line-height: 0; } .page-title:afte ...

I am facing difficulties with deploying my Next.js App on Vercel. Whenever I try to deploy, I encounter an error stating that the Command "npm run build" exited with 1

Hey there! I'm currently following a tutorial by JavaScript Mastery on Next.js (big shoutout to you, sir). I've been trying to deploy it on Vercel, but running into some deployment issues and having trouble testing out different tutorials. Here&a ...

Achieving the ideal positioning of content within the flex property

I am facing an issue with my containers, specifically .grid.left and .grid.right. The images within each of these grids are dynamic and enclosed within another div called .gallery. The problem arises when I apply margins to the image boxes, causing gaps w ...

Bar Chart Data Label Problem with HighCharts

My goal is to have the label positioned outside the bar stack. I attempted to achieve this using the code below, but it seems to be inconsistent in its results. dataLabels: { enabled: true, color: '#333', ...

The functionality of arguments in the whenAllDone promise/deferred javascript helper seems to fail when attempting to encapsulate existing code within a Deferred

My goal is to implement the solution provided in TypeScript from Stack Overflow: UPDATE 2 - The issue with the original answer is that it does not support a single deferred. I have made modifications to reproduce the error in his fiddle. http://jsfiddle.n ...

What exactly is the significance of localizing an Aria label?

Looking to add an aria label that needs to be localized. What exactly does this mean? Here is the code I have: <a href="link"><i class="button" aria-label="back button"> How do I modify this code in order to make ...

Tips on deleting CSS comments from a CSS file

Currently, I am utilizing nextjs + reactjs. My objective is to eliminate all CSS comments from my existing css file. Despite using next-purgecss in order to get rid of unnecessary CSS code, the comments are still persisting. What could be the reason behind ...

Is there a way to effortlessly generate a mini-website from Markdown files?

Can a tool be found that creates a mini-website from locally-stored Markdown files complete with automatically generated navigation? I'm hoping for a service that can sync with my Dropbox, analyze the file structure, read the Markdown files, and effo ...

Preventing bots and spiders from infiltrating the ad network. Stepping up efforts to block unwanted traffic

We are facing a constant battle against bots and spiders with our in-house ad system, striving for 100% valid impressions. To achieve this goal, I conduct experiments on a specific ad zone that is only displayed on one page of our site. By comparing the G ...

Executing Enter Key and Button Simultaneously with JavaScript: Step-by-Step Guide

I need assistance understanding how to simultaneously trigger the enter key and button in this code. When the value is entered into the input field, it should trigger both the enter key and the button "Enter" at the same time. Additionally, after pressing ...

React App folders are not being properly installed through NPX

Encountering an error message while attempting to use npx create-react-app Husna@LAPTOP-LPCC954R MINGW64 ~/Desktop/React GitHib Project (master) $ npx create-react-app github2020 Creating a new React app in C:\Users\Husna\Desktop\Reac ...

Implementing multiple condition-based filtering in React Native for arrays

I am looking to apply multiple filters to an array based on certain conditions defined by toggling switches. The issue arises when toggling two or more switches simultaneously, resulting in an empty array. My goal is to retrieve an array containing the tru ...

Steps for filling an HTML table within a dynamically loaded DIV

I have a container in my HTML page where I dynamically load other pages using the jQuery.load() function. One of the pages requires me to populate a table from the database just after/before it loads. How can I trigger a JavaScript function to execute righ ...

Locate the point at which the two strings no longer match in their indices

Consider having 2 strings: var a = "abcdef", b = "abcdefgh"; I am searching for the first index where the complete match is broken without needing to iterate over both strings and compare each character with a loop. In this instance, I need to identify ...