You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Bookdown中移除HTML输出里的图片边框?

移除Bookdown bs4_book模板中图片的边框

方法1:优化自定义CSS选择器(推荐)

bs4_book的默认主题样式优先级高于全局img选择器,需要用更具体的选择器覆盖原有样式:

将style.css中的代码替换为:

/* 针对book容器内的图片移除边框和阴影 */
.book .figure img {
  border: none;
  box-shadow: none;
}

/* 若figure容器本身带边框,一并移除 */
.book .figure {
  border: none;
}

方法2:内联样式快速解决

直接在图片的代码块中添加out.extra参数,为图片设置内联样式:

```{r, fig.align='center', echo=FALSE, out.extra='style="border: none; box-shadow: none;"'}
knitr::include_graphics('./images/Solar panel.jpg')
## 方法3:强制覆盖样式(慎用)
如果前两种方法无效,可使用`!important`强制覆盖所有冲突样式:
```css
img, .img-fluid, .figure {
  border: none !important;
  box-shadow: none !important;
}

重新编译Bookdown文档后,图片边框即可被移除。

内容的提问来源于stack exchange,提问作者Grant Coble-Neal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 00:05:35