Image with Responsive Textarea in Bootstrap

Having a bit of trouble figuring things out. Hi everyone!

I have a basic frontend setup with a navbar and two columns below. The left column has a fixed size of 80px, while the right one contains an image (making it fluid/responsive).

The issue I'm facing is adding an input field over the image but making it responsive to the image's size seems to be a challenge.

My idea was to determine the scale of the image and then downscale the input field accordingly using JavaScript.

Here's a snippet of what I had in mind:

$(window).resize(function() {
    // 1192 is the original imagewidth
    let scale = $(".step:visible").width() / 1192;

    let inputposition = document.getElementById(testid);
    inputposition.css('transform', 'scale(' + scale + ')');
    inputposition.css('transform-origin', 'top left');
});

I considered using `transform: scale(scale);` on the input field but that also downscaled the image along with it.

If anyone has some insights or suggestions, please do share them.

Ultimately, my goal is to have the input field resize and reposition as the window size changes.

Below is the sample code I'm currently working with:

<!DOCTYPE html>
<html>

... (rest of the code) ...

</html>

Thanks a lot for your help!

Answer №1

This technique is quite straightforward. Instead of applying position:absolute directly to the <input>, it's better to utilize a <div> for that purpose.

First, create a <div> container with position:relative. Insert an image with the classes w-100 d-block to ensure responsiveness. Then, add a separate <div> element for the overlay and insert your content within. Any <input> or <textarea> elements with the class

.form-control</code will automatically inherit a width of 100%.</p>

<p>
<div>
<div>
<pre class="snippet-code-css lang-css"><code>/*DEMO*/body{padding:3rem}

#overlay{
  position:absolute;
  top:50%;
  right:3rem;
  left:3rem;
  transform:translateY(-50%);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">

<div class="position-relative">
  <img class="w-100 d-block" src="https://via.placeholder.com/400x300/007bff/ffffff" alt="">
  <div id="overlay">
    <input class="form-control" placeholder="Lorem Ipsum">
    <hr>
    <textarea class="form-control" placeholder="Lorem Ipsum"></textarea>
  </div>
</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

Display the div when the total of three drop-down selections surpasses 300

I'm struggling to find a solution to my issue. I have three dropdown selectors and when the total value of these three lists exceeds 300, I want to display a div with a checkbox. This is for my form where customers can receive something for free if th ...

Chrome throwing Dom Mutation warnings related to Angular violations

Recently in our Angular 6 project, I've started noticing some unexpected [Violation] warnings showing up in Chrome. These warnings seem to be originating from line 1666 of zone.js with the message: [Violation] Added synchronous DOM mutation listener ...

Complete the form by following a hyperlink located on a different webpage

I recently developed three PHP pages. The first one consists of the following form: <form method="POST" name="go" action="search_form_all.php" > <input name="value" type="text" id="search_form_1" size="65" placeholder="enter name"/> <i ...

Repositioning SVG rectangles made with d3.js (Using d3 or jQuery for this task)

Situation: I'm currently working on integrating a Google map with a d3 overlay, inspired by Mike Bostock's example found here: http://bl.ocks.org/mbostock/899711 This project is being developed within a Rails 4 application, utilizing d3.js and ...

Tips for organizing a list in Angular 1 when a button is clicked

I'm looking for help with sorting a list in Angular 1 when a button is clicked. I want the ability to toggle between ascending and descending order on each click. Here is a link to the code: https://plnkr.co/edit/HYuk7DAgOY6baWhrvXko?p=preview var ap ...

Rendering HTML strings instead of HTML in ReactJS

When I try to display HTML, all I see is strings var ref = firebase.database().ref('raffle/'); ref.on('value', (snapshot) => { var content = ``; var IDwrapper = document.getElementById('raffleFeed'); snapshot.forEac ...

Increasing numerical section of text with JavaScript

Is there a way to increment the numeric part at the end of a string in JavaScript when certain actions occur? For example: var myString = 'AA11111' increaseStringValue(myString) # Updated value of myString => 'AA11112' Additional ...

Unlocking the potential of Bootstrap 4 pop ups and modals within an Angular 6 project

Angular.json "styles": [ "./node_modules/bootstrap/dist/css/bootstrap.min.css", "./node_modules/ngx-bootstrap/datepicker/bs-datepicker.css", "src/styles.css" ], ...

Processing made easy with jQuery

In my HTML page, I have multiple rows that represent records from a database. Each row contains input fields and a link at the end. When I click on the link, I need to capture the values of the input fields within the same row. Here is an example of the H ...

What might be causing the overflow of my page width by my navbar?

I am currently working on creating a product landing page for freecodecamp, and I'm facing some issues with my navbar - the first element I need to get right. Could you help me identify what's wrong with my code? Additionally, I would like to ad ...

Is it possible to utilize Angular's structural directives within the innerHtml?

Can I insert HTML code with *ngIf and *ngFor directives using the innerHtml property of a DOM element? I'm confused about how Angular handles rendering, so I'm not sure how to accomplish this. I attempted to use Renderer2, but it didn't wor ...

bootstrap hstack containing a table with scroll functionality

Trying to implement a scrollable table within a container alongside other components has proven challenging. While the table functions perfectly on its own, integrating other components below it has presented issues. The use of hstack and d-flex came to mi ...

Creating smooth and natural movement of a div element using Javascript (rotating and moving)

After struggling to use jquery plugins for smooth motion with the div elements I'm working on, I've decided it's time to seek some assistance. I have a group of div elements that all share a class and I want them to move around the screen c ...

React component props are failing to update

import React,{useEffect} from 'react' import { Pin, Group } from './Pin'; import Cluster from './Cluster'; function DisplayClusterGroup({textAsIcon,iconStyle,mapRef,onViewportChange,dataSet,icon,onClick,clickedMarkers }) { ...

Can someone please help me identify the issues in my code? I'm facing difficulties while working with Express and connecting to MongoDB

I'm completely stumped on what's causing the issue in my code. This error message keeps popping up: TypeError: Class constructor MongoStore cannot be invoked without 'new' Does anyone have any insights into this problem? And is there ...

"Jquery's .append function may sometimes display as undefined when

$("#clckjson").click(function() { $(document).ready(function() { $.getJSON("fuelj.json", function(data) { $(data).each(function(i, item) { console.log(item.stationID); var $table = $('<table>'); $table.a ...

Measuring the rendering time of an AngularJS directive

Is there a way to measure the rendering time of a directive (element)? If not, is it possible to identify which directive takes the longest time to render? PS. I have tried using Batarang, but it only displays watch-expressions that consume the most time. ...

Positioning SVGs within a parent container while maintaining responsiveness

How can I anchor an SVG overlay with a circle in the bottom right corner while expanding the rest of the SVG to fill the remaining area of the container without distorting the circle? I've been able to position the SVG in the bottom right corner, but ...

Having difficulties with Smooth Div Scroll and Colorbox integration

Check out the gallery page by following this link: http://www.gerardtonti.com/Scrollable%20Gallery%2/index.html After trying numerous methods, I am still facing the same issue. Upon discovering your jQuery Smooth Div Scroll tool online, I intend to contr ...

Transmit information from JavaScript to HTML and retrieve it using PHP

Hey there, I'm not entirely sure if I'm doing this correctly. Can someone please provide me with an example of how to fetch data in JavaScript and send it to HTML? JS $(document).ready(function() { var chosenYear = $('#choose_year'); ...