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

Use width instead of maxWidth after resizing image #8683

Closed
3 tasks done
iamqiz opened this issue Jul 5, 2023 · 28 comments
Closed
3 tasks done

Use width instead of maxWidth after resizing image #8683

iamqiz opened this issue Jul 5, 2023 · 28 comments
Assignees
Milestone

Comments

@iamqiz
Copy link
Contributor

iamqiz commented Jul 5, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Can the issue be reproduced with the default theme (daylight/midnight)?

  • I was able to reproduce the issue with the default theme

Could the issue be due to extensions?

  • I've ruled out the possibility that the extension is causing the problem.

Describe the problem

在使用下面的css代码片段限制图片最大宽度时, 发现不会生效,但是给元素手动加上 style属性之后才能生效(即便为空值)

.protyle-wysiwyg span.img[data-type="img"] {
    max-width: 30%;
}

元素如下
Snipaste_环境返回_2023-07-05__09-37-50

所以建议给这个元素默认加上 style属性,空值即可,
顺便请教一下,为什么加个style之后才会生效?

Expected result

1

Screenshot or screen recording presentation

No response

Version environment

- Version:  v2.9.4
- Operating System: win10
- Browser (if used):

Log file

1

More information

No response

@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 5, 2023

@88250 另外我建议思源直接支持在设置里设置图片的最大默认宽度(实际值或百分比), 这个限制图片宽度的需求有很多人提了,之前我用代码片段实现,最近发现失效了, 所以官方能支持的话就省事了

@88250
Copy link
Member

88250 commented Jul 5, 2023

默认是没有 style 属性的,只有手动调整过图片大小才会有。

@88250
Copy link
Member

88250 commented Jul 5, 2023

另外,如果支持设置默认宽度,不同设备上应该无法自适应。之前考虑过 #5097

@88250 88250 closed this as completed Jul 5, 2023
@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 5, 2023

默认是没有 style 属性的,只有手动调整过图片大小才会有。

我知道, 所以我说:

Snipaste_环境返回_2023-07-05__13-49-41

@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 5, 2023

默认宽度

这个可以弄成本地设置, 不同设备间相互独立

@chenshinshi
Copy link

@88250 另外我建议思源直接支持在设置里设置图片的最大默认宽度(实际值或百分比), 这个限制图片宽度的需求有很多人提了,之前我用代码片段实现,最近发现失效了, 所以官方能支持的话就省事了

没失效啊我还可以限制默认最大宽度。

@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 5, 2023

@chenshinshi 代码片段发一下我试试

@chenshinshi
Copy link

@chenshinshi 代码片段发一下我试试

.b3-typography img, .protyle-wysiwyg img {
max-width: 400px;
margin: 0 auto;
}

@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 5, 2023

@chenshinshi 代码片段发一下我试试

.b3-typography img, .protyle-wysiwyg img { max-width: 400px; margin: 0 auto; }

@chenshinshi 这个是直接作用于 img元素的,我之前试过, 如果你把 400px 换成百分比,比如30% ,就会出现问题,如下图,图片两边会出现空白
Snipaste_环境返回_2023-07-05__19-11-56
因此,如果想使用百分比限制宽度,需要针对 img外部元素,即 .protyle-wysiwyg span.img[data-type="img"]

@chenshinshi
Copy link

@chenshinshi 代码片段发一下我试试

.b3-typography img, .protyle-wysiwyg img { max-width: 400px; margin: 0 auto; }

@chenshinshi 这个是直接作用于 img元素的,我之前试过, 如果你把 400px 换成百分比,比如30% ,就会出现问题,如下图,图片两边会出现空白
Snipaste_环境返回_2023-07-05__19-11-56
因此,如果想使用百分比限制宽度,需要针对 img外部元素,即 .protyle-wysiwyg span.img[data-type="img"]

我不太清楚你想达到的效果,我使用这段代码还搭配了图片居左等设置。

@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 5, 2023

@chenshinshi 你把400px换成 百分比, 就能发现问题了
想要的效果是图片宽度随文档宽度缩放而缩放,而不是固定的宽度,比如400px

@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 5, 2023

@88250

@88250
Copy link
Member

88250 commented Jul 5, 2023

@Vanessa219

@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 10, 2023

@Vanessa219 @88250

1 similar comment
@iamqiz
Copy link
Contributor Author

iamqiz commented Jul 13, 2023

@Vanessa219 @88250

@Vanessa219
Copy link
Member

image

@pisceswb
Copy link

pisceswb commented Aug 7, 2023

@chenshinshi 你把400px换成 百分比, 就能发现问题了 想要的效果是图片宽度随文档宽度缩放而缩放,而不是固定的宽度,比如400px

请问最终是能实现这样设置了吗?怎样设置?

@iamqiz
Copy link
Contributor Author

iamqiz commented Aug 7, 2023

@pisceswb 可以的,下面代码片段是百分比宽度的,把30%改成111px就是固定宽度了;

.protyle-wysiwyg span.img[data-type="img"]{
max-width: 30%;
display:inline-block;
}

-----更新,
把max-width改成width,即可适用于新版思源

@pisceswb
Copy link

一直不明白,为什么这么多人需求的插入图片后自动调整图片大小的功能咋就怎么也实现不了。。。。

@pisceswb
Copy link

@pisceswb 可以的,下面代码片段是百分比宽度的,把30%改成111px就是固定宽度了;

.protyle-wysiwyg span.img[data-type="img"]{
max-width: 30%;
display:inline-block;
}

感谢回复,不是想限制图片的最大宽度,是想实现插入新图片后,图片的宽度能够默认设置成33%。不用每次都手动调整

@iamqiz
Copy link
Contributor Author

iamqiz commented Aug 26, 2023

@pisceswb 上面的代码就可以实现你的需求,粘贴图片后默认宽度30%,手动缩放后最大宽度能超过30%

@iamqiz
Copy link
Contributor Author

iamqiz commented Aug 26, 2023

@88250 @Vanessa219 手动缩放图片宽度时修改的是元素的max-width属性, 而通过图片右键菜单"宽度"修改的是元素width属性, 能不能统一 一下? 由于这个差异导致我通过代码片段设置图片最大宽度时(设置max-width)不能同时能够手动缩放+图片右键菜单缩放,只能二选一

Vanessa219 added a commit that referenced this issue Aug 27, 2023
@Vanessa219
Copy link
Member

统一为 width,还麻烦看一下是否可以了?

@Vanessa219
Copy link
Member

@pisceswb max-width 改为 width 试试,这个不是每个人都有这样的需求,只能自定义

@Vanessa219 Vanessa219 changed the title 设置图片最大宽度 Use width instead of maxWidth after resizing image Aug 27, 2023
@Vanessa219 Vanessa219 self-assigned this Aug 27, 2023
@Vanessa219 Vanessa219 added this to the 2.10.2 milestone Aug 27, 2023
@Zuoqiu-Yingyi
Copy link
Contributor

@Vanessa219 这会不会造成页面宽度较小时图片无法完整显示❓

@iamqiz
Copy link
Contributor Author

iamqiz commented Aug 27, 2023

@Vanessa219

可以的~

@Vanessa219
Copy link
Member

@Vanessa219 这会不会造成页面宽度较小时图片无法完整显示❓

应该不会,还有个 max-width:100% 的样式

@pisceswb
Copy link

@pisceswb max-width 改为 width 试试,这个不是每个人都有这样的需求,只能自定义

可用了,非常感谢! @Vanessa219 @iamqiz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants