Skip to main content
Enabled syntax highlighting (as a result, the diff looks more extensive than it really is - use view "Side-by-side Markdown" to compare), etc.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

I have an image element that I want to change on click.

<img id="btnLeft">

This works:

#btnLeft:hover {
    width:70px;
    height:74px;
}
#btnLeft:hover {
    width: 70px;
    height: 74px;
}

But what I need is:

#btnLeft:onclick {
    width:70px;
    height:74px;
}
#btnLeft:onclick {
    width: 70px;
    height: 74px;
}

But, it doesn't work, obviously. Is it possible at all to have onclick behavior in CSS (i.e., without using JavaScript)?

I have an image element that I want to change on click.

<img id="btnLeft">

This works:

#btnLeft:hover {
    width:70px;
    height:74px;
}

But what I need is:

#btnLeft:onclick {
    width:70px;
    height:74px;
}

But, it doesn't work, obviously. Is it possible at all to have onclick behavior in CSS (i.e. without using JavaScript)?

I have an image element that I want to change on click.

<img id="btnLeft">

This works:

#btnLeft:hover {
    width: 70px;
    height: 74px;
}

But what I need is:

#btnLeft:onclick {
    width: 70px;
    height: 74px;
}

But, it doesn't work, obviously. Is it possible at all to have onclick behavior in CSS (i.e., without using JavaScript)?

Notice removed Reward existing answer by Sam
Bounty Ended with Mori's answer chosen by Sam
Notice added Reward existing answer by Sam
Bounty Started worth 50 reputation by Sam
edited tags
Link
Makyen
  • 33.6k
  • 12
  • 94
  • 128
Rollback to Revision 6
Source Link
TylerH
  • 21.3k
  • 84
  • 84
  • 121

Selector for `click` Can I have an onclick effect in CSS?

I have an image element that I want to change on click:.

<img id="btnLeft">

This works:

#btnLeft:hover {
    width:70px;
    height:74px;
}

But what I need is:

#btnLeft:onclick {
    width:70px;
    height:74px;
}

But, it doesn't work, obviously.

  Is it possible at all to have onclick behavior in CSS (i.e. without using JavaScript)?

Selector for `click` effect

I have an image element that I want to change on click:

<img id="btnLeft">

This works:

#btnLeft:hover {
    width:70px;
    height:74px;
}

But what I need is:

#btnLeft:onclick {
    width:70px;
    height:74px;
}

But it doesn't work, obviously.

  Is it possible at all to have onclick behavior in CSS (i.e. without using JavaScript)?

Can I have an onclick effect in CSS?

I have an image element that I want to change on click.

<img id="btnLeft">

This works:

#btnLeft:hover {
    width:70px;
    height:74px;
}

But what I need is:

#btnLeft:onclick {
    width:70px;
    height:74px;
}

But, it doesn't work, obviously. Is it possible at all to have onclick behavior in CSS (i.e. without using JavaScript)?

added 2 characters in body; edited title
Source Link
Alexander Abakumov
  • 14.7k
  • 16
  • 99
  • 135
Loading
Post Reopened by TylerH css
Post Closed as "Duplicate" by dippas css
Code Snippets should be reserved for code that actually has a viewable output.
Link
TylerH
  • 21.3k
  • 84
  • 84
  • 121
Loading
Rollback to Revision 3
Source Link
TylerH
  • 21.3k
  • 84
  • 84
  • 121
Loading
Notice removed Reward existing answer by user177800
Bounty Ended with TylerH's answer chosen by CommunityBot
Notice added Reward existing answer by user177800
Bounty Started worth 500 reputation by CommunityBot
Please use the codesnippet to give a live overview of your code result
Source Link
Loading
added 89 characters in body
Source Link
TylerH
  • 21.3k
  • 84
  • 84
  • 121
Loading
added 54 characters in body; edited title
Source Link
TylerH
  • 21.3k
  • 84
  • 84
  • 121
Loading
Question Protected by Quentin
Source Link
Alegro
  • 8.1k
  • 18
  • 55
  • 78
Loading