1

I have created the jQuery Script below, But am having a few problems converting it to preferably only CSS using transitions. If anybody could help me, I'll be greatfull.

Explanation of the example below:
- When you click on the text box a empty div container drops down, but I am having a few problems with scripting it in just mainly CSS3 Transitions.

HTML:

<div class="div">
    <input type="text" class="textbox" id="textbox"/>
    <p>example</p>
</div>

CSS:

.textbox {width:300px;}
.div { width:300px; background-color:#f8f8f8; }
p {width:300px; height:300px; background-color: #f8f8f8;}

jQuery:

$("#textbox").click(function() {
    $("p").slideToggle();
});

Live demo: jsFiddle

2
  • When I click on the text box, the <p> tags slides up...there's no empty <div> that drops down. Unless I'm missing something... Commented Aug 19, 2012 at 21:07
  • Oh sorry, Yes there is a <p> inside the div, But I'm looking for it in mainly CSS Transitions Commented Aug 19, 2012 at 21:09

1 Answer 1

1
p {
    height: 0;
    overflow: hidden;
    transition: height .3s;
}
input:focus + p {
    height: 20px;
}

Here's your fiddle: http://jsfiddle.net/58VHE/33/ (click to focus on the input).


P.S. Don't forget the vendor prefixes. The fiddle uses -prefix-free to auto-add the vendor prefixes.

Sign up to request clarification or add additional context in comments.

6 Comments

That is the part I am having trouble with, but thank you anyway
@user1608656 - Can you explain what trouble you're having? Does the fiddle work the way you intend it to? If not, what do you expect the result to be?
I am having trouble the vendor prefixes, and have tried scripting it, But have failed. - The result would be clicking on a text box and a div drops down, In CSS3 Transitions. - Just like the jQuery Demo, But in CSS3.
@user1608656 - This is exactly what happens in the fiddle I've linked to. It's all done in CSS3 - no JavaScript.
About the prefixes - Do I have to add that in my code if I save it as a .HTML file?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.