How to scale an image roughly? #6813
-
The only way I know by far is setting |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hello @madjxatw, /* Scale to fit the page */
/* Small images will become very blurry */
/* Not recommended */
.md-content__inner img {
width: 100%;
}
/* Scale to fit the page with constraints */
/* Smaller images will be min 25% of the width, so not as blurry */
/* Bigger images will be max 90% of the width, better for centring (?) */
.md-content__inner img {
min-width: 25%;
max-width: 90%;
}
/* Center the images */
.md-content__inner img {
display: block;
margin: 0 auto;
}
/* Add outline to make them pop */
.md-content__inner img {
outline: 1px solid var(--md-accent-fg-color);
} Example docs: scale-images.zip |
Beta Was this translation helpful? Give feedback.
After looking at: https://stackoverflow.com/questions/63392775/is-there-a-way-to-set-the-image-scaling-method-in-rest-sphinx
and reading the first answer,
I think scale does use the percentage to calculate the pixel dimensions and then sets a static pixel width with CSS.
So it doesn't really scale with the viewport later, because it's not 50% of the viewport width, but 50% of the actual image size 🧐
So perhaps this answer will help with the transform:
https://stackoverflow.com/questions/8397049/how-can-i-resize-an-image-to-a-percentage-of-itself-with-css
@alexvoss Setting width with percentage with attribute list probably won't work, as the value should be pixels, but I don't know for sure
…