css - 如何使用 nextjs 更改图像大小
问题描述
我在引导卡中有一个使用next/image
. 我希望图像更小,而不是填满卡片的整个顶部。说大约是原始大小的 60%。我尝试将图像包装在 div 容器中并添加了一些 css,但对更改大小没有任何影响。
import Image from 'next/image'
import logo from '../public/delta-logo.png'
import { Card, Button } from 'react-bootstrap'
import styles from './landing.module.css'
import 'bootstrap/dist/css/bootstrap.min.css'
export default function LandingPage() {
return (
<Card style={{ width: '18rem' }}>
<Image src={logo} alt='Picture of our Logo' />
<Card.Body className='text-center'>
<Card.Title>Card Title</Card.Title>
<Card.Text>
Some quick example text to build on the card title and make up the
bulk of the card's content.
</Card.Text>
<Button variant='primary'>Go somewhere</Button>
</Card.Body>
</Card>
)
}
解决方案
您可以在like中使用width
和height
属性Image
<Image src={logo} alt='Picture of our Logo' width={500} height={500}/>
或者
在您的 CSS 文件中为您的图像定义一个类,并将其添加className
到您的Image
标签中,例如
<Image src={logo} alt='Picture of our Logo' className='yourClass'/>
推荐阅读
- php - realpath() 不显示 realpath GitLab ci runner
- node.js - 从詹金斯无休止地加载 sudo npm
- sql - 如何在sql中组合日期和时间字段?
- android - 调用 goBack 后相对链接不起作用
- web-scraping - 为什么我的 html 请求不包含导航器上显示的所有元素?
- java - 如何使用 junit mockito 覆盖匿名类覆盖的方法
- javascript - 将 HTML 添加到 Chrome 扩展中的 DOM 后,通过单击浏览器操作删除 HTML?
- php - Trumbowyg:如何使用 Jquery .html() 或 .text() 放置文本
- android - 如何使用 DiffUtil 更新另一个 RecyclerView 中的 RecyclerView 适配器
- javascript - 如何在 location.back 之后重新加载上一页中的当前页面(不是 SPA)