Turn the div called "window" into a new div positioned underneath

To create a scroll-like animation using CSS, I want to have one HTML div act as a "window" that shows another div beneath it. This lower div can then be animated to move up and down, covering the content as it moves in and out of view. The background div will only contain text on separate lines, while the front or "window" div is empty but has the height of one line of text.

Many suggestions mention making the parent element "position: relative;" and the child element "absolute;". However, when I try moving the child element, it goes outside the viewport. For some reason, overflow:hidden; doesn't work for the window div.

<div class="sometext">
hello I am 
  <div class="window">
    funny
    <div class="view">
    funny<br>great<br>dull<br>silly
    </div>
  </div>
</div>

CSS:

.sometext{
  background-color:pink;
}

.window{
  display:inline;
  position:relative;
  color:transparent;
  overflow:hidden;
  background-color:green;
  z-index:1;
}

.view{
 position:absolute;
 top:0;
 right:0;
 color:black;
 overflow:hidden;
}

Check out the code here: https://jsfiddle.net/u23hv1dx/

Note:

  • The viewport should only show the green rectangle initially, displaying only the word "funny." You can change this by adjusting the .view's top parameter.

  • The .window element contains the (transparent) word "funny" simply to provide the necessary width for the child element.

  • By the way, why is the child element positioned slightly to the right of its ancestor?

Answer №1

After carefully considering your inquiry, it appears that setting overflow hidden to inline elements is not feasible. Instead, try using inline-block, aligning the content to the bottom vertically, and adjusting the line-height to 1. This should resolve the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to display text from a file on a different html page using jQuery's json2html?

Here is the json data: var data = [ { "name": "wiredep", "version": "4.0.0", "link": "https://github.com/taptapship/wiredep", "lice ...

Unable to Embed Tweets resulting in 403 Error (Forbidden)

While working on embedding some Tweets on my webpage, I encountered the following error message: GET https://cdn.api.twitter.com/1/friendships/exists.json?user_a=19463349&screen_name_b=mrland_news&callback=twttr.setFriendshipExists 403 (Forbidden) ...

HTML, PHP, and MySQLI registration form without any noticeable errors

For a personal project, I am currently working on coding a registration form for my webpage. Although the webpage loads, nothing seems to be happening. No data is being inserted into the database. Below is the HTML code for the form. Note that I am usin ...

Utilizing jQuery to display labels only for selected checkboxes while concealing the ones that are not checked

I currently have the following setup: <style>.selectit{display:none;}</style> <div id="foo"> <label class="selectit"> <input type="checkbox" name="one" id="one" checked> One </label> <label class="selectit"> <i ...

What is the best way to move between websites or pages without having to reload the current page using a selector?

Have you ever wondered how to create a webpage where users can navigate to other websites or pages without seeing their address, simply by selecting from a drop-down menu? Take a look at this example. Another similar example can be found here. When visit ...

Using Javascript to Change Background Color on Button Click

The button press does not result in a change of the background color. What could be causing this issue? var body = document.getElementsByTagName("body"); var bgbutton = doucument.getElementById("bgchange"); bgbutton.onclick = function() { body.style.b ...

Expand and reposition other div boxes by manipulating the div box dimensions

For my current project, I am aiming for a three-box style page. However, I am facing an issue where the boxes float over each other when they auto-expand to fit the content inside. This is due to the positioning that I have set for them. This is the HTML ...

Encountering an error while submitting form via Ajax to PHP backend

Currently, I am in the process of developing a form that solicits information from a user, including their name, address, amount1, amount2, and a comment. It seems that the radio inputs for amount1 and amount2 are causing issues with my form. Upon submiss ...

The calculation in JavaScript using the Math formula yields unexpected numerical outcomes

I'm struggling to wrap my head around this. I've designed an HTML form for calculating body fat percentage with a conditional field depending on the selected gender. The JavaScript formula works correctly for males but gives a strange result for ...

Position pictures in the same row in a straight line

I am struggling to align a set of images properly. The screenshot below shows the current layout: My goal is to have all four images lined up in a single row, with any additional images starting on a new row. I have attempted various methods, but none ha ...

Guide to creating an endless loop animation within a frame

<div className="sound-wave-container py-8"> <img src={!recording ? Wave : DottedLine} className={!recording ? "sound-wave" : ""} alt="Sound Wave" /> </div> ...

Button with embedded Bootstrap dropdown

I need help with centering a dropdown menu on my webpage. I followed the instructions, but it's still appearing next to the button instead of in the center. Below is the code snippet: <div class="btn-group"> <button type=" ...

Matching start and end of CSS selectors using regex

If I have elements with a title attribute like the examples below, how can I select the div with the title custom-marker-wqs-tailrace bbu-l2 using a CSS regex selector? <div title="custom-marker-awlr-tailrace bbu-l2"></div> <div ti ...

centered logo in a flexbox header

Having trouble with Flex for the first time. Despite reading and experimenting, I still can't figure it out. Any suggestions on how to accomplish this? Check out an example ...

Content linked to an uneditable text box that does not appear in the HTML code

I recently encountered a situation where the value in a readonly textbox was not found in the underlying page HTML. Even though the browser displayed 'A504Y' in the textbox, I couldn't retrieve it using Webdriver's .text method: string ...

Conceal the page's content as it moves beneath a stationary div

My issue involves a fixed div position with a margin from the top of the page. When I scroll my page, the content of my relatively positioned div (containing page content) is visible under the fixed div due to the margin from the top of the page. Despite s ...

Find the current location of the scroll bar on the view port

Currently, I am utilizing the Addazle React grid for my project. However, I need to incorporate endless scrolling functionality which is not already included in this grid system. Thus, I am tasked with devising my own solution for this issue. To successful ...

What is the best way to make a flex box smoothly appear on the

Is there a way to make a flex box hidden until it fades in without losing its flexibility? I used to use 'display: 0;' and then apply jQuery .fadeIn(). However, setting display to 0 causes the flex properties of the box to disappear when fading i ...

Can a dynamic hyperlink be included in an email using exclusively JavaScript without any HTML? (Utilizing Google Script to send the email)

Just to clarify, I am not using JavaScript directly in the email. Instead, I am utilizing Google Script to send the email. Although I don't have much experience with HTML/JS in emails, my roommate needed assistance in adding a dynamic link using Java ...

Achieve a fading effect on an element as you scroll down the page

I successfully implemented a toggle audio button on my website, but now I would like it to fade in along with the scroll-to-top button that I also have (which operates similarly to the buttons on scrolltotop.com). Is there a simple way to achieve this? He ...