使用文字

时间:2016-06-13 18:53:50

标签: html css

我有以下内容。但是,我一直试图让蓝色标题区域扩大,而外部div和箭头在中间对齐。我有一个外部div设置为25%,所以文本包装。



.breakingNewsRec {
  width: 100%;
  background: #FFF;
  position: relative;
  border: solid 2px #6A7791;
}
.breakingNewsRec>.bn-rec {
  width: auto;
  display: inline-block;
  background: #6A7791;
  position: relative;
  margin-right: 20px;
}
.breakingNewsRec>.bn-rec>h2 {
  display: inline-block;
  margin: 0;
  padding: 0 20px;
  line-height: 40px;
  font-size: 0.8em;
  color: #FFF;
  box-sizing: border-box;
}
.breakingNewsRec>.bn-rec>span {
  position: absolute;
  right: -10px;
  top: 10px;
  height: 0;
  border-style: solid;
  border-width: 10px 0 10px 10px;
  border-color: transparent transparent transparent #6A7791;
}
.breakingNewsTown {
  width: 100%;
  height: 40px;
  background: #FFF;
  position: relative;
  border: solid 2px #74936A;
}
.breakingNewsTown>.bn-rec {
  width: auto;
  height: 40px;
  display: inline-block;
  background: #74936A;
  position: relative;
  margin-right: 20px;
}
.breakingNewsTown>.bn-rec>h2 {
  display: inline-block;
  margin: 0;
  padding: 0 20px;
  line-height: 40px;
  font-size: 0.8em;
  color: #FFF;
  height: 40px;
  box-sizing: border-box;
}
.breakingNewsTown>.bn-rec>span {
  width: 0;
  position: absolute;
  right: -10px;
  top: 10px;
  height: 0;
  border-style: solid;
  border-width: 10px 0 10px 10px;
  border-color: transparent transparent transparent #74936A;
}

<div style="width: 25%">
  <div class="breakingNewsRec">
    <div class="bn-rec">
      <h2>Recreation News</h2><span></span>
    </div>fdsasdf asdif ksd jfkasjdfasj dfla sjdflj
    <img src="imgs/slides/slide2.jpg" width="25%">asdfljas dflkjsdf alskdjf asdfl</div>
  <div class="breakingNewsTown">
    <div class="bn-rec">
      <h2>Town News</h2><span></span>
    </div>fareveae vasev</div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

我不确定你想要达到的目标,但听起来像这样:

enter image description here

只会将width:100%;应用于.bn-rec

修改

关于你的评论 - 我想我当时明白了。如何围绕<div>中的文字并同时制作<div>个标记display:inline-block;并将其宽度限制为%。然后增加箭头的边距,也像我在这里做的那样:

https://jsfiddle.net/030y329m/

那更接近你的想法吗?

答案 1 :(得分:0)

使用display:table-cell这很容易实现:

&#13;
&#13;
#news {
    width: 50%;
}
#news .item {
    border-width: 1px;
    border-style: solid;
}
#news .item h2 {
    color: white;
    font-size: 100%;
    white-space: nowrap;
    position: relative;
    border-color: inherit;
}
#news .item h2:after {
    content: '';
    display: inline-block;
    border-style: solid;
    border-width: 10px 0 10px 10px;
    border-color: transparent;
    border-left-color: inherit;
    vertical-align: middle;
    position: absolute;
    left: 100%;
}
#news .item h2,
#news .item div {
    display: table-cell;
    vertical-align: middle;
    padding: 0 1.5em;
}
.style1  { border-color: #697791 }
.style1 h2 { background: #697791 }
.style2  { border-color: #74936a }
.style2 h2 { background: #74936a }
&#13;
<div id="news">
    <div class="item style1">
        <h2>Recreation News</h2>
        <div>
            <p>fdsasdf asdif ksd jfkasjdfasj dfla sjdflj asdfljas dflkjsdf alskdjf asdfl</p>
        </div>
    </div>
    <div class="item style2">
        <h2>Town News</h2>
        <div>
            <p>fareveae vasev</p>
        </div>
    </div>
</div>
&#13;
&#13;
&#13;