I don't know a single pure CSS solution for this - moving values ββto auto is something that the specification did not include; I think it was even an explicit solution, based on the fact that there may be problems with the implementation.
But for a βsimpleβ solution, jQuery Id just completes the paragraph content in an extra range, sets the paragraph's initial height to 0 and overflows: hides, leaves the transition for the height in place - and then allows jQuery to do only one thing, read the height of the span element, set the height for the paragraph, and then set it again to 0 to erase the text again.
.details { height: 0; margin: 0; overflow: hidden; transition: height 1s; }
$("div").mouseenter(function() { $(this).find('p').css('height', $(this).find('span').height()); }) $("div").mouseleave(function() { $(this).find('p').css('height', 0); })
In this way, CSS still performs a βheavy liftβ of height change processing using transition (which can be optimized in browsers), and jQuery / JavaScript is used only to create it a little "push", he should know what to do. (It's pretty accurate that jQuery does the same thing internally, and nowadays with animate() , if the browser supports it - the added benefit would be that jQuery will take care of the fallback implementation if the really old browser doesn't support transition ; my solution , the height will simply change instantly, without any transition.)
https://jsfiddle.net/ypwu9n0g/7/
Please note that in this example the method is the same for all four elements, and I did not change the text content; -)
CBroe
source share