Text over image - responsive

拟墨画扇 提交于 2019-12-30 03:25:09

问题


this is my first question soo... i have to do someting like this:

but i search a lot and nothing work for me, i had something like this in my html and css

.thumbnail {
    position: relative;
    margin-bottom: 0;
    border: 0;
    border-color: transparent;
}

.caption {
    position: absolute;
    top: 40%;
    left: 0;
    width: 100%;
}
  <div id="box-search">
      <div class="thumbnail text-center">
          <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Granola03242006.JPG/280px-Granola03242006.JPG" alt="">
          <div class="caption">
              <p>contacto@windberg.cl</p>
              <p>+56983874071   |   +56228231294</p>
              <p>El Aguilucho 3174, Providencia, Región Metropolitana</p>
          </div>
      </div>
  </div>

that work, but when i use the responsive mode from chrome, the text leave the image

(sorry for my english, i speak spanish)


回答1:


img {
    display: block;
}

.thumbnail {
    position: relative;
    display: inline-block;
}

.caption {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate( -50%, -50% );
    text-align: center;
    color: white;
    font-weight: bold;
}
<div id="box-search">
      <div class="thumbnail">
          <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Granola03242006.JPG/280px-Granola03242006.JPG" alt="">
          <div class="caption">
              <p>contacto@windberg.cl</p>
              <p>+56983874071   |   +56228231294</p>
              <p>El Aguilucho 3174, Providencia, Región Metropolitana</p>
          </div>
      </div>
  </div>


来源:https://stackoverflow.com/questions/43333495/text-over-image-responsive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!