更改大小磁贴 SCSS

Change size tiles SCSS

提问人:Panpan 提问时间:11/11/2023 更新时间:11/11/2023 访问量:26

问:

我对 html 和 CSS 很陌生,但在基于此模板制作网页时,我学到了一些东西。我想通过将瓷砖的 f orm 更改为矩形而不是正方形来增强效果,因此在使用小屏幕时看起来更好。

这些是我认为相关的代码行:

  • 这是在主 .css 文件中。
* Tiles */

.tiles {
    display: -moz-flex;
    display: -webkit-flex;
    display: -ms-flex;
    display: flex;
    -moz-flex-wrap: wrap;
    -webkit-flex-wrap: wrap;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    position: relative;
    margin: -2.5em 0 0 -2.5em;
}

    .tiles article {
        -moz-transition: -moz-transform 0.5s ease, opacity 0.5s ease;
        -webkit-transition: -webkit-transform 0.5s ease, opacity 0.5s ease;
        -ms-transition: -ms-transform 0.5s ease, opacity 0.5s ease;
        transition: transform 0.5s ease, opacity 0.5s ease;
        position: relative;
        width: calc(33.33333% - 2.5em);
        margin: 2.5em 0 0 2.5em;
    }

        .tiles article > .image {
            -moz-transition: -moz-transform 0.5s ease;
            -webkit-transition: -webkit-transform 0.5s ease;
            -ms-transition: -ms-transform 0.5s ease;
            transition: transform 0.5s ease;
            position: relative;
            display: block;
            width: 100%;
            border-radius: 4px;
            overflow: hidden;
        }

            .tiles article > .image img {
                display: block;
                width: 100%;
            }

            .tiles article > .image:before {
                -moz-pointer-events: none;
                -webkit-pointer-events: none;
                -ms-pointer-events: none;
                pointer-events: none;
                -moz-transition: background-color 0.5s ease, opacity 0.5s ease;
                -webkit-transition: background-color 0.5s ease, opacity 0.5s ease;
                -ms-transition: background-color 0.5s ease, opacity 0.5s ease;
                transition: background-color 0.5s ease, opacity 0.5s ease;
                content: '';
                display: block;
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                opacity: 1.0;
                z-index: 1;
                opacity: 0.8;
            }

            .tiles article > .image:after {
                -moz-pointer-events: none;
                -webkit-pointer-events: none;
                -ms-pointer-events: none;
                pointer-events: none;
                -moz-transition: opacity 0.5s ease;
                -webkit-transition: opacity 0.5s ease;
                -ms-transition: opacity 0.5s ease;
                transition: opacity 0.5s ease;
                content: '';
                display: block;
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cstyle%3Eline %7B stroke-width: 0.25px%3B stroke: %23ffffff%3B %7D%3C/style%3E%3Cline x1='0' y1='0' x2='100' y2='100' /%3E%3Cline x1='100' y1='0' x2='0' y2='100' /%3E%3C/svg%3E");
                background-position: center;
                background-repeat: no-repeat;
                background-size: 100% 100%;
                opacity: 0.25;
                z-index: 2;
            }

        .tiles article > a {
            display: -moz-flex;
            display: -webkit-flex;
            display: -ms-flex;
            display: flex;
            -moz-flex-direction: column;
            -webkit-flex-direction: column;
            -ms-flex-direction: column;
            flex-direction: column;
            -moz-align-items: center;
            -webkit-align-items: center;
            -ms-align-items: center;
            align-items: center;
            -moz-justify-content: flex-start;
            -webkit-justify-content: flex-start;
            -ms-justify-content: flex-start;
            justify-content: flex-start;
            -moz-transition: background-color 0.5s ease, -moz-transform 0.5s ease;
            -webkit-transition: background-color 0.5s ease, -webkit-transform 0.5s ease;
            -ms-transition: background-color 0.5s ease, -ms-transform 0.5s ease;
            transition: background-color 0.5s ease, transform 0.5s ease;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            padding: 1em;
            border-radius: 4px;
            border-bottom: 0;
            color: #314F00;
            text-align: centre;
            text-decoration: none;
            z-index: 3;
        }

            .tiles article > a > :last-child {
                margin: 0;
            }

            .tiles article > a:hover {
                color: #ffffff !important;
            }

            .tiles article > a h2 {
                margin: 0;
            }

            .tiles article > a .content {
                -moz-transition: max-height 0.5s ease, opacity 0.5s ease;
                -webkit-transition: max-height 0.5s ease, opacity 0.5s ease;
                -ms-transition: max-height 0.5s ease, opacity 0.5s ease;
                transition: max-height 0.5s ease, opacity 0.5s ease;
                width: 100%;
                max-height: 0;
                line-height: 1.5;
                margin-top: 0.35em;
                opacity: 0;
            }

                .tiles article > a .content > :last-child {
                    margin-bottom: 0;
                }

        .tiles article.style1 > .image:before {
            /* background-color: #f2849e; */
            background-image:url(images\one-man-tent.jpg);
        }

        .tiles article.style2 > .image:before {
            /*background-color: #7ecaf6;*/
            background-image:url(images\two-man-tent.jpg);
        }

        .tiles article.style3 > .image:before {
            /*background-color: #7bd0c1;*/
            background-image:url(images\group-tent.jpg);
        }

        .tiles article.style4 > .image:before {
            /*background-color: #c75b9b;*/
            background-image:url(images\camping-gear.jpg);
        }

        .tiles article.style5 > .image:before {
            /*background-color: #ae85ca;*/
            background-image:url(images\camping-checklist.jpg);
        }

        .tiles article.style6 > .image:before {
            /*background-color: #8499e7;*/
            background-image:url(images\campsites.jpg);
        }

        body:not(.is-touch) .tiles article:hover > .image {
            -moz-transform: scale(1.1);
            -webkit-transform: scale(1.1);
            -ms-transform: scale(1.1);
            transform: scale(1.1);
        }

            body:not(.is-touch) .tiles article:hover > .image:before {
                background-color: #333333;
                opacity: 0.35;
            }

            body:not(.is-touch) .tiles article:hover > .image:after {
                opacity: 0;
            }

        body:not(.is-touch) .tiles article:hover .content {
            max-height: 15em;
            opacity: 1;
        }

    * + .tiles {
        margin-top: 2em;
    }

    body.is-loading .tiles article {
        -moz-transform: scale(0.9);
        -webkit-transform: scale(0.9);
        -ms-transform: scale(0.9);
        transform: scale(0.9);
        opacity: 0;
    }

    body.is-touch .tiles article .content {
        max-height: 15em;
        opacity: 1;
    }

    @media screen and (max-width: 1280px) {

        .tiles {
            margin: -1.25em 0 0 -1.25em;
        }

            .tiles article {
                width: calc(33.33333% - 1.25em);
                margin: 1.25em 0 0 1.25em;
            }

    }

    @media screen and (max-width: 980px) {

        .tiles {
            margin: -2.5em 0 0 -2.5em;
        }

            .tiles article {
                width: calc(50% - 2.5em);
                margin: 2.5em 0 0 2.5em;
            }

    }

    @media screen and (max-width: 736px) {

        .tiles {
            margin: -1.25em 0 0 -1.25em;
        }

            .tiles article {
                width: calc(50% - 1.25em);
                margin: 1.25em 0 0 1.25em;
            }

                .tiles article:hover > .image {
                    -moz-transform: scale(1.0);
                    -webkit-transform: scale(1.0);
                    -ms-transform: scale(1.0);
                    transform: scale(1.0);
                }

    }

    @media screen and (max-width: 480px) {

        .tiles {
            margin: 0;
        }

            .tiles article {
                width: 100%;
                margin: 1.25em 0 0 0;
            }

    }
  • 这是特定的 tiles.scss 文件:
.tiles {
    $gutter: _size(gutter);
    $duration: 0.5s;
    $ease: 'ease';

    @include vendor('display', 'flex');
    @include vendor('flex-wrap', 'wrap');
    postiion: relative;
    margin: ($gutter * -1) 0 0 ($gutter * -1);

    article {
        @include vendor('transition', (
            'transform #{$duration} #{$ease}',
            'opacity #{$duration} #{$ease}'
        ));
        position: relative;
        width: calc(#{(100% / 3)} - #{$gutter * 1});
        margin: $gutter 0 0 $gutter;

        > .image {
            @include vendor('transition', 'transform #{$duration} #{$ease}');
            position: relative;
            display: block;
            width: 100%;
            border-radius: _size(border-radius);
            overflow: hidden;

            img {
                display: block;
                width: 100%;
            }

            &:before {
                @include vendor('pointer-events', 'none');
                @include vendor('transition', (
                    'background-color #{$duration} #{$ease}',
                    'opacity #{$duration} #{$ease}'
                ));
                content: '';
                display: block;
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                opacity: 1.0;
                z-index: 1;
                opacity: 0.8;
            }

            &:after {
                @include vendor('pointer-events', 'none');
                @include vendor('transition', 'opacity #{$duration} #{$ease}');
                content: '';
                display: block;
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background-image: svg-url('<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100" preserveAspectRatio="none"><style>line { stroke-width: 0.25px; stroke: #ffffff; }</style><line x1="0" y1="0" x2="100" y2="100" /><line x1="100" y1="0" x2="0" y2="100" /></svg>');
                background-position: center;
                background-repeat: no-repeat;
                background-size: 100% 100%;
                opacity: 0.25;
                z-index: 2;
            }
        }

        > a {
            @include vendor('display', 'flex');
            @include vendor('flex-direction', 'column');
            @include vendor('align-items', 'center');
            @include vendor('justify-content', 'center');
            @include vendor('transition', (
                'background-color #{$duration} #{$ease}',
                'transform #{$duration} #{$ease}'
            ));
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            padding: 1em;
            border-radius: _size(border-radius);
            border-bottom: 0;
            color: _palette(fg-accent);
            text-align: center;
            text-decoration: none;
            z-index: 3;

            > :last-child {
                margin: 0;
            }

            &:hover {
                color: _palette(fg-accent) !important;
            }

            h2 {
                margin: 0;
            }

            .content {
                @include vendor('transition', (
                    'max-height #{$duration} #{$ease}',
                    'opacity #{$duration} #{$ease}'
                ));
                width: 100%;
                max-height: 0;
                line-height: 1.5;
                margin-top: 0.35em;
                opacity: 0;

                > :last-child {
                    margin-bottom: 0;
                }
            }
        }

        &.style1 {
            > .image:before {
                background-color: _palette(accent1);
            }
        }

        &.style2 {
            > .image:before {
                background-color: _palette(accent2);
            }
        }

        &.style3 {
            > .image:before {
                background-color: _palette(accent3);
            }
        }

        &.style4 {
            > .image:before {
                background-color: _palette(accent4);
            }
        }

        &.style5 {
            > .image:before {
                background-color: _palette(accent5);
            }
        }

        &.style6 {
            > .image:before {
                background-color: _palette(accent6);
            }
        }

        body:not(.is-touch) & {
            &:hover {
                > .image {
                    @include vendor('transform', 'scale(1.1)');

                    &:before {
                        background-color: _palette(bg-accent);
                        opacity: 0.35;
                    }

                    &:after {
                        opacity: 0;
                    }
                }

                .content {
                    max-height: 15em;
                    opacity: 1;
                }
            }
        }
    }

    * + & {
        margin-top: _size(element-margin);
    }

    body.is-loading & {
        article {
            @include vendor('transform', 'scale(0.9)');
            opacity: 0;
        }
    }

    body.is-touch & {
        article {
            .content {
                max-height: 15em;
                opacity: 1;
            }
        }
    }

    @include breakpoint(large) {
        $gutter: _size(gutter) * 0.5;

        margin: ($gutter * -1) 0 0 ($gutter * -1);

        article {
            width: calc(#{(100% / 3)} - #{$gutter * 1});
            margin: $gutter 0 0 $gutter;
        }
    }

    @include breakpoint(medium) {
        $gutter: _size(gutter);

        margin: ($gutter * -1) 0 0 ($gutter * -1);

        article {
            width: calc(#{(100% / 2)} - #{$gutter * 1});
            margin: $gutter 0 0 $gutter;
        }
    }

    @include breakpoint(small) {
        $gutter: _size(gutter) * 0.5;

        margin: ($gutter * -1) 0 0 ($gutter * -1);

        article {
            width: calc(#{(100% / 2)} - #{$gutter * 1});
            margin: $gutter 0 0 $gutter;

            &:hover {
                > .image {
                    @include vendor('transform', 'scale(1.0)');
                }
            }
        }
    }

    @include breakpoint(xsmall) {
        $gutter: _size(gutter) * 0.5;

        margin: 0;

        article {
            width: 100%;
            margin: $gutter 0 0 0;
        }
    }
}
  • 我试图在main.css中修改.tiles文章,添加高度命令,但没有任何反应。

  • 我通过在 .tiles 文章 .image 中添加 50% 的高度命令并向上移动文本来获得矩形形状,但方形平铺形状仍然存在,第二行中的新平铺很远。

  • 我想将瓷砖周围的“盒子”减少到其高度的一半,但这些矩形瓷砖将堆积为默认的正方形瓷砖。

提前感谢您的帮助。

HTML CSS 模板 SASS

评论


答: 暂无答案