gpt4 book ai didi

sass - 使用 Sass 以可重用的方式设计一组特定的输入类型

转载 作者:行者123 更新时间:2023-12-01 04:35:43 24 4
gpt4 key购买 nike

我想要一个 mixin 函数,它返回 HTML5 输入类型的列表。我想在一个地方管理这个,随着新类型的出现,改变函数,而不是代码中其他地方的所有地方。

问题似乎是 mixin 不是为了返回可以在 CSS 中的花括号之外使用的字符串。这是我的 mixin 示例(当前返回错误)以及我将如何使用它:

/* 
* Set all the up-and-coming input text types here for easier reference
* Does not include types that are not meant to be displayed full width, such as:
type=number, type=range, type=date, type=color
*/
@mixin input_text_types( $focus:false ) {
@if $focus {
@return #{input[type=text]:focus, input[type=password]:focus, input[type=search]:focus, input[type=email]:focus, input[type=url]:focus, input[type=tel]:focus};
} @else {
@return #{input[type=text], input[type=password], input[type=search], input[type=email], input[type=url], input[type=tel]};
}
}

正在使用:
@include input_text_types() {
width: 80%;
}

我得到的错误就像 error sass/style.scss (Line 134 of sass/_functions.scss: Invalid CSS after "...@return #{input": expected "}", was "[type=text]:foc...")
我尝试使用和不使用 @return 来格式化输出指令,并以不同的方式将字符串值括起来(在引号中,在单引号中,在带有散列的花括号中)。以前有人尝试过做这样的事情吗?

最佳答案

使用变量来包含选择器可能会更好地解决您的问题。通过使用 mixin,您将失去将其与类似元素链接的能力。

$form-input-text: 'input[type="text"], input[type="password"], input[type="search"], input[type="email"], input[type="tel"], input[type="url"]';
$form-input-buttons: 'input[type="submit"], input[type="reset"], input[type="button"], button';
$form-input-dates: 'input[type^="date"], input[type="month"], input[type="week"], input[type="time"]';
$form-input-not-radio: 'input:not([type="radio"]):not([type="checkbox"])';

#{$form-input-text}, textarea {
@include border-radius(.25em);
border: $form-input-border;
}

#{$form-input-text}, textarea, input[type="file"] {
width: $form-input-width;
max-width: 100%;
-webkit-appearance: textfield
}

#{$form-input-buttons} {
padding: .25em .5em;
}

关于sass - 使用 Sass 以可重用的方式设计一组特定的输入类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17369600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com