Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p 元素中的 img 居中 #87

Closed
zsdycs opened this issue Jun 17, 2020 · 5 comments
Closed

p 元素中的 img 居中 #87

zsdycs opened this issue Jun 17, 2020 · 5 comments

Comments

@zsdycs
Copy link
Contributor

zsdycs commented Jun 17, 2020

hi,@yihui

https://github.com/rbind/yihui/blob/23fe62cdeda1905704fe7db088d3c50ce8ed920e/static/js/center-img.js#L15

我发现这一行不能很好的达到效果(可以用较窄长的图片测试)。

如果要让 img 在 p 中正确居中,建议设置 img:

display: block;
margin: auto;
@yihui
Copy link
Owner

yihui commented Jun 17, 2020

谢谢反馈,不过请参见:yihui/hugo-ivy#6 真是巧了,一周内有两个人分别跟我提起这个问题。

对窄长图片来说,我想不出用 display: blockmargin: auto 居中图片和用我的 JS 办法居中有什么区别,你的窄长的意思是指高度超高吗?对超过父元素宽度的超宽图片也许有区别(尽管我也怀疑)。给个例子看看?

@zsdycs
Copy link
Contributor Author

zsdycs commented Jun 17, 2020

哈,太巧了。😄

这个图片就可以 测试出来效果。

我是在手机上发现这个问题的,在较小宽度显示时,图片居中后左右宽度不一致的问题会比较明显。

@yihui
Copy link
Owner

yihui commented Jun 18, 2020

https://jsfiddle.net/sg45k68p/ 有何区别?

@zsdycs
Copy link
Contributor Author

zsdycs commented Jun 18, 2020

实在抱歉,找到了原因,代码没有问题。

是因为我在 P 开头增加了    作为段落缩进, 转义字符在控制台难以看出来区别。

https://jsfiddle.net/zsdycs/dkf0szcu/

(真相大白)

@yihui
Copy link
Owner

yihui commented Jun 18, 2020

哦,明白了。看样子你已经解决了:zsdycs/lipk.org-hugo@49072d4

我个人不太倾向于同时使用首行缩进和段落间空行。不过这是你自己的审美偏好,自己觉得舒服就行。

@yihui yihui closed this as completed Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants