Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React JSS(当前)元件选择器-`&;元素`_Reactjs_Material Ui_Jss_Makestyles - Fatal编程技术网

Reactjs React JSS(当前)元件选择器-`&;元素`

Reactjs React JSS(当前)元件选择器-`&;元素`,reactjs,material-ui,jss,makestyles,Reactjs,Material Ui,Jss,Makestyles,在React JSS样式语法中,当前元素选择器是否有一个工作等效项 '&element': { margin: 0 } 用例 我的应用程序中的所有组件都有这种样式 '&:first-of-type': { marginLeft: 0 }, '&:last-of-type': { marginRight: 0 } 因此,如果它们出现在一行中,则第一个和最后一个具有适当的边距 然而,有时我使用 <Button component={Link} ../> 到目

在React JSS样式语法中,当前元素选择器是否有一个工作等效项

'&element': { margin: 0 }
用例

我的应用程序中的所有
组件都有这种样式

'&:first-of-type': { marginLeft: 0 },
'&:last-of-type': { marginRight: 0 }
因此,如果它们出现在一行中,则第一个和最后一个具有适当的边距

然而,有时我使用

<Button component={Link} ../>
到目前为止,我正在使用替代方案

'&:first-of-type:not(a)': { marginLeft: 0 },
'&:last-of-type:not(a)': { marginRight: 0 }

Button元素不应该对边距负责,因为它破坏了封装,您的组件不应该负责外层空间,它的父元素应该负责。

只是想了解更多关于这一点及其背后的上下文。这是良好用户体验的常见做法吗?我在哪里可以阅读更多内容,我应该搜索什么?根据@Oleg Isonen下面的回答,给父元素
左填充
右填充
,而不是尝试给所有其他元素
边距
,或者使用父元素子元素的选择器
'&:first-of-type:not(a)': { marginLeft: 0 },
'&:last-of-type:not(a)': { marginRight: 0 }