create a pop up using bootstrap css and html, write css in… · The Chat Archive
Sure! Below is an example of a Bootstrap pop-up (modal) dialog box created using HTML and CSS. This modal includes:
Two file input fields (styled with a stipple outline).
A "Continue" button.
A "Cancel" button.
A dropdown menu with three options accessed through three dots in the top right corner.
A close button (cross) at the top of the modal.
HTML Code:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<title>Bootstrap Modal Example</title>
<style>
.file-input {
border: 2px dashed #007bff;
border-radius: 0.25rem;
padding: 20px;
text-align: center;
margin: 10px 0;
}
.file-input input[type="file"] {
display: none;
}
.file-label {
display: inline-block;
cursor: pointer;
color: #007bff;
}
.modal-header .dropdown-toggle::after {
display: none; /* Hides the dropdown arrow */
}
.modal-header {
position: relative;
}
.close {
position: absolute;
right: 15px;
top: 15px;
color: #000;
font-size: 1.5rem;
opacity: 0.5;
}
.dropdown-menu {
left: -20px; /* Align dropdown correctly */
}
</style>
</head>
<body>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Upload Files</h5>
<div class="dropdown ml-auto">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
...
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Option 1</a>
<a class="dropdown-item" href="#">Option 2</a>
<a class="dropdown-item" href="#">Option 3</a>
</div>
</div>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="file-input">
<label class="file-label" for="file1">Upload File 1</label>
<input type="file" id="file1" />
</div>
<div class="file-input">
<label class="file-label" for="file2">Upload File 2</label>
<input type="file" id="file2" />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Continue</button>
</div>
</div>
</div>
</div>
<!-- Button to trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Open Modal
</button>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
Explanation:
Bootstrap Framework : The code includes links to Bootstrap CSS and JS files from a CDN. Ensure that you have internet access to load these resources.
Modal Structure : The modal is structured using Bootstrap's classes. The modal-header, modal-body, and modal-footer classes are used to define the layout.
File Input Styling : Custom CSS is applied to the file inputs to create a dashed outline effect.
Dropdown Menu : The three dots act as a toggle for the dropdown menu, styled according to Bootstrap's styles.
Close Button : The close button ('×') allows users to dismiss the modal.
Trigger Button : A button is provided outside the modal to open it.
To use it, just copy and paste the HTML into your web page, and you can adjust the options in the dropdown as needed. The modal can be triggered by clicking the “Open Modal” button.
create a form with
image upload (stipple outline) and this window is the sixe of feature image
fields: name, designation, date, reason
editable table with 6 columns and an ability to load file
Assistant2025-03-03 13:05 UTC Copy response
Below is an example of an HTML form that includes:
An image upload input styled with a stippled outline that resembles a feature image area.
Input fields for "Name," "Designation," "Date," and "Reason."
An editable table with six columns and an option to upload a file within that table.
HTML Code:
move text fields to the right
add some button that will load file into table
Assistant2025-03-03 13:07 UTC Copy response
To adjust the layout, we can move the text fields to the right by utilizing Bootstrap's grid system. We can also add a button that allows users to load files into the table dynamically. Below is the updated code:
Updated HTML Code:
change image ratio of sides to 1280x904
Assistant2025-03-03 13:09 UTC Copy response
To adjust the image upload area to a specific aspect ratio (1280x904), you can modify the CSS styles of the .file-input class. This will include setting the width and height to maintain the desired aspect ratio. Additionally, you should use a container that constrains the dimensions.
Here's the updated code with the adjusted image upload dimensions:
Updated HTML Code with Aspect Ratio 1280x904:
Assistant2025-03-03 13:13 UTC Copy response
No problem! Let's adjust the image upload area to maintain the aspect ratio of 904x1280. Here’s the updated code with the required changes:
Updated HTML Code for 904x1280 Aspect Ratio:
убираем таблицу снизу
слева под ввод картинки
справа под ввод имя, дата, обозначение, причина изменения и ввод файлов (они потом там как теги отображаются)
сверху заглушка навбара
заголовок 'новая сборка'
кнопка продолжить
Assistant2025-03-03 13:33 UTC Copy response
To create the layout you described, we'll avoid using a table and instead arrange the elements in a structured form. We will position the image upload area on the left, and the input fields on the right, below a navigation bar and a header titled "Новая сборка" ("New Assembly").
The file uploads will be handled similarly to tags, which can be displayed dynamically. Here's the complete code:
Complete HTML Code:
Not yet included in a published release.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<title>Form with Image Upload and Editable Table</title>
<style>
.file-input {
border: 2px dashed #007bff;
border-radius: 0.25rem;
padding: 50px;
text-align: center;
margin: 20px 0;
height: 200px; /* Custom height for the feature image */
display: flex;
justify-content: center;
align-items: center;
color: #007bff;
}
.file-input input[type="file"] {
display: none;
}
.file-label {
display: inline-block;
cursor: pointer;
color: #007bff;
}
.table-row {
align-items: center;
}
.editable-cell {
cursor: text;
vertical-align: middle;
}
.upload-btn {
cursor: pointer;
}
</style>
</head>
<body>
<div class="container mt-5">
<form>
<div class="file-input">
<label class="file-label" for="imageUpload">Upload Feature Image</label>
<input type="file" id="imageUpload" accept="image/*" />
</div>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" required>
</div>
<div class="form-group">
<label for="designation">Designation:</label>
<input type="text" class="form-control" id="designation" required>
</div>
<div class="form-group">
<label for="date">Date:</label>
<input type="date" class="form-control" id="date" required>
</div>
<div class="form-group">
<label for="reason">Reason:</label>
<textarea class="form-control" id="reason" rows="3" required></textarea>
</div>
<h5>Editable Table</h5>
<table class="table">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Upload</th>
</tr>
</thead>
<tbody>
<tr class="table-row">
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td>
<label class="upload-btn" for="fileUpload1">Upload File</label>
<input type="file" id="fileUpload1" style="display:none;" />
</td>
</tr>
<tr class="table-row">
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td>
<label class="upload-btn" for="fileUpload2">Upload File</label>
<input type="file" id="fileUpload2" style="display:none;" />
</td>
</tr>
<!-- Add more rows as needed -->
</tbody>
</table>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Show file uploads when the label is clicked
document.querySelectorAll('.upload-btn').forEach(function(btn) {
btn.addEventListener('click', function() {
const fileInputId = this.getAttribute('for');
document.getElementById(fileInputId).click();
});
});
</script>
</body>
</html>
Explanation of the Code:
Image Upload : The image upload area is styled with a stipple outline using a dashed border and a flexbox for centering the label.
Form Fields : The required fields for "Name," "Designation," "Date," and "Reason" are created using Bootstrap's form components.
Editable Table : The table consists of six columns, and each cell can be edited by clicking within it. The cells are marked as contenteditable="true".
File Upload in Table : Each row in the table includes a label for the file upload, linking to hidden file input elements with a click event listener to trigger the file upload dialog.
Submit Button : A button to submit the form is included at the bottom.
Usage:
Copy the above code and paste it into your HTML file, then open it in a web browser. You can edit the table and upload images or files as specified. Adjust the table rows as necessary to match your requirements.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<title>Form with Image Upload and Editable Table</title>
<style>
.file-input {
border: 2px dashed #007bff;
border-radius: 0.25rem;
padding: 50px;
text-align: center;
margin: 20px 0;
height: 200px; /* Custom height for the feature image */
display: flex;
justify-content: center;
align-items: center;
color: #007bff;
}
.file-input input[type="file"] {
display: none;
}
.file-label {
display: inline-block;
cursor: pointer;
color: #007bff;
}
.table-row {
align-items: center;
}
.editable-cell {
cursor: text;
vertical-align: middle;
}
.upload-btn {
cursor: pointer;
}
</style>
</head>
<body>
<div class="container mt-5">
<form>
<div class="row">
<div class="col-md-6">
<div class="file-input">
<label class="file-label" for="imageUpload">Upload Feature Image</label>
<input type="file" id="imageUpload" accept="image/*" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" required>
</div>
<div class="form-group">
<label for="designation">Designation:</label>
<input type="text" class="form-control" id="designation" required>
</div>
<div class="form-group">
<label for="date">Date:</label>
<input type="date" class="form-control" id="date" required>
</div>
<div class="form-group">
<label for="reason">Reason:</label>
<textarea class="form-control" id="reason" rows="3" required></textarea>
</div>
<button type="button" class="btn btn-primary" id="addFileRow">Add File Row</button>
</div>
</div>
<h5 class="mt-4">Editable Table</h5>
<table class="table">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Upload</th>
</tr>
</thead>
<tbody id="fileTableBody">
<tr class="table-row">
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td>
<label class="upload-btn" for="fileUpload1">Upload File</label>
<input type="file" id="fileUpload1" style="display:none;" />
</td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Show file uploads when the label is clicked
document.querySelectorAll('.upload-btn').forEach(function(btn) {
btn.addEventListener('click', function() {
const fileInputId = this.getAttribute('for');
document.getElementById(fileInputId).click();
});
});
// Function to add a new row to the table
document.getElementById('addFileRow').addEventListener('click', function() {
const newRow = `
<tr class="table-row">
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td>
<label class="upload-btn" for="fileUploadNew">Upload File</label>
<input type="file" id="fileUploadNew" style="display:none;" />
</td>
</tr>
`;
document.getElementById('fileTableBody').insertAdjacentHTML('beforeend', newRow);
// Add event listener to the new upload button
const newUploadBtn = document.querySelector('#fileTableBody .table-row:last-child .upload-btn');
newUploadBtn.addEventListener('click', function() {
const fileInputId = this.getAttribute('for');
document.getElementById(fileInputId).click();
});
});
</script>
</body>
</html>
Changes and Additions Made:
Shifted Text Fields : The form fields for "Name," "Designation," "Date," and "Reason" are now placed inside a Bootstrap grid column allowing them to shift to the right of the image upload area.
"Add File Row" Button : A new button was added below the text fields labeled "Add File Row." When clicked, it dynamically generates a new row in the table with editable cells and a file upload option.
Dynamic Row Creation : The script has been updated to allow for the addition of a new row to the table, with the same editable cells and upload functionality. Each added row includes an appropriate click event to handle file uploads.
Usage:
Copy the updated code into your HTML file and view it in a browser. The layout will provide a user-friendly approach to adding details, uploading images, and handling additional file inputs within the table. Adjustments to styles and functionality can be made as per your requirements.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<title>Form with Image Upload and Editable Table</title>
<style>
.file-input {
border: 2px dashed #007bff;
border-radius: 0.25rem;
display: flex;
justify-content: center;
align-items: center;
color: #007bff;
margin: 20px 0;
/* Set the width and height to maintain the 1280x904 ratio */
width: 100%; /* Perform well on different screen sizes */
max-width: 1280px; /* Maintain specific width */
height: calc(1280px * (904 / 1280)); /* Calculate height based on the ratio */
}
.file-upload-label {
text-align: center;
width: 100%; /* Ensures label covers full width */
}
.file-input input[type="file"] {
display: none;
}
.table-row {
align-items: center;
}
.editable-cell {
cursor: text;
vertical-align: middle;
}
.upload-btn {
cursor: pointer;
}
</style>
</head>
<body>
<div class="container mt-5">
<form>
<div class="row">
<div class="col-md-6">
<div class="file-input">
<label class="file-upload-label" for="imageUpload">Upload Feature Image (1280x904)</label>
<input type="file" id="imageUpload" accept="image/*" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" required>
</div>
<div class="form-group">
<label for="designation">Designation:</label>
<input type="text" class="form-control" id="designation" required>
</div>
<div class="form-group">
<label for="date">Date:</label>
<input type="date" class="form-control" id="date" required>
</div>
<div class="form-group">
<label for="reason">Reason:</label>
<textarea class="form-control" id="reason" rows="3" required></textarea>
</div>
<button type="button" class="btn btn-primary" id="addFileRow">Add File Row</button>
</div>
</div>
<h5 class="mt-4">Editable Table</h5>
<table class="table">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Upload</th>
</tr>
</thead>
<tbody id="fileTableBody">
<tr class="table-row">
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td>
<label class="upload-btn" for="fileUpload1">Upload File</label>
<input type="file" id="fileUpload1" style="display:none;" />
</td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Show file uploads when the label is clicked
document.querySelectorAll('.upload-btn').forEach(function(btn) {
btn.addEventListener('click', function() {
const fileInputId = this.getAttribute('for');
document.getElementById(fileInputId).click();
});
});
// Function to add a new row to the table
document.getElementById('addFileRow').addEventListener('click', function() {
const newRow = `
<tr class="table-row">
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td>
<label class="upload-btn" for="fileUploadNew">Upload File</label>
<input type="file" id="fileUploadNew" style="display:none;" />
</td>
</tr>
`;
document.getElementById('fileTableBody').insertAdjacentHTML('beforeend', newRow);
// Add event listener to the new upload button
const newUploadBtn = document.querySelector('#fileTableBody .table-row:last-child .upload-btn');
newUploadBtn.addEventListener('click', function() {
const fileInputId = this.getAttribute('for');
document.getElementById(fileInputId).click();
});
});
</script>
</body>
</html>
Changes Made:
Aspect Ratio for Image Upload :
The .file-input class is updated to explicitly set its width to maintain an aspect ratio of 1280x904.
The height is calculated dynamically based on the desired width to maintain the aspect ratio.
Label Update :
The label for the file input now specifies that the upload is intended for a feature image with a recommended aspect ratio.
Usage:
You can copy and paste the above code into your HTML file and open it in a web browser. The image upload area will now maintain the desired dimensions (1280x904), and the layout will also adjust to accommodate the form fields on the right. You can further customize the styles or functionality as needed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<title>Form with Image Upload and Editable Table</title>
<style>
.file-input {
border: 2px dashed #007bff;
border-radius: 0.25rem;
display: flex;
justify-content: center;
align-items: center;
color: #007bff;
margin: 20px 0;
/* Set the width and height to maintain the 904x1280 ratio */
width: 100%; /* Perform well on different screen sizes */
max-width: 904px; /* Maintain specific width */
height: calc(904px * (1280 / 904)); /* Calculate height based on the ratio */
}
.file-upload-label {
text-align: center;
width: 100%; /* Ensures label covers full width */
}
.file-input input[type="file"] {
display: none;
}
.table-row {
align-items: center;
}
.editable-cell {
cursor: text;
vertical-align: middle;
}
.upload-btn {
cursor: pointer;
}
</style>
</head>
<body>
<div class="container mt-5">
<form>
<div class="row">
<div class="col-md-6">
<div class="file-input">
<label class="file-upload-label" for="imageUpload">Upload Feature Image (904x1280)</label>
<input type="file" id="imageUpload" accept="image/*" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" required>
</div>
<div class="form-group">
<label for="designation">Designation:</label>
<input type="text" class="form-control" id="designation" required>
</div>
<div class="form-group">
<label for="date">Date:</label>
<input type="date" class="form-control" id="date" required>
</div>
<div class="form-group">
<label for="reason">Reason:</label>
<textarea class="form-control" id="reason" rows="3" required></textarea>
</div>
<button type="button" class="btn btn-primary" id="addFileRow">Add File Row</button>
</div>
</div>
<h5 class="mt-4">Editable Table</h5>
<table class="table">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Upload</th>
</tr>
</thead>
<tbody id="fileTableBody">
<tr class="table-row">
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td>
<label class="upload-btn" for="fileUpload1">Upload File</label>
<input type="file" id="fileUpload1" style="display:none;" />
</td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Show file uploads when the label is clicked
document.querySelectorAll('.upload-btn').forEach(function(btn) {
btn.addEventListener('click', function() {
const fileInputId = this.getAttribute('for');
document.getElementById(fileInputId).click();
});
});
// Function to add a new row to the table
document.getElementById('addFileRow').addEventListener('click', function() {
const newRow = `
<tr class="table-row">
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td contenteditable="true" class="editable-cell">Editable Cell</td>
<td>
<label class="upload-btn" for="fileUploadNew">Upload File</label>
<input type="file" id="fileUploadNew" style="display:none;" />
</td>
</tr>
`;
document.getElementById('fileTableBody').insertAdjacentHTML('beforeend', newRow);
// Add event listener to the new upload button
const newUploadBtn = document.querySelector('#fileTableBody .table-row:last-child .upload-btn');
newUploadBtn.addEventListener('click', function() {
const fileInputId = this.getAttribute('for');
document.getElementById(fileInputId).click();
});
});
</script>
</body>
</html>
Key Modifications:
Aspect Ratio for Image Upload :
The .file-input class is updated to properly set its height and width to maintain the 904x1280 aspect ratio.
The max-width property is set to 904px , and the height is calculated based on the desired width.
Label Update :
The label for the file input now specifies that the upload is intended for a feature image with a recommended aspect ratio of 904x1280.
Usage:
Copy and paste this updated code into your HTML file and open it in a web browser. The image upload area will maintain the desired dimensions (904x1280), and the layout will accommodate the form fields on the right. You can further customize styles and functionalities as necessary.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<title>Новая сборка</title>
<style>
body {
background-color: #f8f9fa;
}
.file-input {
border: 2px dashed #007bff;
border-radius: 0.25rem;
display: flex;
justify-content: center;
align-items: center;
color: #007bff;
margin: 20px 0;
width: 100%; /* Fits the parent width */
max-width: 904px; /* Maintain specific width */
height: calc(904px * (1280 / 904)); /* Calculate height based on the ratio */
}
.file-upload-label {
text-align: center;
width: 100%;
}
.uploaded-files {
display: flex;
flex-wrap: wrap;
margin-top: 10px;
}
.uploaded-file {
background-color: #007bff;
color: white;
padding: 5px 10px;
border-radius: 8px;
margin-right: 5px;
margin-bottom: 5px;
}
.navbar {
margin-bottom: 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-light bg-light">
<a class="navbar-brand" href="#">My Application</a>
</nav>
<div class="container mt-5">
<h2>Новая сборка</h2>
<div class="row">
<div class="col-md-6">
<div class="file-input">
<label class="file-upload-label" for="imageUpload">Загрузите изображение (904x1280)</label>
<input type="file" id="imageUpload" accept="image/*" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="name">Имя:</label>
<input type="text" class="form-control" id="name" required>
</div>
<div class="form-group">
<label for="designation">Обозначение:</label>
<input type="text" class="form-control" id="designation" required>
</div>
<div class="form-group">
<label for="date">Дата:</label>
<input type="date" class="form-control" id="date" required>
</div>
<div class="form-group">
<label for="reason">Причина изменения:</label>
<textarea class="form-control" id="reason" rows="3" required></textarea>
</div>
<div class="form-group">
<label>Загруженные файлы:</label>
<div class="uploaded-files" id="uploadedFilesContainer"></div>
<input type="file" id="fileUpload" style="display:none;" />
<button type="button" class="btn btn-secondary mt-2" id="addFileBtn">Добавить файл</button>
</div>
</div>
</div>
<button type="button" class="btn btn-primary">Продолжить</button>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Show file upload dialog when 'Добавить файл' button is clicked
document.getElementById('addFileBtn').addEventListener('click', function() {
document.getElementById('fileUpload').click();
});
// Handle file selection and display it as a tag
document.getElementById('fileUpload').addEventListener('change', function() {
const uploadedFilesContainer = document.getElementById('uploadedFilesContainer');
Array.from(this.files).forEach(file => {
const fileTag = document.createElement('div');
fileTag.className = 'uploaded-file';
fileTag.textContent = file.name;
uploadedFilesContainer.appendChild(fileTag);
});
this.value = ''; // Reset the input after selection
});
</script>
</body>
</html>
Explanation of the Code:
Navbar : A simple navbar is created at the top using Bootstrap classes.
Header : The title "Новая сборка" (“New Assembly”) is displayed prominently.
Image Upload Area : The left column contains the image upload section with a stippled outline; the specified dimensions (904x1280) are maintained.
Input Fields : The right column holds all form input fields: Name, Designation, Date, and Reason for Change.
File Upload Input :
A hidden file input (fileUpload) is created for adding files.
A button "Добавить файл" ("Add File") is used to trigger this hidden input.
When a file is selected, its name is displayed in the form of tags below the button, visually indicating which files have been uploaded.
Continue Button : A button labeled "Продолжить" ("Continue") is at the bottom, ready for further actions.
Usage:
Copy the provided code into your HTML file and open it in your web browser. You’ll see the structured form with a functional interface for uploading images and files, matching the layout you specified. You can further customize styles and functionality as needed.