news/app/components/body/ImageGridSection.tsx

109 lines
4.0 KiB
TypeScript
Raw Normal View History

2025-11-18 17:13:49 +08:00
import { CarouselDemo } from "@/components/Carousel";
const ImageGridSection = () => {
2025-11-18 20:45:54 +08:00
2025-11-18 17:13:49 +08:00
const elements = [
"/images/carousel-1.jpg",
<CarouselDemo />,
"/images/carousel-2.jpg",
"/images/carousel-3.jpg"
];
2025-11-19 08:22:08 +08:00
{/*
2 + 2
*/}
2025-11-18 17:13:49 +08:00
const listItems = [
'新闻标题一:重要政策发布',
'新闻标题二:经济数据稳步回升',
'新闻标题三:科技创新成果显著',
'新闻标题四:民生工程持续推进',
'新闻标题五:国际交流合作深化'
];
return (
<div style={{
display: 'flex',
gap: '24px',
padding: '20px',
maxWidth: '1200px',
margin: '0 auto',
fontFamily: 'Microsoft YaHei, sans-serif'
}}>
2025-11-19 08:22:08 +08:00
{/* 3 + 1 2x2
*/}
2025-11-18 17:13:49 +08:00
<div style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr',
gridTemplateRows: '1fr 1fr',
gap: '16px',
width: '600px',
height: '450px',
boxSizing: 'border-box' // 确保padding和border不会增加元素的实际宽度和高度
}}>
2025-11-19 08:22:08 +08:00
2025-11-18 17:13:49 +08:00
{elements.map((element, index) => (
<div
key={index}
style={{
borderRadius: '8px',
overflow: 'hidden',
boxShadow: '0 4px 10px rgba(0,0,0,0.1)',
display: 'flex',
2025-11-19 08:22:08 +08:00
alignItems: 'stretch'
2025-11-18 17:13:49 +08:00
}}
>
{typeof element === 'string' ? (
<img
src={element}
alt={`图片 ${index + 1}`}
style={{
width: '100%',
height: '100%',
objectFit: 'cover',
display: 'block'
}}
/>
) : (
2025-11-19 08:22:08 +08:00
element // 占据剩余空间 最小宽度;与左侧高度对齐;垂直布局;内容在垂直方向均匀分布
// 背景色、圆角、阴影、内边距 防撑大
2025-11-18 17:13:49 +08:00
)}
</div>
))}
</div>
<div style={{
flex: 1,
minWidth: '300px',
2025-11-19 08:22:08 +08:00
height: '450px',
2025-11-18 17:13:49 +08:00
display: 'flex',
flexDirection: 'column',
2025-11-19 08:22:08 +08:00
justifyContent: 'space-between',
2025-11-18 17:13:49 +08:00
background: '#f9f9f9',
borderRadius: '8px',
boxShadow: '0 2px 8px rgba(0,0,0,0.1)',
padding: '16px',
boxSizing: 'border-box'
}}>
<ul style={{
listStyle: 'none',
padding: 0,
2025-11-19 08:22:08 +08:00
flexGrow: 1,
overflowY: 'auto' // 当 内 容超出时启用滚动条 填满剩余 文间
2025-11-18 17:13:49 +08:00
}}>
{listItems.map((item, index) => (
<li
key={index}
style={{
marginBottom: '12px',
color: '#333',
fontSize: '16px'
}}
>
<span style={{ color: '#c00', marginRight: '8px' }}></span>
{item}
</li>
))}
</ul>
</div>
</div>
);
};
export default ImageGridSection;