无法将文字放在图像上

时间:2016-07-12 07:33:59

标签: html css image css3

我正在尝试将文字放在图像上,但是当我将文本参数left:分成两半时。

HTML:

<div class="c-subcat-item">
  <div class="pro-img-wrap">
    <div class="pro-img-wrap-in">
      <div class="img-middle-center">
        <a class="img-middle-wrap" href="/Wines/Product/1417">
          <img src="/Images/bottle-red.jpg" alt="Produkt">
        </a>
      </div>
    </div>
  </div>

  <div class="subcat-item-details">
    <div class="product-desc-container">
      <div class="">
        <a class="item-name" href="/Wines/Product/1417">Avilla</a>
        <div class="clearfix"></div>
        <div class="item-our-price">
          <span class="item-sold-out">Chwilowo niedostępny</span>
        </div>
        <div class="item-detail-price">
          <span class="item-price-value">45,00 zł </span>
        </div>
      </div>
      <div class="div-empty-margin"></div>
    </div>
    <div class="clearfix"></div>
    <span class="item-more">
      <a class="item-more" href="/Wines/Product/1417">Zobacz więcej</a>
    </span>
    <div class="div-empty-margin"></div>
    <div class="add-to-cart">
    </div>
  </div>
</div>

CSS:

body {
    background-color: #fffff7;
    color: #666;
    font-family: 'Roboto Condensed',sans-serif;
    font-size: 10px;
    height: 100%;
  margin: 0;}
html, body, .page-wrapper {
    width: 100%;
    min-width: 1024px;
    margin-left: auto;
  margin-right: auto;}
.page-wrapper {
    height: 100%;
}
.page-content-wrapper {
    min-height: 100%;
    text-align: center;
}
.main {
    display: inline-block;
    margin: 20px auto 0;
    margin-bottom: 61px;
    position: relative;
    text-align: left;
    width: 965px;
}
.wrapper {
    float: left;
    margin-bottom: 20px;
    width: 100%;
}
.content {
    float: left;
    width: 100%;
}
.content-main-wrapper1 {
    float: left;
    width: 100%;
}
.content-main-wrapper2 {
    float: left;
    position: relative;
    right: 767px;
    width: 100%;
}
.content-wo-padding {
    float: left;
    left: 768px;
    position: relative;
    width: 726px;
}
.pro-img-wrap {
    float: left;
}

.c-subcat-item {
    float: left;
    padding: 20px;
    position: relative;
    width: 726px;
}
.pro-img-wrap-in {
    border: 1px solid #e8e5e5;
    float: left;
    height: 240px;
    overflow: hidden;
    width: 160px;
    display: table;
}
.img-middle-center {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background: #fff;
    display: table-cell;
    float: none;
    height: 100%;
    width: 100%;
    text-align: center;
    vertical-align: middle;
}
.subcat-item-details {
    float: right;
    height: 242px;
    width: 544px;
    position: relative;
}
.product-desc-container {
    overflow: hidden;
    position: relative;
}
h2.item-name, a.item-name {
    color: #333;
    float: left;
    font-size: 16px;
    font-weight: bold;
    line-height: 15px;
    margin: 2px 0 5px 0;
    padding: 0;
    width: 100%;
    text-transform: uppercase;
}
.clearfix {
    clear: both;
}
.item-our-price {
    float: left;
    margin-top: 10px;
    width: 100%;
}
.item-our-price span.item-sold-out {
    position: relative;
    color: #f00;
    background-color: #fff;
    padding: 10px;
    border: solid 1px #f00;
    font-size: 1.3em;
    cursor: default;
  left: -60px;
}

您可以查看here

3 个答案:

答案 0 :(得分:1)

从班级overflow: hidden;

中删除.product-desc-container

body {
    background-color: #fffff7;
    color: #666;
    font-family: 'Roboto Condensed',sans-serif;
    font-size: 10px;
    height: 100%;
  margin: 0;}
html, body, .page-wrapper {
    width: 100%;
    min-width: 1024px;
    margin-left: auto;
  margin-right: auto;}
.page-wrapper {
    height: 100%;
}
.page-content-wrapper {
    min-height: 100%;
    text-align: center;
}
.main {
    display: inline-block;
    margin: 20px auto 0;
    margin-bottom: 61px;
    position: relative;
    text-align: left;
    width: 965px;
}
.wrapper {
    float: left;
    margin-bottom: 20px;
    width: 100%;
}
.content {
    float: left;
    width: 100%;
}
.content-main-wrapper1 {
    float: left;
    width: 100%;
}
.content-main-wrapper2 {
    float: left;
    position: relative;
    right: 767px;
    width: 100%;
}
.content-wo-padding {
    float: left;
    left: 768px;
    position: relative;
    width: 726px;
}
.pro-img-wrap {
    float: left;
}

.c-subcat-item {
    float: left;
    padding: 20px;
    position: relative;
    width: 726px;
}
.pro-img-wrap-in {
    border: 1px solid #e8e5e5;
    float: left;
    height: 240px;
    overflow: hidden;
    width: 160px;
    display: table;
}
.img-middle-center {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background: #fff;
    display: table-cell;
    float: none;
    height: 100%;
    width: 100%;
    text-align: center;
    vertical-align: middle;
}
.subcat-item-details {
    float: right;
    height: 242px;
    width: 544px;
    position: relative;
}
.product-desc-container {
    
    position: relative;
}
h2.item-name, a.item-name {
    color: #333;
    float: left;
    font-size: 16px;
    font-weight: bold;
    line-height: 15px;
    margin: 2px 0 5px 0;
    padding: 0;
    width: 100%;
    text-transform: uppercase;
}
.clearfix {
    clear: both;
}
.item-our-price {
    float: left;
    margin-top: 10px;
    width: 100%;
}
.item-our-price span.item-sold-out {
    position: relative;
    color: #f00;
    background-color: #fff;
    padding: 10px;
    border: solid 1px #f00;
    font-size: 1.3em;
    cursor: default;
  left: -60px;
}
<div class="c-subcat-item">
  <div class="pro-img-wrap">
    <div class="pro-img-wrap-in">
      <div class="img-middle-center">
        <a class="img-middle-wrap" href="/Wines/Product/1417">                      <img src="/Images/bottle-red.jpg" alt="Produkt">
        </a>
      </div>
    </div>
  </div>

  <div class="subcat-item-details">
    <div class="product-desc-container">
      <div class="">
        <a class="item-name" href="/Wines/Product/1417">Avilla</a>
        <div class="clearfix"></div>
        <div class="item-our-price">
          <span class="item-sold-out">Chwilowo niedostępny</span>
        </div>
        <div class="item-detail-price">
          <span class="item-price-value">45,00 zł </span>
        </div>
      </div>
      <div class="div-empty-margin"></div>
    </div>
    <div class="clearfix"></div>
    <span class="item-more">
      <a class="item-more" href="/Wines/Product/1417">Zobacz więcej</a>
    </span>
    <div class="div-empty-margin"></div>
    <div class="add-to-cart">
    </div>
  </div>
</div>

答案 1 :(得分:0)

overflow:hidden移除.product-desc-container,这是文字在图片上不可见的原因

答案 2 :(得分:0)

overflow:hidden

中删除.product-desc-container

请参阅此处:jsfiddle

代码

.product-desc-container {
/* overflow: hidden; */
position: relative;
}