我想更改网格的第一个“生成”单元格的大小。在 javascript 在其上打印 RSS 信息之前,html 中不存在网格,因此我无法直接定位行或单元格。
注意:第一个元素设置为display:none;
因为它会重复自己。
想要的结果: https: //i.imgur.com/x07Egoz.png
实际网格: https: //codepen.io/jinzagon/pen/JjXMXxo
CSS
body {
margin: 1rem;
display: grid;
background-color:#272d32;
grid-template-columns: repeat(auto-fit, minmax(250px, 250px));
grid-gap: 2rem;
}
img {
max-width: 100%;
box-shadow: 0 0 3px #B0BEC5;
width: 100%;
/* height: 100%;*/
object-fit: cover;
display: block;
}
article {
background: #ECEFF1;
border-radius: 4px;
overflow: hidden;
height: 250px;
font: 12px/1.1 system-ui, sans-serif;
a {
text-decoration: none;
color: #455A64;
&:hover, &:focus {
color: #2196F3;
}
}
h2 {
padding: 1rem 1rem;
margin: 0;
}
}
article:first-of-type {
display:none;
}
JS
const RSS_URL = 'https://cors-anywhere.herokuapp.com/https://fitgirl-repacks.site/feed/';
fetch(RSS_URL)
.then(response => response.text())
.then(str => new window.DOMParser().parseFromString(str, "text/xml"))
.then(data => {
console.log(data);
const items = data.querySelectorAll("item");
let html = ``;
items.forEach(el => {
var image = null;
var encoded = new window.DOMParser().parseFromString(
el.getElementsByTagNameNS("*", "encoded").item(0).innerHTML,
"text/html"
);
// console.log(encoded.querySelectorAll('img').item(0) ? null.src)
if (encoded.querySelector('img') != null) {
image = encoded.querySelector('img').src;
} else {
return true;
}
html += `
<article>
<!--<h2>${el.querySelector("title ").innerHTML}
</h2>
<a href="${el.querySelector("link").innerHTML}" target="_blank" rel="noopener">
</a>-->
<img src="${image}" alt="" />
</article>
`;
});
document.body.insertAdjacentHTML("beforeend", html);
});
慕村225694
胡子哥哥
相关分类