Maintaining the position of the screen as you type in information that is located outside of the container

I am encountering an issue with the input/text-area element in absolute position extending halfway outside the container. The screen position seems to follow the caret as I type, but I'd prefer to keep writing and have part of the text hidden beyond the parent element. Is there a way to prevent the screen from scrolling while typing outside the container? It would be ideal if the input text wouldn't scroll either, just concealing whatever is typed beyond the parent and input field.

To clarify further, I've prepared a fiddle

.wrapper {
width: 200px;
height: 150px;
position: relative;
overflow: hidden;
border: 1px solid #ccc;
}
input.test1 {
position: absolute;
top: 50px;
left: 5px;
width: 250px;

}
input.test2 {
position: absolute;
top: 10px;
left: 90px;
width: 150px;
}
<div class='wrapper'>

<input type="text" class="test1" />
<input type="text" class="test2" />

</div>

Answer №1

Here is a suggested solution:

$('.container').on('scroll', function() {
    $('.container').scrollLeft(0);
});
.container {
width: 200px;
height: 150px;
position: relative;
overflow: hidden;
border: 1px solid #ccc;
}
input.test1 {
position: absolute;
top: 50px;
left: 5px;
width: 250px;

}
input.test2 {
position: absolute;
top: 10px;
left: 90px;
width: 150px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='container'>

<input type="text" class="test1" />
<input type="text" class="test2" />

</div>

Answer №2

Looking to adjust the spacing of the input boxes? All I did was insert a space between "input" and ".test1" and ".test2". This should resolve the issue of the first text box overlapping the div.

.container {
width: 200px;
height: 150px;
position: relative;
overflow: hidden;
border: 1px solid #ccc;
}
input .test1 {
position: absolute;
top: 50px;
left: 5px;
width: 250px;
}
input .test2 {
position: absolute;
top: 10px;
left: 90px;
width: 150px;
}
<div class='container'>
<input type="text" class="test1" />
<input type="text" class="test2" />
</div>

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

Encountering an issue when attempting to send a post request with an image, resulting in the following error: "Request failed with status code

Whenever I submit a post request without including an image, everything goes smoothly. However, when I try to add an image, the process fails with an Error: Request failed with status code 409. Below is the code snippet for my react form page. const Entry ...

What is the method for ensuring that the delete functionality is displayed within the same row?

In my division, there are options for names and deletion. It is displayed on my website as: 1.jpg delete The HTML code for the division is: <div id="files1" class="files"> <b class='dataname' >1.jpg</b> <span cla ...

Oops! You forgot to include the necessary getStaticPaths function for dynamic SSG pages on '/blogs/[post]'

Whenever I attempt to execute npm run build, an error occurs. The following build error occurred: Error: getStaticPaths is required for dynamic SSG pages and is missing for '/blogs/[post]'. This is the code snippet causing the issue: function ...

Transmit a JSON array from a controller to a JavaScript variable

I have retrieved a JSON array from a database and it is set up in a controller like this: public ActionResult highlight() { var statesHighlight = db.Jobs .Select(r => r.State); return Json(statesHighlight , JsonRequestBehavi ...

Tips for arranging elements in a customized manner using Bootstrap

Is it possible to reorder columns between desktop and mobile in Bootstrap 5 like the example shown in this image? https://i.sstatic.net/I74PF.jpg I have explored using the order classes and experimented with position: absolute, but I haven't been ab ...

Optimizing images for various screen sizes with responsive design

As I delve into using responsive images, a question has arisen. On my website, there is an icon that comes in two sizes: a small version measuring 74 pixels wide and a larger version at 94 pixels wide. <img alt="Section Gino" style="background-color: ...

Utilize ngFor in Angular Ionic to dynamically highlight rows based on specific criteria

I'm working on an application where I need to highlight rows based on a count value using ngFor in Angular. After trying different approaches, I was only able to highlight the specific row based on my count. Can someone please assist me? Check out m ...

Detecting if the request in Yii Framework 2.0 is coming from an AJAX GET call

While utilizing Yii framework 2.0, I have implemented an AJAX GET jQuery script that references a function within a controller class. $.get('localhost/website/index', {param: 'xxxx'}, function(returnedData){ // some code here..... ...

JavaScript encountered an issue when trying to display HTML content

Through my PHP code, I am attempting to create a popup window that displays the content of an HTML file. However, after adding script tags, no HTML content is displayed. When I tried echoing out $row2, only the word 'array' appeared on the screen ...

What causes a syntax error when attempting to install Babel?

Can someone explain why babel installations are failing with the error shown below? The logs related to this issue can be found here, ...

Submitting forms from a different router in React can pose a unique challenge

As a beginner in React, I am working on creating a simple meal app. In my App component, I am fetching meal data from an api and allowing users to click on a meal for more details. However, I am facing an issue where searching for a new meal on the detail ...

Does Vuejs emit an event when a specific tab becomes active in boostrap-vue?

I am looking for a way to display and hide a section on my page when a specific tab is active, and close it when the tab is inactive. I have tried using the forceOpenSettings and forceCloseSettings methods for opening and closing the div. Is there an event ...

Fixing the department display list in React Hook: A step-by-step guide

{ roomDept.map((item, index) => ( <div key={index} className="flex flex-col pb-2 items-center"> <div className="flex pb-2 w-full"> <SelectPick ...

Using Try and Catch effectively - tips and strategies

As I delve into learning JavaScript on my own, one topic that caught my attention is the try/catch structure. The tutorial I came across only covers how to implement it, but lacks in explaining its practical applications. Is there anyone who can shed som ...

Adding an image to an HTML page

I am working on an HTML page and need to insert an image. Here is the code I currently have: <img src="../Images/logo.jpg" alt="Logo" height="50"> I chose "../Images/logo.jpg" as the source because my logo.jpg is located two levels up from the curr ...

Refining Calculated Attributes

I am currently creating a list where you can add and remove elements while specifying the count of each added element. I have included all elements in my data: Example: [ { "rowID": "21", "rowAnzahl": 1, "elementID": "127", "elementNam ...

Call order for importing and exporting in NodeJS

This question is related to "code theory." Let's explore a scenario where I am utilizing the global namespace in a package. The structure includes a main entrypoint file, classes that are exported, and utility files used by the classes. Here's a ...

Converting an Angular promise into a jQuery deferred object: A guide

I am looking for a way to send promises from my module/sdk to non-angular JavaScript. If I return a promise to jQuery, it seems like I should use a jQuery deferred object. Is there a way to convert an Angular promise to a jQuery promise/deferred object? A ...

A step-by-step guide to launching a user control as a popup with jQuery dialog

On my Parts.aspx page, I have UserControl1.ascx which contains a textbox and button1. Additionally, Add.ascx consists of a textbox, button2, and button3. Now, I have included UserControl1.ascx on the parts.aspx page. Upon clicking button1 in UserControl1. ...

Blackberry Browser 4.2 experiencing spacing troubles

Seeking advice for developing a web application specifically for the Blackberry Browser 4.2. Looking to add vertical spacing between a series of links, but struggling due to lack of support for padding and margin in this version. Have tried using height an ...