私は次のコードを書いていますが、SASSの可能性を最大限に活用するとこれは短くなる可能性があります。SASを効率的に使用してコードを保存DRY
コード:
&.pos-y-top {
.dropdown-element {
top: 0;
.content-wrapper {
.content, app-dropdown-content {
bottom: 0;
}
}
}
}
&.pos-y-bottom {
.dropdown-element {
bottom: 0;
.content-wrapper {
.content, app-dropdown-content {
top: 0;
}
}
}
}
&.pos-x-left {
.dropdown-element {
right: 0;
.content-wrapper {
.content, app-dropdown-content {
right: 0;
}
}
}
}
&.pos-x-right {
.dropdown-element {
left: 0;
.content-wrapper {
.content, app-dropdown-content {
left: 0;
}
}
}
}
&.pos-x-left.pos-y-bottom {
.dropdown-element {
.content-wrapper {
.content, app-dropdown-content {
transform-origin: top right;
}
}
}
}
&.pos-x-left.pos-y-top {
.dropdown-element {
.content-wrapper {
.content, app-dropdown-content {
transform-origin: bottom right;
}
}
}
}
&.pos-x-right.pos-y-bottom {
.dropdown-element {
.content-wrapper {
.content, app-dropdown-content {
transform-origin: top left;
}
}
}
}
&.pos-x-right.pos-y-top {
.dropdown-element {
.content-wrapper {
.content, app-dropdown-content {
transform-origin: bottom left;
}
}
}
}
私は@each
で昨日試してみましたが、私はそれを終えた後のコードは、この1と同じくらいの長さでした。
誰も私にこのようなコードを書くための「スマートな」方法を示すことができますか?
おかげで、しかし、理由の例のように、私はdropdown.element aに、時には必要ですcontent-wrapperではなく、$ ele-top:0、$ ele-right:0、$ ele-bottom:0、$ ele-left:0、$のような単一のvarを作成する必要があります0- $ con-right:0、$ con-bottom:0、$ con-left:0 このようにして、変換の起源を持つものを作ることは不可能です。私は2つのクラスをチェックし、すべての場合に変換元を与える必要があります:XY – Budi