Files
FlexPhoto/style.css

98 lines
3.0 KiB
CSS
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
:root{
--gap: 10px; /* 把间距也抽成变量,方便统一修改 */
}
.flexphoto {
display: flex;
gap: var(--gap); /* 使用变量统一控制间距 */
flex-wrap: wrap;
padding: 0;
margin: 10px 0;
/* 缩略图统一裁切比例:每排高度一致,改这里即可(如 3 / 2、16 / 9、1 / 1) */
--flexphoto-ratio: 4 / 3;
}
.flexphoto figure {
margin: 0 !important;
flex: 1;
min-width: 0;
display: flex; /* 让内部的 a 撑满整块,整行高度由 flex 拉伸统一 */
aspect-ratio: var(--flexphoto-ratio); /* 统一比例,图片按 cover 裁切 */
}
/* 点击放大的触发层(Fancybox 绑定在 a.flexphoto-link 上) */
.flexphoto .flexphoto-link,
.flexphoto .flexphoto-link:hover {
display: flex; /* 同时作为 img 的容器,让 img 拉伸填满 */
flex: 1;
min-width: 0;
cursor: zoom-in;
text-decoration: none; /* 屏蔽主题 a:hover 的点状下划线 */
}
.flexphoto figure img{
height: 100%;
width: 100%;
object-fit: cover;
max-height: 100%;
}
.flexphoto.diycol figure {
flex: none;
/* 正确计算宽度:100%均分 - 分摊的间距 */
width: calc((100% / var(--col-num)) - (var(--gap) * (var(--col-num) - 1) / var(--col-num)));
/* 关键:给figure设置最小高度,避免img的height:100%无参考 */
}
.flexphoto.diycol{
--col-num: var(--desktop-col, 4);
}
/* 平板端(≤1024px):读取data-tablet-col */
@media (max-width: 1024px) {
.flexphoto.diycol {
--col-num: var(--tablet-col, 3);
}
}
/* 手机端(≤768px):读取data-mobile-col */
@media (max-width: 768px) {
.flexphoto.diycol {
--col-num: var(--mobile-col, 2);
}
}
/* ------------------------------------------------------------------
* 兼容层:任何「包了一层再放图」的插件(如七牛的 EXIF 浮层容器)
* 把包裹元素当作 figure 的同级替身,flex 子项语义、列宽、比例与裁切
* 全部下沉到包裹层,内部的 figure 退化为撑满即可。
* 这样无论包裹层在外(.flexphoto 的直接子项)还是在内(<a> 里面),
* 横排都不会被顶掉。
* ------------------------------------------------------------------ */
.flexphoto > .qiniu-exif-container {
display: flex;
flex: 1;
min-width: 0;
aspect-ratio: var(--flexphoto-ratio);
overflow: hidden; /* 与 figure 的封面裁切保持一致的圆角/裁切观感 */
border-radius: 10px;
}
.flexphoto.diycol > .qiniu-exif-container {
flex: none;
width: calc((100% / var(--col-num)) - (var(--gap) * (var(--col-num) - 1) / var(--col-num)));
}
/* 包裹层已经承担了比例,内部 figure 不能再按 4:3 二次约束,否则高度会被压缩 */
.flexphoto > .qiniu-exif-container > figure {
flex: 1;
width: auto;
min-width: 0;
aspect-ratio: auto;
margin: 0;
}
/* 包裹层落在 <a> 内部的情况:让 a 与包裹层都撑满格子 */
.flexphoto .flexphoto-link > .qiniu-exif-container {
display: flex;
flex: 1;
min-width: 0;
overflow: hidden;
border-radius: 10px;
}
.flexphoto .qiniu-exif-container img {
height: 100%;
width: 100%;
object-fit: cover;
max-height: 100%;
}