[英]How to grow height of an element when it is overflowed
I have a timeline component and the data in it is being set dynamically mapping an array.我有一个时间线组件,其中的数据被设置为动态映射一个数组。 Everything works fine, but when I add more data, the element which should be overflowed on y if the max height is reached, isn't displayed entirely.
一切正常,但是当我添加更多数据时,如果达到最大高度,应该在 y 上溢出的元素不会完全显示。 I tried everything, but I don't get the expected result.
我尝试了一切,但没有得到预期的结果。 Here is my CodeSandBox .
这是我的CodeSandBox 。
My scss file :我的 scss 文件:
// Mixins
@import "mixins";
// Timeline
// $timeline-color: #ee4d4d;
.timelineWrapper{
overflow-y: auto;
min-height: 30vh;
max-height: 80vh;
}
#timeline {
line-height: 1.5em;
font-size: 14px;
width: 90%;
margin: 30px auto;
position: relative;
// overflow-x: hidden;
// overflow-y: scroll;
@include prefix(transition, all .4s ease);
&,
*,
*:before,
*:after {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
&:before {
content:"";
width: 5px;
height: 100%;
background: #26C17E;
left: 50%;
top: 0;
position: absolute;
}
&:after {
content: "";
clear: both;
display: table;
width: 100%;
}
.timeline-item {
margin-bottom: 50px;
position: relative;
@extend %clearfix;
.timeline-icon {
background:white ;
width: 50px;
height: 50px;
position: absolute;
top: 0;
left: 50%;
// overflow: hidden;
margin-left: -23px;
@include prefix(border-radius, 50%);
// .year {
// position: relative;
// text-align: center;
// //transform: translate(50%, 50%);
// }
}
.year {
position: absolute;
top:-6px;
font-family: Open Sans;
font-style: normal;
font-weight: bold;
font-size: 16px;
line-height: 120%;
//transform: translate(50%, 50%);
}
.timeline-content {
// width: 882px;
background: #EEEEEE;
padding: 10px 10px 5px 15px;
position: relative;
@include prefix(box-shadow, 0 3px 0 rgba(0,0,0,0.1));
@include prefix(border-radius, 5px);
// @include prefix(transition, all .3s ease);
h2 {
font-family: Open Sans;
font-style: normal;
font-weight: bold;
font-size: 16px;
line-height: 120%;
// @include prefix(border-radius, 3px 3px 0 0);
}
p{
font-family: Open Sans;
font-style: normal;
font-weight: normal;
font-size: 14px;
line-height: 150%;
padding-left: 5px;
}
&:before {
content: '';
position: absolute;
top: 20px;
right: -5px;
width: 14px;
height: 14px;
background-color: #EEEEEE;
display: block;
border-radius: 3px;
transform: rotate(45deg);
}
&.right {
float: right;
&:before {
left: -5px;
right: inherit;
}
}
}
}
}
#timeline {
// margin: 30px;
// padding: 5px;;
margin-left:10px;
padding: 0;
&:before {
left: 15px;
}
.timeline-item {
.timeline-content {
// width: 95%;
// float: right;
margin-left:70px;
// margin-left:40px;
&:before,
&.right:before {
left: -5px;
right: inherit;
}
}
.timeline-icon {
left: 15px;
}
}
}
.year{
color:black;
text-align:center;
margin-top:20px;
}
// @media screen and (max-width: 768px) {
// #timeline {
// margin: 30px;
// padding: 0;
// &:before {
// left: 0;
// }
// .timeline-item {
// .timeline-content {
// width: 90%;
// float: right;
// &:before,
// &.right:before {
// left: -5px;
// right: inherit;
// }
// }
// .timeline-icon {
// left: 0;
// }
// }
// }
// }
Component:零件:
<>
<section>
<h1>Education</h1>
<div id="timeline" className='timelineWrapper'>
{data.map((info)=>(
<div className="timeline-item">
<span className="timeline-icon">
<span> </span>
<span className="year">{info.date}</span>
</span>
<div className='timeline-content'>
<h2>{info.title}</h2>
<p>{info.text}</p>
</div>
</div>
))}
</div>
</section>
</>
Component should have an internal scroll with a height equal to 30vh* (30%) and a max height of 80vh (80%):组件应具有高度等于 30vh* (30%) 且最大高度为 80vh (80%) 的内部滚动:
I need that green bar be displayed proportionally with how many items are being added there.我需要与那里添加的项目数量成比例地显示绿色条。 Could you help me please?
请问你能帮帮我吗?
#timeline
is the container and that is the green line: #timeline
是容器,即绿线:
&:before {
content:"";
width: 5px;
height: 100%;
background: #26C17E;
left: 50%;
top: 0;
position: absolute;
By adding a div
with timelineContainer
class in App.js
and changing timeline.scss
a little bit, I am getting I think what you want.通过在 App.js 中添加一个带有
timelineContainer
容器App.js
的div
并稍微更改timeline.scss
线.scss,我得到了你想要的。 Here is a live CodeSandbox and the code:这是一个实时的CodeSandbox和代码:
App.js:应用程序.js:
import "./styles.css";
export default function App(props) {
const { data } = props;
return (
<section>
<h1>Education</h1>
<div className="timelineContainer">
<div id="timeline" className="timelineWrapper">
{data.map((info, index) => (
<div className="timeline-item" key={index}>
<span className="timeline-icon">
<span> </span>
<span className="year">{info.date}</span>
</span>
<div className="timeline-content">
<h2>{info.title}</h2>
<p>{info.text}</p>
</div>
</div>
))}
</div>
</div>
</section>
);
}
Timeline.scss:时间线.scss:
// Mixins
@import "mixins";
// Timeline
// $timeline-color: #ee4d4d;
.timelineContainer{
overflow-y: auto;
min-height: 30vh;
max-height: 80vh;
}
.timelineWrapper {
line-height: 1.5em;
font-size: 14px;
width: 90%;
margin: 30px auto;
position: relative;
// overflow-x: hidden;
// overflow-y: scroll;
@include prefix(transition, all .4s ease);
&,
*,
*:before,
*:after {
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
&:before {
content:"";
width: 5px;
height: 100%;
background: #26C17E;
left: 50%;
top: 0;
position: absolute;
}
&:after {
content: "";
clear: both;
display: table;
width: 100%;
}
.timeline-item {
margin-bottom: 50px;
position: relative;
@extend %clearfix;
.timeline-icon {
background:white ;
width: 50px;
height: 50px;
position: absolute;
top: 0;
left: 50%;
// overflow: hidden;
margin-left: -23px;
@include prefix(border-radius, 50%);
// .year {
// position: relative;
// text-align: center;
// //transform: translate(50%, 50%);
// }
}
.year {
position: absolute;
top:-6px;
font-family: Open Sans;
font-style: normal;
font-weight: bold;
font-size: 16px;
line-height: 120%;
//transform: translate(50%, 50%);
}
.timeline-content {
// width: 882px;
background: #EEEEEE;
padding: 10px 10px 5px 15px;
position: relative;
@include prefix(box-shadow, 0 3px 0 rgba(0,0,0,0.1));
@include prefix(border-radius, 5px);
// @include prefix(transition, all .3s ease);
h2 {
font-family: Open Sans;
font-style: normal;
font-weight: bold;
font-size: 16px;
line-height: 120%;
// @include prefix(border-radius, 3px 3px 0 0);
}
p{
font-family: Open Sans;
font-style: normal;
font-weight: normal;
font-size: 14px;
line-height: 150%;
padding-left: 5px;
}
&:before {
content: '';
position: absolute;
top: 20px;
right: -5px;
width: 14px;
height: 14px;
background-color: #EEEEEE;
display: block;
border-radius: 3px;
transform: rotate(45deg);
}
&.right {
float: right;
&:before {
left: -5px;
right: inherit;
}
}
}
}
}
#timeline {
// margin: 30px;
// padding: 5px;;
margin-left:10px;
padding: 0;
&:before {
left: 15px;
}
.timeline-item {
.timeline-content {
// width: 95%;
// float: right;
margin-left:70px;
// margin-left:40px;
&:before,
&.right:before {
left: -5px;
right: inherit;
}
}
.timeline-icon {
left: 15px;
}
}
}
.year{
color:black;
text-align:center;
margin-top:20px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.