Answer the question
In order to leave comments, you need to log in
Why does the style for the smallest resolution (styled-components) work?
Trying to migrate bootstrap grid to styled-components but getting a permissions issue.
For some reason, at a resolution of 1200 and above, styles for 576 work?
The order of the styles does not solve the problem.
import React from 'react';
import styled from 'styled-components';
const Column = styled.div`
position: relative;
width: 100%;
padding-right: 15px;
padding-left: 15px;
`;
const columnCount = 12;
const ColumnStyled = styled(Column)`
${props => props.lg ?
`
@media (min-width: 1200px) {
flex: 0 0 ${(100 / columnCount) * props.lg}%;
max-width: ${(100 / columnCount) * props.lg}%;
}
`
:
''
}
${props => props.md ?
`
@media (min-width: 992px) {
flex: 0 0 ${(100 / columnCount) * props.md}%;
max-width: ${(100 / columnCount) * props.md}%;
}
`
:
''
}
${props => props.sm ?
`
@media (min-width: 768px) {
flex: 0 0 ${(100 / columnCount) * props.sm}%;
max-width: ${(100 / columnCount) * props.sm}%;
}
`
:
''
}
${props => props.xs ?
`
@media (min-width: 576px) {
flex: 0 0 ${(100 / columnCount) * props.xs}%;
max-width: ${(100 / columnCount) * props.xs}%;
}
`
:
''
}
`;
export default (props) => {
return (
<ColumnStyled xs={4} sm={4} md={4} lg={8}>
{ props.children }
</ColumnStyled>
)
}
Answer the question
In order to leave comments, you need to log in
To solve the problem, you need to understand the order of the rules and parameters in the component
import React from 'react';
import styled from 'styled-components';
const Column = styled.div`
position: relative;
width: 100%;
padding-right: 15px;
padding-left: 15px;
`;
const columnCount = 12;
const ColumnStyled = styled(Column)`
${props => props.xs ?
`
@media (min-width: 576px) {
flex: 0 0 ${(100 / columnCount) * props.xs}%;
max-width: ${(100 / columnCount) * props.xs}%;
}
`
:
''
}
${props => props.sm ?
`
@media (min-width: 768px) {
flex: 0 0 ${(100 / columnCount) * props.sm}%;
max-width: ${(100 / columnCount) * props.sm}%;
}
`
:
''
}
${props => props.md ?
`
@media (min-width: 992px) {
flex: 0 0 ${(100 / columnCount) * props.md}%;
max-width: ${(100 / columnCount) * props.md}%;
}
`
:
''
}
${props => props.lg ?
`
@media (min-width: 1200px) {
flex: 0 0 ${(100 / columnCount) * props.lg}%;
max-width: ${(100 / columnCount) * props.lg}%;
}
`
:
''
}
`;
export default (props) => {
return (
<ColumnStyled lg={8} md={4} sm={4} xs={4}>
{ props.children }
</ColumnStyled>
)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question