【发布时间】:2018-06-13 09:39:16
【问题描述】:
我希望它们都适合带边框的框,但我不希望它们看起来被拉伸。我该怎么做?
我尝试给它们一个固定的高度、div 内的宽度等,但它们看起来总是不太正确
<CategoryContainer>
<CategoryLink to={`${category.name.toLowerCase()}`}>
<CategoryImage>
<Image image={category.products[0].image} />
</CategoryImage>
<CategoryName>
{`${category.name}`}
</CategoryName>
</CategoryLink>
</CategoryContainer>
我的样式组件是:
export const Container = styled.div`
display: flex;
width: 1000px;
`;
export const CategoryContainer = styled.div`
height: 300px;
width: 33%;
margin-right: 10px;
position: relative;
border: 1px solid black;
`;
export const CategoryLink = styled(Link)`
text-decoration: none;
color: black;
z-index: 5;
position: absolute;
`;
export const CategoryImage = styled.div`
`
export const CategoryName = styled.div`
`
【问题讨论】:
-
请包含呈现的 HTML 和 CSS ...
-
max-height: 100%; max-width: 100%;应该可以在大多数浏览器中使用,我记得这可能会导致某个地方的兼容性问题(我认为是 safari),但这是几年前的事情,现在可能已经解决了。不过,您不需要设置明确的高度或宽度,因为这会导致它倾斜。只有两个max属性,没有别的。 -
@jmcgriz
max-width: 100%; max-height: 100%; width: auto;我相信就足够了。 -
@DeepakKamat 但是我应该将这些应用到上面的哪个组件?
-
图像,
img标记在您放置它们的容器内。
标签: javascript html css styled-components