首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS截断不起作用

CSS截断不起作用
EN

Stack Overflow用户
提问于 2016-03-09 09:35:08
回答 2查看 134关注 0票数 0

你能告诉我为什么价格($33000000.33)会跳到第二行吗?我需要有一个价格和“超长标题”在同一行。基本上,当价格太高时,我需要截短“超长标题”,比如"Super Lon……“例如,两者仍然在同一行上。

代码如下:

代码语言:javascript
复制
<div class="item-description group">
  <a href="/pro/test-item-with-variations">
    <p class="title truncate-text" title="">Test Item with variationsktvy9i</p>
  </a>
  <p class="shop truncate-text" title="">
    <a href="/pro">Super long title</a>
  </p>
  <a href="/pro/test-item-with-variations">
    <p class="price">$33000000.33</p>
  </a>
</div>

Screenshot

代码语言:javascript
复制
.item-description {
    padding: 15px 10px;
    background: white;
    display: block;
}
a {
    text-decoration: none;
    color: #66c6c3;
    background-color: transparent;
}
p.shop {
    font-size: 14px;
}
.shop {
    color: #5d6d6d;
    font-size: 16px;
    padding: 0;
    margin: 0;
    width: 50%;
    float: left;
}
.truncate-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
p {
    display: block;
}
p.shop a {
    color: #5d6d6d;
}
p.price {
    font-size: 16px;
}
.price {
    color: #62c6c4;
    font-weight: 600;
    float: right;
}
EN

回答 2

Stack Overflow用户

发布于 2016-03-09 09:47:21

直接在具有长文本的元素上使用这些规则集:

代码语言:javascript
复制
.ellipse {
  display: block;
  position: relative;
  outline: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  /*vertical-align: middle;*//* for content in a table-cell*/
  width: 100%;
}

  • 删除了所有浮动,
  • 在段落中放置了所有锚点,
  • 使所有段落display: inline-block
  • 使所有锚点floats

注意:所有添加的outlinebackground-color都是为了显示元素的边缘存在的位置和文本被裁剪的位置。它基本上是在元素右边缘的同一行上的一致剪辑(没有换行)。

代码片段

代码语言:javascript
复制
a {
  width: 49%;
  background: rgba(255, 0, 0, .3);
  text-decoration: none;
  color: #66c6c3;
}
p {
  width: 49%;
  outline: 1px solid blue;
  background: yellow;
  display: inline-block;
  position:relative;
}
div {
  outline: 2px dashed #e3e;
}
.ellipse {
  display: block;
  position: relative;
  outline: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  /*vertical-align: middle;*/
  /* for content in a table-cell*/
  width: 100%;
}
.item-description {
  padding: 15px 10px;
  background: white;
  display: block;
  position: relative;
}

.shop {
  color: #5d6d6d;
  font-size: 16px;
  padding: 0;
  margin: 0;
  width: 49%;

}
.shop a {
  color: #5d6d6d;
}
.price {
  color: #62c6c4;
  font-size: 16px;
  
}
代码语言:javascript
复制
<div class="item-description group">
  <p class="title" title="">
  <a href="/pro/test-item-with-variations" class="ellipse">
    Test Item with variationsktvy9i&((79777788uhgfrtrfghuooooooogybvtvtuiuy3463%^&8*Upl[lk;klhguifdttftuuuuuuuuuuuuuyvtfcjhgfds</a>
  </p><br/>
  <p class="shop" title="">
    <a class="ellipse" href="/pro">Super long titlexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>
  </p>
  <p class="price" title="">
    <a href="/pro/test-item-with-variations" class="ellipse">$3300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.33</a>
    </p>
</div>

票数 0
EN

Stack Overflow用户

发布于 2016-03-10 15:30:20

谢谢你的评论,我的问题已经解决了。

代码语言:javascript
复制
.item-description {
    padding: 15px 10px;
    background: white;
    display: block;
}
a {
    text-decoration: none;
    color: #66c6c3;
    background-color: transparent;
}
p.shop {
    font-size: 14px;
}
.shop {
    color: #5d6d6d;
    font-size: 16px;
    padding: 0;
    margin: 0;
    min-width: 10%;
}
.truncate-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
p.shop a {
    color: #5d6d6d;
}
p.price {
    font-size: 16px;
}
.price {
    color: #62c6c4;
    font-weight: 600;
    float: right;
} 
代码语言:javascript
复制
<div style="width:190.5px;">
<div class="item-description group">
  <a href="/pro/test-item-with-variations">
    <p class="title truncate-text" title="">Test Item with variationsktvy9i</p>
  </a>
  <div style="height:20px;">
  <a href="/pro/test-item-with-variations">
    <span class="price">$33000000.33</span>
  </a>
  <p class="shop truncate-text" title="">
    <a href="/pro">Super long title</a>
  </p>
  </div>
</div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35881360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档