summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorSangeeth Sudheer <git@sangeeth.dev>2024-11-06 04:20:17 +0530
committerSangeeth Sudheer <git@sangeeth.dev>2024-11-17 17:21:02 +0530
commit97936e3070c707fd2db6aa1c3db092aa159563f2 (patch)
tree80978b106d16221e1cc7da3a1f857c808c634d53 /assets
parentf025f972e0b1ffb8df288be632bb3c34a58b66e8 (diff)
Add width and height attrs for local images
Image render hook now computes width/height of local images and adds them as attributes. This patch also adds relevant CSS changes to prevent stretchy images. The main reason for this change is to avoid content shifts when images load. Without providing width/height, browser doesn't have info to know the aspect ratio to reserve some space until the image loads. With this change, browser knows the intrinsic size and aspect-ratio to reserve space and avoid content shifts in the page. I believe this also fixes an issue I face in Safari where sometimes, an image below the fold wouldn't load and thus have zero height because it has loading="lazy". To avoid images getting stretched and images overflow/filling the entire screen when their intrinsic size is larger than the container size, I've added some CSS. A configurable `max-height` is present which is used for `figure img` elements. This especially helps when you have tall images like mobile screenshots.
Diffstat (limited to 'assets')
-rw-r--r--assets/css/main.css17
-rw-r--r--assets/css/vars.css1
2 files changed, 17 insertions, 1 deletions
diff --git a/assets/css/main.css b/assets/css/main.css
index d95ca04..57d9066 100644
--- a/assets/css/main.css
+++ b/assets/css/main.css
@@ -394,6 +394,20 @@ footer a {
/* images */
+figure > div {
+ width: 100%;
+ display: flex;
+ justify-content: center;
+}
+
+figure img {
+ max-width: 100%;
+ max-height: var(--figure-img-max-height);
+ width: auto;
+ height: auto;
+ margin-inline: auto;
+}
+
.dark .img-light {
display: none !important;
}
@@ -419,6 +433,7 @@ footer a {
}
.img-full img {
+ height: auto;
width: 100vw !important;
max-width: 100vw !important;
}
@@ -527,4 +542,4 @@ blockquote {
blockquote p {
margin-left: 1rem;
margin-right: 1rem;
-} \ No newline at end of file
+}
diff --git a/assets/css/vars.css b/assets/css/vars.css
index 837acf7..9a6584f 100644
--- a/assets/css/vars.css
+++ b/assets/css/vars.css
@@ -53,6 +53,7 @@
/* Content */
--content-height: calc(100vh - var(--footer-height));
+ --figure-img-max-height: 500px;
/* Tables */
--table-cell-padding: .5rem;