隐藏div之外的文本

时间:2017-03-20 00:32:08

标签: html css twitter-bootstrap twitter-bootstrap-3

I have

我正在尝试创建上面的设计。这是我到目前为止所取得的成就,但我使用的是固定高度。

https://jsfiddle.net/iDaniel19/b0LL5wj8/1/

{{1}}

如何确保文字保留在一行而不显示在外面?

E.g。在上面的图片中,底线(时间和位置)将不适合移动设备,并将在容器外部打破

这是编码图像的正确方法吗?

3 个答案:

答案 0 :(得分:0)

updated fiddle

尝试按以下方式进行操作 - 它不会在小型设备中中断,而是会创建一个新行。



.body {
    font-family: 'Open Sans';
}



.no-padding-left {
    padding-left:0;
}

.float-right {
    float:right;
}
.event{
    height:70px;
}
.event-date {
    border-right: 1px solid black;
    text-align: center;
}

.event-date > h3 {
    font-weight: bold;
    text-transform: uppercase;
    padding:0;
    margin:0;
    line-height: 34px;
}

.event-info-title {
    height: 35px;
}

.event-info-title > h4{
    padding: 0 0 0 5px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin:0;
    top:25%;
    position: relative;
}

.event-info-tl {
    height: 35px;
    border-top: 1px solid black;
}
.event-info-tl > div {
    display: inline-block;
}

.event-info-tl-text {
    top:25%;
    position: relative;
}

.event-info-tl-text > p {
    display: inline-block;
    margin: 0;
}
.event-info-tl-text > p:first-child{
    padding-left: 5px;
}
.event-info-tl-icon {
    float:right;
    margin:0;
}
.event-icon {
    padding:5px;
    font-size: 20px;
    margin:0;
}

@media (max-width: 576px) {
    .container {
        padding:0;
    }
}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container">
    <div class="row event">
        <div class="col-xs-3 col-sm-2 col-md-1 event-date">
            <h3>9</h3>
            <h3>May</h3>
        </div>
        <div class="col-xs-9 col-sm-10 col-md-1 no-padding-left event-info">
            <div class="event-info-title">
                <h4>Title</h4>
            </div>
            <div class="event-info-tl ">
                <div class="event-info-tl-text ">
                <div class="col-xs-12 col-sm-6">
                
               
                    <p><span class="glyphicon glyphicon-time" aria-hidden="true"></span> Time</p>
                     </div>
                     <div class="col-xs-12 col-sm-6">
                    <p><span class="fa fa-map-marker" aria-hidden="true"></span>Post code</p>
                     </div>
                </div>
                <div class="event-info-tl-icon">
                    <p class="event-icon"><span class="fa fa-chevron-right" aria-hidden="true"></span></p>
                    <div style="clear: both;"></div>
                </div>
            </div>
        </div>
    </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以使用上/下填充在标题/时间/邮政编码文本上方/下方创建空格并删除固定高度。绝对定位右箭头。并在容器上使用white-space: nowrap来获取您不想破坏的2行文本。

.body {
  font-family: 'Open Sans';
}

.no-padding-left {
  padding-left: 0!important;
}

.float-right {
  float: right;
}

.event-date {
  border-right: 1px solid black;
  text-align: center;
}

.event-date > h3 {
  font-weight: bold;
  text-transform: uppercase;
  padding: 0;
  margin: 0;
  line-height: 34px;
}

.event-info-title,
.event-info-tl {
  padding: .5em 0;
}

.event-info-title > h4 {
  padding: 0 0 0 5px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin: 0;
  top: 25%;
  position: relative;
}

.event-info-tl {
  border-top: 1px solid black;
  position: relative;
  overflow: hidden;
}

.event-info-tl > div {
  display: inline-block;
}

.event-info-tl-text {
  top: 25%;
  position: relative;
  white-space: nowrap;
}

.event-info-tl-text > p {
  display: inline-block;
  margin: 0;
}

.event-info-tl-text > p:first-child {
  padding-left: 5px;
}

.event-info-tl-icon {
  position: absolute;
  top: .5em;
  right: 0;
}

.event-icon {
  font-size: 20px;
  margin: 0;
}

@media (max-width: 576px) {
  .container {
    padding: 0;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<div class="container">
    <div class="row event">
        <div class="col-xs-3 col-sm-2 col-md-1 event-date">
            <h3>9</h3>
            <h3>May</h3>
        </div>
        <div class="col-xs-9 col-sm-10 col-md-1 no-padding-left event-info">
            <div class="event-info-title">
                <h4>Title</h4>
            </div>
            <div class="event-info-tl">
                <div class="event-info-tl-text">
                    <p><span class="glyphicon glyphicon-time" aria-hidden="true"></span> Time</p>
                    <p><span class="fa fa-map-marker" aria-hidden="true"></span> Post code</p>
                </div>
                <div class="event-info-tl-icon">
                    <p class="event-icon"><span class="fa fa-chevron-right" aria-hidden="true"></span></p>
                    <div style="clear: both;"></div>
                </div>
            </div>
        </div>
    </div>
</div>

答案 2 :(得分:0)

使用overflow隐藏它怎么样?我添加了最后这两个类:

.event-info-tl-text{width:90%; line-height: 1.1em; height: 1.1em; overflow:hidden;white-space: nowrap;}
.event-info-tl-icon{width:5%}

这里有fiddle