2017-02-26 144 views
1

我无法在透明div上设置非透明字体。透明div上的不透明字体

enter image description here

我用这个CSSh3,但它不工作。

.posterTextContainer { 
    position: absolute; 
    width: 100%; 
    background-color: orange; 
    left: 0; 
    bottom: 0; 
    z-index: 5; 
    text-align: center; 
    display: block; 
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; 
    filter: alpha(opacity=70); 
    opacity: 0.7 !important; 
    -moz-opacity: 0.7; 
    -khtml-opacity: 0.7; 
} 

    .posterTextContainer > h3 { 
     font-weight: bold; 
     color: white !important; 
     -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"!important; 
     filter: alpha(opacity=100)!important; 
     opacity: 1.0 !important; 
     -moz-opacity: 1.0 !important; 
     -khtml-opacity: 1.0 !important; 
     text-transform: uppercase; 
     margin: 0.4em 0.7em 0.5em 0.7em !important; 
     white-space: nowrap; 
     overflow: hidden !important; 
     text-overflow: ellipsis; 
    } 

HTML

<div id="premieresList" class="owl-carousel owl-theme classPremieres" style="display:block; width:100%!important; height:auto!important;"> 
      @if (ViewBag.Premieres != null) 
      { 
       foreach (var item in (List<.FilmView>)ViewBag.Premieres) 
       { 
        <div class="item" style="width:100%!important;"> 
         <img class="owl-lazy" data-src="@item.FileUrl" alt="" style="border: 1px solid hsla(30, 96%, 52%, 0.6);" /> 
         <div class="posterTextContainer"> 
          <h3> 
           @item.Title.ToUpper() 
          </h3> 
         </div> 
        </div> 
       } 
      } 
     </div> 

请帮助我。谢谢!

+2

邮政所有代码,所以我们有一个[MCVE] –

+0

@MichaelCoker我没有,它覆盖证明彼此的代码。 –

+0

@Dimo - 好像你应该。你的HTML在哪里?图像在哪里? –

回答

1

基本上所有你需要做的是包装你的图片和标题文本中的一个元素,而无论是浮空包装它们的元素或将其设置为inline-block的,这样它会符合图像的形状。然后将其设置为position: relative,将标题设置为position: absolute,然后使用rgba()(使用Alpha透明度)作为标题的背景颜色。

.posterTextContainer { 
 
    display: inline-block; 
 
    position: relative; 
 
    background: orange; 
 
    padding: 2px; 
 
} 
 

 
.posterTextContainer > h3 { 
 
    font-weight: bold; 
 
    color: white !important; 
 
    text-transform: uppercase; 
 
    margin: 0; 
 
    white-space: nowrap; 
 
    overflow: hidden !important; 
 
    text-overflow: ellipsis; 
 
    background: rgba(255,165,0,0.5); 
 
    position: absolute; 
 
    bottom: 0; 
 
    left: 0; right: 0; 
 
    text-align: center; 
 
    padding: .5em 0; 
 
} 
 

 
img { 
 
    max-width: 100%; 
 
    display: block; 
 
}
<div class="posterTextContainer"> 
 
    <img src="https://pmcvariety.files.wordpress.com/2016/06/inferno-movie-tom-hanks.jpg?w=1000&h=563&crop=1"> 
 
    <h3>text</h3> 
 
</div>

-1

变化opacity:1.0喜欢的东西opacity:0.6

+0

我做到了,但不起作用。 –

+0

在小提琴上为我工作 – James

+0

添加图像,然后 – James