文本溢出省略号不受position:relative影响

时间:2016-08-18 09:21:48

标签: html css css3 text-styling

FIDDLE HERE

我有一张图片,下面我有span图片名。

<div class="myImageList  withScrollbars">
    <div class="myImageListEntry">
        <img style="width: 140px; height: 105px; margin-top: 17.5px;" src="..._thumbn.png" class="myImageListImage">
        <span class="myImageName">audsfsdfsdfsfsfsdfsdfgsdf43545345to1.JPG</span>
    </div>
</div>

由于图片名称可能太长,我在overflow: ellipsis;上有.myImageListEntry

现在我想将span 10px放在图像下方。 margin-top和padding-top不起作用,所以我使用了这个:

.myImageName{
    position: relative;
    top: 10px;
}

跨度中的文字距离顶部10px,但三个点(...)没有向下移动。

image and imagename

如何将省略号10px放下?

3 个答案:

答案 0 :(得分:1)

将省略号添加到包含文本的范围,而不是包装图像和文本的div

.myImageName {
    position: relative;
    top: 10px;
    width: 100%;
    white-space: nowrap;
    text-overflow: ellipsis;
    display: block;
    overflow: hidden;
}

&#13;
&#13;
.myImageList{
  max-height: 320px;
}

.myImageListEntry{
  display: block;
  float: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px 5px 5px 5px;
  margin: 5px 5px 5px 5px;
  border: 1px solid rgb(128, 128, 128);
  border-radius: 10px;
  width: 150px;
  height: 150px;
  background-color: rgb(178, 178, 255);
}

.myImageListImage{
  display: block;
  margin-left: auto;
  margin-right: auto;
  margin-top: auto;
  margin-bottom: auto;
  max-width: 140px;
  max-height: 105px;
  cursor: pointer;
  margin-top: auto !important;
  line-height: 150px;
  vertical-align: middle;
}

.myImageName {
    position: relative;
    top: 10px;
    width: 100%;
    white-space: nowrap;
    text-overflow: ellipsis;
    display: block;
    overflow: hidden;
}
&#13;
<div class="myImageList  withScrollbars">
  <div class="myImageListEntry">
      <img style="width: 140px; height: 105px; margin-top: 17.5px;" src="//www.brukacm.nl/restcontent/uploads/734/349817438DE30553C1AE0D1ECAB91BE48BA0B26D/1/2/42aaaa23401f4cf6a3c0a6cc5f0cd9f0_JPG_thumbn.png" class="myImageListImage">
      <span class="myImageName">audsfsdfsdfsfsfsdfsdfgsdf43545345to1.JPG</span>
  </div>
  <div class="myImageListEntry">
    <img style="width: 140px; height: 125.3px; margin-top: 7.35px;" src="//www.brukacm.nl/restcontent/uploads/734/4F237AC78A20570E0E45E2115D1B13E06697F7AF/1/2/93503e0ebd5f4f079a879eb41785b3e3_png_thumbn.png" class="myImageListImage">
    <span class="myImageName">happyt.png</span>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我认为它不是一个好方法,文本eclips默认样式总是与文本对齐如何才能移到顶部。

请使用此代码。

.myImageName {
    display: inline-block;
    height: 22px;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 154px;
}

希望这可能会有所帮助。感谢。

答案 2 :(得分:0)

更新jsfiddle

.myImageName{
  position: relative;
  top: 6px;
  vertical-align: super;
}