[英]Styled-components css properties are only enacted when surrounded by javascript
The problem is the css in the style-components is only enacted in the react-beautiful-dnd project if the CSS properties values are surrounded in javascript brackets ${"50%"}, ${"100px"}, ${"orange"}.问题是样式组件中的 css 仅在 react-beautiful-dnd 项目中执行,如果 CSS 属性值包含在 javascript 括号 ${"50%"}, ${"100px"}, ${"orange “}。
My question is why is this occurring?我的问题是为什么会这样?
"App.styles.js" the styled-components file. “App.styles.js”样式组件文件。 Note!
笔记! the height and border-color property are not surrounded by javascript brackets.
height 和 border-color 属性没有被 javascript 括号包围。
import styled from 'styled-components'
export const DroppableContainer = styled.div`
display: ${'flex'};
overflow: ${'auto'};
border: ${"1px solid"};
border-color: "orange";
width: ${"50%"};
height: "100px";
`
export const DraggableItem = styled.div`
font-size: ${"60px"};
flex: ${"auto"};
text-align: ${"center"};
background-color: ${({dragging}) => dragging ? "rgb(11, 138, 79)" : "rgb(156, 186, 172)"};
`
"App.js" The return statement for the React App component, which uses the “App.js” React App 组件的返回语句,它使用
return (
<div>
<DragDropContext onDragEnd={result => onDragEnd(result)}>
<Droppable droppableId="droppable" direction="horizontal">
{(provided, snapshot) => (
<DroppableContainer
ref={provided.innerRef}
{...provided.droppableProps}
>
{items.map((item, index) => (
<Draggable key={item.id} draggableId={item.id} index={index}>
{(provided, snapshot) => (
<DraggableItem
dragging={snapshot.isDragging}
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
style={{ ...provided.draggableProps.style,}}
>
{item.content}
</DraggableItem>
)}
</Draggable>
))}
{provided.placeholder}
</DroppableContainer>
)}
</Droppable>
</DragDropContext>
</div>
);
As you can see the height of the component is not 100px and the border-color is not orange如您所见,组件的高度不是 100px,边框颜色也不是橙色
All properties in the styled-components must not have string quotations around them. styled-components 中的所有属性都不能有字符串引号。
import styled from 'styled-components'
export const DroppableContainer = styled.div`
display: flex;
overflow: auto;
background-color: rgb(156, 186, 172);
width: 500px;
border: 5px solid;
border-color: green;
`
export const DraggableItem = styled.div`
font-size: 60px;
flex: auto;
text-align: center;
background-color: ${({dragging}) => dragging ? "rgb(11, 138, 79)" : "rgb(156, 186, 172)"};
`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.