/    Sign up×
Community /Pin to ProfileBookmark

CSS transition

In the following code I can move the ‘*’ character from one side of the label to the other
with a ‘text-align: left || right’ setting. The effect is immediate when clicked.

I wanted to try using the ‘transition’ command to move the ‘*’ character
smoothly across the label area rather than the immediate jump effect.
However, if you run the sample, the transition code seems to have no effect.

Any ideas as to what to change to make the ‘*’ character move smoothly
back and forth within the element?

[code]
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width-device-width,initial-scale=1.0, user-scalable=yes”/>
<title> HTML5 Test Page </title>
<!– link rel=”stylesheet” href=”common.css” media=”screen” –>
<style>
label { width: 5em; border: 1px solid black; display: inline-block;
color: blue; background-color: orange; text-align: left; }
input:checked + label { text-align: right; }

#sw {
-webkit-transition: all 2s ease-in-out;
-moz-transition: all 2s ease-in-out;
-o-transition: all 2s ease-in-out;
transition: all 2s ease-in-out;
}
#sw {
transition-property: left;
transition-duration: 2s;
transition-delay: 0s;
}
</style>
</head>
<body>
<input type=”checkbox” id=”cbox”><label for=”cbox” id=”sw1″><div id=”sw”>&#x2600;</div></label>
</body>
</html>

[/code]

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJun 14.2019 — text-align cannot be animated. You need to use transform:translate or absolute positioning. This works:
&lt;style&gt;
label {
width: 5em;
border: 1px solid black;
display: inline-block;
color: blue;
background-color: orange;
text-align: left;
}

<i> </i> input:checked+label&gt;#sw {
<i> </i> transform: translateX(4em);
<i> </i> }

<i> </i> #sw {
<i> </i> transition: all 2s ease-in-out;
<i> </i> }
<i> </i>&lt;/style&gt;

<i> </i>&lt;input type="checkbox" id="cbox"&gt;&lt;label for="cbox" id="sw1"&gt;
<i> </i> &lt;div id="sw"&gt;&amp;#x2600;&lt;/div&gt;
<i> </i>&lt;/label&gt;
Copy linkTweet thisAlerts:
@JMRKERauthorJun 14.2019 — Thank you 'Sempervivum'. Works like a charm.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...