There are different approaches to create rectangles containing text input boxes using JavaScript. One possible way is to use HTML and CSS to create the rectangle structure and add the input boxes dynamically with JavaScript. Here is an example:
HTML:
<div id="rectangle-container"></div>
CSS:
.rectangle {
border: 1px solid #000;
padding: 10px;
margin-bottom: 10px;
}
JavaScript:
// Get a reference to the rectangle container
var rectangleContainer = document.getElementById("rectangle-container");
// Define the dimensions and text of the rectangles
var rectangles = [
{ width: "200px", height: "100px", text: "Rectangle 1" },
{ width: "300px", height: "150px", text: "Rectangle 2" },
{ width: "150px", height: "75px", text: "Rectangle 3" }
];
// Loop through the rectangles and create a div for each one
for (var i = 0; i < rectangles.length; i++) {
var rectangle = rectangles[i];
// Create the rectangle div and set its CSS properties
var rectangleDiv = document.createElement("div");
rectangleDiv.className = "rectangle";
rectangleDiv.style.width = rectangle.width;
rectangleDiv.style.height = rectangle.height;
rectangleDiv.textContent = rectangle.text;
// Create the input box and append it to the rectangle div
var inputBox = document.createElement("input");
inputBox.type = "text";
rectangleDiv.appendChild(inputBox);
// Add the rectangle div to the container
rectangleContainer.appendChild(rectangleDiv);
}
This code creates three rectangles with different dimensions and text, and adds an input box to each one. The rectangles are displayed inside the rectangle-container
div using the CSS styles defined for the .rectangle
class. The resulting HTML structure will look like this:
<div id="rectangle-container">
<div class="rectangle" style="width: 200px; height: 100px;">Rectangle 1<input type="text"></div>
<div class="rectangle" style="width: 300px; height: 150px;">Rectangle 2<input type="text"></div>
<div class="rectangle" style="width: 150px; height: 75px;">Rectangle 3<input type="text"></div>
</div>
Asked: 2021-06-19 11:00:00 +0000
Seen: 14 times
Last updated: Nov 11 '22