I have a very specific question and I'm not sure if you can do what I want with css. For what I saw on other posts, this may be outside the scope, but I thought I would ask if there would be css geniuses there. I want to achieve a very specific behavior. I have a column of text, and some words in this column are highlighted. When you click on a word, I want the text to split and the video to go up.
my html is simple:
<p>text<span id="clickable" class="link">highlighted text</span>. <div class="closed"> <video id="video" width="100%"> <source src="myVideo.mp4" type="video/mp4"> </video> </div>text</p>
css contains a class closed (with height 0) and a class open with a certain height
CSS
.closed { overflow: hidden; height: 0px; transition-property: all; transition-duration: 2s; transition-timing-function: ease-in-out; } .open { height: 11.4vw; }
js applies the class to the opening when the text is clicked and plays the video, everything is very straight forward
Javascript
$(document).ready(function() { $("#clickable").click(function() { var vid = document.getElementById("video"); var closed = $('.closed'); if(closed.hasClass("open")) { closed.removeClass('open'); vid.pause(); } else { closed.addClass('open'); vid.play(); } }); });
Everything works. But here's the thing, and I know that I'm picky, so I'm not sure if css can do this. The problem is that the text immediately after clicking the "clickable" button goes to the next line. I want this not to be done in a way that disrupts the reading. I know this is because the div in which I have my video is a block element. But if I change the tag to make it span (I know heresy), like this:
<span class="closed"> <video id="video" width="100%"> <source src="myVideo.mp4" type="video/mp4"> </video> </span>
video refuses to follow
overflow: hidden;
and just does not hide from the sight, which is the whole point of what I'm trying to do. Adding
display: inline-block;
the div does not do this. I experimented with some floats, but I get erratic behavior in Chrome. So my ideas are running out. I want the video to work as an inline element. Maybe someone will just relieve me of my suffering and say that it is impossible to do so that I can move on. Thank you for your time.
----------------------------------------------- --- -------------- EDIT -------------------------------- --- --------------------------
Here is an example of my project. This is with the “div” option, and it works the way I want, except that, as I said, after the video text goes to the next line that I don't want.
GIF:
