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

Error: The variable 'xxxxxx' is not recognized

Encountering an issue while trying to pass data via an onclick event and receiving the error message "Uncaught ReferenceError: 'xxxxxx' is not defined" var ShowDetails = function (insuredID) { $.ajax({ type: "GET", ...

Dynamic CSS sizing

Currently, I am in the process of creating a component and my goal is to achieve a specific layout without the use of JavaScript, preferably utilizing flexbox. Essentially, envision a messenger chat screen with a header and footer containing controls. htt ...

Locating a user by their ID within a collection in Meteor can lead to some unexpected behavior

I have a requirement where I only want to allow users to insert a document if their email is verified. In an attempt to achieve this, I wrote the following code snippet. Events.allow({ insert: function (userId, doc) { var user = Meteor.users.f ...

What is the best way to modify tabulator styles?

Is there a way to update the column header in Tabulator using inline style when trying to avoid ellipsis as the column size is reduced? <VueTabulator ref="tabulator" v-model="receipts" :options="options" style="white ...

Supervising the organization of HTML sections for an offline web application

Currently, I am developing an offline HTML5 application that involves a significant amount of DOM manipulation through the creation of HTML strings within JavaScript functions. For example: var html=''; html+='<div class="main">&apos ...

Responsive design is key in ensuring that Bootstrap columns adjust accordingly

I am attempting to create a responsive block in the center of my webpage with the help of Bootstrap. However, I am having trouble getting the columns to respond correctly to my bootstrap setup. Can anyone point out what I might be doing wrong? <lin ...

The functionality of .map() in Javascript is non-existent

I am completely new to this community (and JavaScript is also new for me), so I apologize in advance for asking some very basic questions. I have an HTML page with various images, all of which share a common class. After using getElementsByClassName, I obt ...

Error: The request was denied by the operating system. Issue encountered while attempting to build a new React application

I recently installed the LTS version 14.17.3 of Node (npm version 6.14.13). Following that, I successfully globally installed create-react-app using the command "npm install -g create-react-app" (version 4.0.3). However, when attempting to create a new R ...

Integrating CSS with Material-UI in a React project: A step-by-step guide

I am currently developing a project using React (along with TypeScript) and the Material-UI library. One of my requirements is to implement an animated submit button, while replacing the default one provided by the library. After some research, I came acr ...

What is the method to make a file download using JavaScript?

In my jQuery ajax form, a user inputs their email and upon submission, they should receive an automatic download of a file. Here is the structure of the form: $(".email-form").submit(function(event) { event.preventDefault(); var $form = $(this), ...

Utilize Ajax, jQuery, and HTML select elements to showcase customized information

Hey everyone, I could really use some assistance with this. What I'm trying to accomplish is selecting data from a database using the onchange() function in Ajax and then returning the result to the client. I have successfully used Ajax to send inform ...

Encountering a Module not found error with a ValidationError when trying to import an SVG file within a React

I've set up a manual Webpack 5 configuration for my React project with TypeScript. I am facing an issue while trying to import an SVG icon and using Material UI in the project. The error message I'm encountering is: Module not found: ValidationEr ...

Is there a way to move the navbar to the right side of the screen?

How do I create a navigation menu that takes up half of the screen on the left side while allowing for scrolling on the right side without moving the navigation? What I am aiming for is similar to the images linked below: example example I attempted to u ...

Screen JSON data by applying filters

In my current project, I am working on extracting data from a JSON file and presenting it to the user in a way that allows them to input values that match the expected data. My goal is to show different sections of the screen at different times. The initi ...

"Learn the steps to access a JSON file directly from a URL within a Next.js

My goal is to upload a JSON file to the server from a URL, open it, parse it, and display its features on Google Maps. However, I am encountering an error with the "fs" library preventing me from opening the file. Below is the code: "use client" ...

Where did my HTML5 Canvas Text disappear to?

I am encountering a common issue with my code and could use some guidance. Despite numerous attempts, I can't seem to figure out why it isn't functioning properly. To better illustrate the problem, here is a link to the troublesome code snippet o ...

Error: undefined callback function in asynchronous parallel execution

Encountering the error message "callback is not defined" while attempting to utilize async.parallel has left me puzzled. Most examples of async.parallel demonstrate functions being inline, as shown in the async documentation here: https://caolan.github.io/ ...

How to achieve smooth transitions in CSS3 with dynamic height changes?

Currently, I am in the process of designing a unique layout. The main challenge lies in toggling between two classes for a div element, one of which has a height of 0px. To achieve this, I have successfully utilized CSS3 animations that effectively scale t ...

Choosing a combination of classes

For my web application, I created checkboxes that control the visibility of windows by toggling classes on elements. My JavaScript code successfully achieves this functionality. $(document).ready(function(){ $('#field').change(function(){ ...

Avoiding freezing of the user interface caused by ajax requests

The code that was previously commented out on lines 192, 193, 196, 197, 199, and 205 in the base.html file at this link caused my UI to freeze. It made working with my text editor extremely difficult. I am looking for a way to uncomment those lines witho ...