css - 图像和两个跨度对齐到 div

标签 css

我有以下文本 CSS 代码:

.text2 
{
vertical-align: middle;
color: white;
text-align: right;
padding-right: 5px;
line-height: 40px;
float: right;
white-space: nowrap;
}

我的问题是 text2 的尺寸可变 我希望它在没有溢出的情况下向左对齐。

https://jsfiddle.net/4oc0b2pe/5/

最佳答案

移除.divboxheader 的宽度。结果仅在全屏模式下可见。

.divbox {
  width: 50%;
  display: inline-block;
  font-family: Helvetica, "Lucida Grande";
  font-size: 14px;
  position: relative;
  box-sizing: border-box;
  padding: 2px;
}

.divboxheader {
  display: block;
  height: 40px;
  background-color: rgb(43, 51, 56);
  text-overflow: ellipsis;
}

.img {
  vertical-align: middle;
  display: table-cell;
  height: calc(100% - 4px) !important;
  float: left;
  margin: 2px 0px;
  width: 20%;
}

.text1 {
  vertical-align: middle;
  color: white;
  text-align: center;
  padding-left: 5px;
  line-height: 40px;
  width: 50%;
  float: left;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.text2 {
  vertical-align: middle;
  color: white;
  text-align: right;
  padding-right: 5px;
  line-height: 40px;
  float: right;
  white-space: nowrap;
}
<div class="divbox">
  <div class='divboxheader'>
    <img class='img' src="https://s3-us-west-1.amazonaws.com/powr/defaults/image-slider1.jpg" />
    <span class='text1'>Text1 Text1 Text1 text1 text1 text1 text1</span>
    <span class='text2'>text2 text2 text2</span>
  </div>
</div>

关于css - 图像和两个跨度对齐到 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44565291/

相关文章:

html - 如何将 index.html 与 github 上的其他 .html 文件放在同一个文件夹中?

html - 如何让图像宽度超过它所在的div的宽度

html - CSS - 带溢出省略号的旋转文本

css - 是否有一个页面列出所有 css 属性及其默认值?

javascript - Chrome 扩展用户界面

html - CSS Responsive - 更改 div 的顺序

jquery - Owl Carousel 自动播放在鼠标悬停时无法正常工作?

javascript - Masonry Image gallery 不工作,内联 Javascript 不生效

iphone - 如何通过 CSS 关闭某些 HTML 元素的硬件加速?

html - 用另一个元素包裹时,CSS 动画无法正常工作