2013-06-14 30 views
19

Tôi đã một Less mixin định nghĩa là:Ít mixin với các thông số tùy chọn

.fontStyle(@family, @size, @weight: normal, @style: normal, @color: #ffffff, @letter-spacing: normal) { 
    font-family: @family; 
    font-size: @size; 
    color: @color; 
    font-weight: @weight; 
    font-style: @style; 
letter-spacing: @letter-spacing; 
} 

Làm thế nào tôi có thể xác định việc sử dụng như:

.fontStyle('NimbusSansNovCon-Reg', 12px, , , , 0.1em); 

I.E. sử dụng giá trị mặc định cho @weight, @style, @color

Trả lời

24

Để cung cấp thông số nằm xa chuỗi đối số, bạn cũng phải cung cấp biến mong đợi để xác định. Vì vậy, đây:

.fontStyle('NimbusSansNovCon-Reg', 12px, @letter-spacing: 0.1em); 

Tạo này (lưu ý cách color, font-weightfont-style sử dụng giá trị mặc định):

font-family: 'NimbusSansNovCon-Reg'; 
font-size: 12px; 
color: #ffffff; 
font-weight: normal; 
font-style: normal; 
letter-spacing: 0.1em; 
Các vấn đề liên quan