首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在较少的混入中仅更改一个参数?

如何在较少的混入中仅更改一个参数?
EN

Stack Overflow用户
提问于 2020-12-10 23:27:09
回答 2查看 73关注 0票数 0

我想在Less中使用多态混合,我已经为我的参数设置了默认值,考虑到这两个多态混合有不同数量的参数,当对不同的元素使用混合时,我想知道是否我只能分配一个特定的参数值,而让其他的保持默认值。例如,这里我有两个多态混入,.testMixin.,.box_1.box_2分别使用它们,没有给出.box_1的混入的参数,编译后的CSS包含了两个具有给定默认值的混入,但我将唯一的参数10赋给了.box_2的混入,它将两个混入的第一个参数设置为10,并保留了其他参数值,如果有的话。以下是问题:首先,我应该怎么做才能将第二个混合的第二个参数赋给一个值,同时保持第一个和第三个参数的默认值?其次,我如何才能只使用其中一种多态混合?关于多态,混入是根据给定的参数数量使用的。

代码语言:javascript
复制
.testMix(@f-size:2){
  font-size: (@f-size * 10px);
}

.testMix(@h:300, @s:70%, @l:50%){
  color: hsl(@h, @s, @l);
}

.box{
  &_1{
    .testMix();
  }
  &_2{
    .testMix(10);
  //  How to assign only one argument, e.g. only the second argument of first mixin
  }
}

EN

回答 2

Stack Overflow用户

发布于 2020-12-11 00:21:23

如果我没理解错的话,需要的是让图像变得可缩放,但保持在它的div中-而不是从填充中渗出。

如果您在容器上使用边距,而不是在图像上填充,则img会稍微缩放,但会停留在其元素内。

注意:你可能会考虑object-fit:在图像上包含或覆盖,而不是宽度/高度100%,这样它就不会失真,当然这取决于你的使用情况。

代码语言:javascript
复制
*,
    *::before,
    *::after{
        padding: 0;
        margin: 0;
        box-sizing: border-box;
    }
    .container{
        position: relative;
        width: calc(33.33334% - 8px);
        height: 300px;
/*        border: 1px solid #000;*/
        float: right;
        overflow: hidden;
        margin: 0 8px 0 0;
    }
    .container::after{
        position: absolute;
        top: 100%;
        left: 0;
        content:"";
        width: 100%
        height: 100%;
        background-color: rgba(0,0,0,0.55);
    }
    .container:hover::after{
        top: 0;
    }
    .container:nth-child(1){
        margin-right: 0;
    }
    .container img{
        width: 100%;
        height: 100%;
        transition: 200ms;
    }
    .container:hover img{
        transform: scale(1.3);
    }
代码语言:javascript
复制
<div class="container"> <img src="https://i.stack.imgur.com/gWzPe.jpg" alt=""> </div>
    <div class="container"> <img src="https://i.stack.imgur.com/gWzPe.jpg.jpg" alt=""> </div>
    <div class="container"> <img src="https://i.stack.imgur.com/gWzPe.jpg" alt=""> </div>

票数 2
EN

Stack Overflow用户

发布于 2020-12-10 23:56:44

你的问题有点含糊。我认为您希望放大图像的一部分,而不更改div / image的大小,另一种实现方法是将图像设置为div的背景,然后按如下所示调整它们的大小

代码语言:javascript
复制
*,
    *::before,
    *::after{
        padding: 0;
        margin: 0;
        box-sizing: border-box;
    }
    .container{
        position: relative;
        width: 30%;
        height: 200px;
        float: right;
        margin: 1%;
        overflow: hidden;
        background-image: url("https://images.ctfassets.net/hrltx12pl8hq/6jVTOtduUgVhFTP1h0MqmX/009e866bd1a3f8a965028874c58b2109/shutterstock_547563823.jpg?fit=fill&w=800&h=300");
        background-size: 100% 100%;
        background-position: center;
        transition: background-size 200ms;
    }
    .container::after{
        position: absolute;
        top: 100%;
        left: 0;
        content:"";
        width: calc(100% - 8px);
        height: 100%;
        background-color: rgba(0,0,0,0.55);
        padding: 0 8px 0 0px;
    }
    .container:hover::after{
        top: 0;
}

    .container:hover {
        background-size: 150% 150%;
    }
代码语言:javascript
复制
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
    <div class="container"> </div>
    <div class="container">  </div>
    <div class="container"> </div>
</body>
</html>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65237433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档