function createCard(arr,lst){
const cardItem = document.createElement('li');
cardItem.classList.add('cards_item');
const card = document.createElement('div');
card.classList.add('card');
const cardImage = document.createElement('div');
cardImage.classList.add('card_image');
const img = document.createElement('img');
if(arr[2].includes("pdf"))
img.src = "/images/pdf_gif.gif";
else
img.src = "/images/webportal_gif.gif";
cardImage.appendChild(img);
const cardContent = document.createElement('div');
cardContent.classList.add('card_content');
const cardTitle = document.createElement('h2');
cardTitle.classList.add('card_title');
cardTitle.textContent = arr[0].toUpperCase(); // Set the title dynamically
const cardText = document.createElement('p');
cardText.classList.add('card_text');
cardText.textContent = arr[1]; // Set the description dynamically
const btn = document.createElement('button');
btn.classList.add('btn', 'card_btn');
btn.textContent = 'Download';
btn.addEventListener('click', function () {
// Create an anchor element
const downloadLink = document.createElement('a');
downloadLink.style.display = 'none'; // Hide the anchor element
// Extract filename from URL
const url = arr[2]; // Assuming arr[2] contains the PDF file URL
const filename = url.split('/').pop(); // Extract filename from URL
// Set the download attribute and href for the PDF file
downloadLink.download = filename; // Set the filename
downloadLink.href = url; // Set the PDF file URL
// Append the anchor element to the body
document.body.appendChild(downloadLink);
// Trigger a click on the anchor to initiate the download
downloadLink.click();
// Remove the anchor element from the body
document.body.removeChild(downloadLink);
});
const tiltedDiv = document.createElement('div');
tiltedDiv.innerText = arr[6];
tiltedDiv.classList.add('tilted_div');
// Append elements to the card
cardContent.appendChild(cardTitle);
cardContent.appendChild(cardText);
cardContent.appendChild(btn);
card.appendChild(tiltedDiv);
card.appendChild(cardImage);
card.appendChild(cardContent);
cardItem.appendChild(card);
lst.appendChild(cardItem);
}
Я хочу создать простой вид карточки с наклоненным элементом div, который должен находиться в верхнем левом углу карточки. Это мой код: [b]CSS[/b] [code] .cards_item { display: flex; padding: 1rem; width: 70%; }
.card { position: relative; background-color: white; border-radius: 0.25rem; box-shadow: 0 20px 40px -14px rgba(0, 0, 0, 0.25); display: flex; flex-direction: column; overflow: hidden; z-index: 0; width: 100%; /* Make each card take full width */ }
const cardTitle = document.createElement('h2'); cardTitle.classList.add('card_title'); cardTitle.textContent = arr[0].toUpperCase(); // Set the title dynamically
const cardText = document.createElement('p'); cardText.classList.add('card_text'); cardText.textContent = arr[1]; // Set the description dynamically
btn.addEventListener('click', function () { // Create an anchor element const downloadLink = document.createElement('a'); downloadLink.style.display = 'none'; // Hide the anchor element
// Extract filename from URL const url = arr[2]; // Assuming arr[2] contains the PDF file URL const filename = url.split('/').pop(); // Extract filename from URL
// Set the download attribute and href for the PDF file downloadLink.download = filename; // Set the filename downloadLink.href = url; // Set the PDF file URL
// Append the anchor element to the body document.body.appendChild(downloadLink);
// Trigger a click on the anchor to initiate the download downloadLink.click();
// Remove the anchor element from the body document.body.removeChild(downloadLink); });