文字超出了容器的最大高度和宽度

时间:2020-02-14 12:27:41

标签: css reactjs

桌面

enter image description here

移动设备:

enter image description here

你好,我的文字超过了我的最大高度 我希望我的容器跟随其高度,并且我的文本具有我的文本容器的最大宽度

代码:

<div className="App">
  <div class="wrapper">
    <div className="text">
      <div class="card-info">
        <div class="card-about">
          <a class="card-tag tag-news">NEWS</a>
          <div class="card-time">6/11/2018</div>
        </div>
      </div>
      <h3 className="textxd">dasssssssssssssssss</h3>
      <p className="textxd">
        aaaaaaaaaaaaa dasuhdasudhu dasuhduashu aaaaaaaaaaaaa dasuhdasudhu
        dasuhduashu aaaaaaaaaaaaa da aaaaaaaaaaaaa dasuhdasudhu dasuhduashu
        aaaaaaaaaaaaa dasuhdasudhu dasuhduashu aaaaaaaaaaaaa dasuhdasudhu
        dasuhduashu aaaaaaaaaaaaa dasuhdasudhu dasuhduashusuhdasudhu
        dasuhduashu aaaaaaaaaaaaa dasuhdasudhu dasuhduashu
      </p>
    </div>
  </div>
</div>

css:

.App {
  padding: 20px;
  font-family: sans-serif;
  text-align: center;
  background: red;
  height: 40vh;
}


.wrapper {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 30vh;
  max-height: 30vh;
  border-radius: 10px;
  cursor: pointer;
  background:blue;

}
.textxd {
  margin-top: 10px;
  margin-bottom: 5px;
}
.text {
  height: 100%;
  max-height: 30vh;
  padding: 0.15rem 1.25rem;
  color: white;
  transition: all 0.3s ease-in;
  ${({ isHover }) =>
    isHover &&
    `
  color:black;
  transition: all 0.3s ease-in;
   `}
}
.card-about {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
}
.card-tag {
  width: 60px;
  max-width: 100px;
  padding: 0.2rem 0.5rem;
  font-size: 12px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: #ffab00;
  color: #fff;
}
.card-info {
  position: relative;
}

我不知道如何解决这个问题,我需要离开容器和响应文本,使我的容器遵循文本的高度或文本的最大高度

3 个答案:

答案 0 :(得分:1)

如果您希望类包装器具有相同的高度,请使用 溢出:滚动。像这样->

.wrapper { ...  overflow : scroll; }

或其他使用高度:自动;

.wrapper { ...  height : auto;   }

答案 1 :(得分:0)

只需在这样的移动设备上设置height auto

@media only screen and (max-width: 600px) {
 .wrapper {
  height: auto;
  max-height: auto;    
 }
}

答案 2 :(得分:0)

尝试此操作。为您的div .class属性添加最大宽度也被错误地指定为className

from scipy.stats import norm
import matplotlib.pyplot as plt
import numpy as np 

idx = np.array([1,1.2,1.4,1.6,1.8,2.0,3.0,4.0,5.0,6.0,7.0])
xxx = np.arange(-10, 10, .1)

for i in range(0,len(idx)):
    rv1 = norm(loc = 0., scale = 1.0*i)
    plt.plot(xxx,rv1.pdf(xxx),  color ='b', alpha=i / len(idx))

plt.show()
.App {
  padding: 20px;
  font-family: sans-serif;
  text-align: center;
  background: red;
 
}


.wrapper {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  
  
  border-radius: 10px;
  cursor: pointer;
  background:blue;

}
.textxd {
  margin-top: 10px;
  margin-bottom: 5px;
}
.text {
 height:auto;
  max-width:100px;
 
  padding: 0.15rem 1.25rem;
  color: white;
  transition: all 0.3s ease-in;
  ${({ isHover }) =>
    isHover &&
    `
  color:black;
  transition: all 0.3s ease-in;
   `}
}
.card-about {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
}
.card-tag {
  width: 60px;
  max-width: 100px;
  padding: 0.2rem 0.5rem;
  font-size: 12px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: #ffab00;
  color: #fff;
}
.card-info {
  position: relative;
}