【发布时间】:2016-11-07 18:00:17
【问题描述】:
我的组件如下:
class Test extends React.Component {
outterDivStyles() {
return {
position: "relative",
width: "100%",
overflow: "hidden",
/*height: this.props.height || 200*/
}
}
innerDivStyles(){
return {
position: "absolute",
top: 0,
left: 0,
right: 0,
width: "1000%",
transition: "left .5s",
transitionTimingFunction: "ease"
}
}
render(){
return(
<div>
<div ref="detailsOutterDiv" className="detailsOutterDiv" style={this.outterDivStyles()}>
<div ref="detailsInnerDiv" className="detailsInnerDiv" style={this.innerDivStyles()}>
<div className="slide" ><img src="http://placehold.it/250x200" /></div>
</div>
</div>
</div>
)
}
React.render(<Test />, document.getElementById('container'));
而css是:
.detailsOutterDiv{
background-color: #f00;
/*height: 200px;*/ //if the height is 200px, then it's ok, but can it be done without that?
width: 300px;
display: block;
}
.slide img{
display: block;
height: auto;
}
如果父 div 没有特定高度,有什么方法可以显示全高?
这里是jsfiddle。
【问题讨论】:
-
小提琴不工作
-
无法正常工作,因为 css 中的
height: 200px;已被注释。我想在没有特定宽度的情况下解决它。 -
你应该创建一个最小的例子,没有 javascript
-
@giorgio 完成。见小提琴。
-
去掉绝对的div然后你就可以看到它会显示出来了