ailsin
ailsin

Reputation: 35

How to prevent image icon from being cut off?

I have created a timeline component in React and I am trying to include an icon on the timeline. However it is being cut off for some reason and is only showing half of the icon on either side. I know it is an overflow issue but I cannot pinpoint it. This is how it currently looks like:

enter image description here

When I add overflow: visible. It does show the full icon but then the timeline section encroaches on to the next section due its length.

This is what happens I add overflow: visible.

enter image description here

As you can see, it is encroaching on to Contact.

How can I show the icon fully but also not have the timeline section encroach on to other sections?

This is what I have so far.

TimelineItem.jsx

import {Person, Mail} from "@material-ui/icons"

const TimelineItem = ({ data }) => (
    <div className="timeline-item">
        <div className="timeline-item-content">
            <span className="tag" style={{ background: data.category.color }}>
                {data.category.tag}
            </span>
            <time>{data.date}</time>
            <p>{data.text}</p>
            {data.link && (
                <a
                    href={data.link.url}
                    target="_blank"
                    rel="noopener noreferrer"
                >
                    {data.link.text}
                </a>
            )}
            <div className="itemContainer">
            <Mail classname="icon" />
            </div>
            {/* <span className="circle"/> */}
        </div>
    </div>
);

export default TimelineItem;

Timeline.jsx

import TimelineData from './TimelineData';
import TimelineItem from './TimelineItem'
import './timeline.scss'


export default function Timeline() {
    return (
        <div className="reactTimeline">
            <h1>Satyen Singh Timeline</h1>
            <div className="timeline-container" id="timeline">
                {TimelineData.map((data, idx) => (
                    <TimelineItem data={data} key={idx} />
                ))}
            </div>
        </div>
    )
}

timeline.scss

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
//   background-color: white;
  overflow-x: visible;
}



h1 {
    text-align: center;
}

body {
    // overflow: visible;

//   line-height: 1.5;
}
.timeline-container {
    display: flex;
    flex-direction: column;
    position: relative;
    margin: 40px 0;
    // overflow-x: visible;
  }
  .timeline-container::after {
    background-color: #e17b77;
    content: '';
    position: absolute;
    left: calc(50% - 2px);
    width: 4px;
    height: 100%;
    // overflow-x: visible;
  }
  
  .timeline-item {
    display: flex;
    justify-content: flex-end;
    padding-right: 30px;
    position: relative;
    margin: 10px 0;
    width: 50%;
    // overflow-x: visible;
  }
  .timeline-item:nth-child(odd) {
    align-self: flex-end;
    justify-content: flex-start;
    padding-left: 30px;
    padding-right: 0;
    // overflow-x: visible;
  }
  
  .timeline-item-content {
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 15px;
    position: relative;
    width: 400px;
    max-width: 70%;
    text-align: right;
    overflow-x: visible
  }
  .timeline-item-content::after {
    content: ' ';
    background-color: #fff;
    box-shadow: 1px -1px 1px rgba(0, 0, 0, 0.2);
    position: absolute;
    right: -7.5px;
    top: calc(50% - 7.5px);
    transform: rotate(45deg);
    width: 15px;
    height: 15px;
    // overflow-x: visible
  }
  .timeline-item:nth-child(odd) .timeline-item-content {
    text-align: left;
    align-items: flex-start;
    // overflow-x: visible
  }
  .timeline-item:nth-child(odd) .timeline-item-content::after {
    right: auto;
    left: -7.5px;
    box-shadow: -1px 1px 1px rgba(0, 0, 0, 0.2);
    overflow-x: visible
  }
  
  .timeline-item-content .tag {
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    top: 5px;
    left: 5px;
    letter-spacing: 1px;
    padding: 5px;
    position: absolute;
    text-transform: uppercase;
    overflow-x: visible;
  }
  .timeline-item:nth-child(odd) .timeline-item-content .tag {
    left: auto;
    right: 5px;
    overflow: visible;
  }
  .timeline-item-content time {
    color: #777;
    font-size: 12px;
    font-weight: bold;
  }
  .timeline-item-content p {
    font-size: 16px;
    line-height: 24px;
    margin: 15px 0;
    max-width: 250px;
  }
  .timeline-item-content a {
    font-size: 14px;
    font-weight: bold;
  }
  .timeline-item-content a::after {
    content: ' ►';
    font-size: 12px;
    overflow: visible;
  }
  .timeline-item-content .itemContainer {
    position: absolute;
    top: calc(50% - 10px);
    right: -40px;
    width: 20px;
    height: 20px;
    z-index: 100;
    overflow-x: visible;
  }
  .timeline-item:nth-child(odd) .timeline-item-content .itemContainer {
    right: auto;
    left: -40px;
    overflow-x: visible;
  }

Upvotes: 0

Views: 523

Answers (1)

Mihir Sojitra
Mihir Sojitra

Reputation: 109

It's Working.. look it out, need to be some css issue for overflow

.moreSec {
  padding: 150px 0;
  font-size: 50px;
  text-align: center;
  background: antiquewhite;
}

.timeline-container {
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 0 0 40px;
  background: beige;
  overflow: hidden;
  margin-top:20px;
}

.timeline-container::after {
  background-color: #e17b77;
  content: '';
  position: absolute;
  left: calc(50% - 2px);
  width: 4px;
  height: 100%;
  ;
}

.timeline-item {
  display: flex;
  justify-content: flex-end;
  padding-right: 30px;
  position: relative;
  margin: 10px 0;
 width: 45%;
    max-width: 100%;
}

.timeline-item:nth-child(odd) {
  align-self: flex-end;
  justify-content: flex-start;
  padding-left: 30px;
  padding-right: 0;
  ;
}

.timeline-item-content {
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  border-radius: 5px;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 15px;
  position: relative;
  width: 400px;
  max-width: 70%;
  text-align: right;
  overflow-x: visible
}

.timeline-item-content::after {
  content: ' ';
  background-color: #fff;
  box-shadow: 1px -1px 1px rgba(0, 0, 0, 0.2);
  position: absolute;
  right: -7.5px;
  top: calc(50% - 7.5px);
  transform: rotate(45deg);
  width: 15px;
  height: 15px;
}

.timeline-item:nth-child(odd) .timeline-item-content {
  text-align: left;
  align-items: flex-start;
}

.timeline-item:nth-child(odd) .timeline-item-content::after {
  right: auto;
  left: -7.5px;
  box-shadow: -1px 1px 1px rgba(0, 0, 0, 0.2);
  overflow-x: visible
}

.timeline-item-content .tag {
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  top: 5px;
  left: 5px;
  letter-spacing: 1px;
  padding: 5px;
  position: absolute;
  text-transform: uppercase;
  overflow-x: visible;
}

.timeline-item:nth-child(odd) .timeline-item-content .tag {
  left: auto;
  right: 5px;
  overflow: visible;
}

.timeline-item-content time {
  color: #777;
  font-size: 12px;
  font-weight: bold;
}

.timeline-item-content p {
  font-size: 16px;
  line-height: 24px;
  margin: 15px 0;
  max-width: 250px;
}

.timeline-item-content a {
  font-size: 14px;
  font-weight: bold;
}

.timeline-item-content a::after {
  content: ' ►';
  font-size: 12px;
  overflow: visible;
}

.timeline-item-content .itemContainer {
  position: absolute;
  top: calc(50% - 10px);
  right: -40px;
  width: 20px;
  height: 20px;
  z-index: 100;
  overflow-x: visible;
}

.timeline-item:nth-child(odd) .timeline-item-content .itemContainer {
  right: auto;
  left: -40px;
  overflow-x: visible;
}
.timeline-item-content .icon {
    background: #ffffff;
    border-radius: 100%;
    box-shadow: 0 0 5px rgb(0 0 0 / 30%);
    height: 25px;
    width: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 23px;
}
<div class="reactTimeline">
  <h1>Timeline</h1>
  <div class="timeline-container" id="timeline">
    <div class="timeline-item">
      <div class="timeline-item-content">
        <span class="tag" style="background-color: aqua;">
                        urgent
                    </span>
        <time>24/05/2022</time>
        <p>dummy text fnejfenjk ehfuheufh, dummy text fnejfenjk ehfuheufh</p>

        <a href=# target="_blank" rel="noopener noreferrer">
                            Read More
                        </a>
        <div class="itemContainer">
          <!-- <Mail class="icon" /> -->
          <span class="icon">✉</span>
        </div>
      </div>
    </div>
    <div class="timeline-item">
      <div class="timeline-item-content">
        <span class="tag" style="background-color: aqua;">
                        urgent
                    </span>
        <time>24/05/2022</time>
        <p>dummy text fnejfenjk ehfuheufh, dummy text fnejfenjk ehfuheufh</p>

        <a href=# target="_blank" rel="noopener noreferrer">
                            Read More
                        </a>
        <div class="itemContainer">
          <!-- <Mail class="icon" /> -->
          <span class="icon">✉</span>
        </div>
      </div>
    </div>
    <div class="timeline-item">
      <div class="timeline-item-content">
        <span class="tag" style="background-color: aqua;">
                        urgent
                    </span>
        <time>24/05/2022</time>
        <p>dummy text fnejfenjk ehfuheufh, dummy text fnejfenjk ehfuheufh</p>

        <a href=# target="_blank" rel="noopener noreferrer">
                            Read More
                        </a>
        <div class="itemContainer">
          <!-- <Mail class="icon" /> -->
          <span class="icon">✉</span>
        </div>
      </div>
    </div>
    <div class="timeline-item">
      <div class="timeline-item-content">
        <span class="tag" style="background-color: aqua;">
                        urgent
                    </span>
        <time>24/05/2022</time>
        <p>dummy text fnejfenjk ehfuheufh, dummy text fnejfenjk ehfuheufh</p>

        <a href=# target="_blank" rel="noopener noreferrer">
                            Read More
                        </a>
        <div class="itemContainer">
          <span class="icon">✉</span>

        </div>
      </div>
    </div>
    <div class="timeline-item">
      <div class="timeline-item-content">
        <span class="tag" style="background-color: aqua;">
                        urgent
                    </span>
        <time>24/05/2022</time>
        <p>dummy text fnejfenjk ehfuheufh, dummy text fnejfenjk ehfuheufh</p>

        <a href=# target="_blank" rel="noopener noreferrer">
                            Read More
                        </a>
        <div class="itemContainer">
          <span class="icon">✉</span>

        </div>
      </div>
    </div>
    <div class="timeline-item">
      <div class="timeline-item-content">
        <span class="tag" style="background-color: aqua;">
                        urgent
                    </span>
        <time>24/05/2022</time>
        <p>dummy text fnejfenjk ehfuheufh, dummy text fnejfenjk ehfuheufh</p>

        <a href=# target="_blank" rel="noopener noreferrer">
                            Read More
                        </a>
        <div class="itemContainer">
          <span class="icon">✉</span>

        </div>
      </div>
    </div>
  </div>
</div>
<div class="moreSec">
  Next Section
</div>

Upvotes: 1

Related Questions