【问题标题】:How to make an image mobile friendly?如何使图像移动友好?
【发布时间】:2018-03-03 20:10:17
【问题描述】:

我正在为某人建立一个网站,但不知何故,我无法使标题中的图像保持在应有的位置。我正在使用@mobile 来确定屏幕宽度,但它仅适用于我的计算机屏幕。当我移动到另一台计算机时,它总是在左侧或底部。

代码:

@media (min-width: 1203px) {
  #profile {
    position: relative;
    margin-top: -35.5%;
    margin-left: -31%;
    float: left; 
    padding-left: 12%
  }
  #mishpat {
    padding-top: 150px;
  }
}
@media (max-width: 1203px) {
  #profile {
    position: relative;
    margin-top: -40.4%;
    margin-left: -35%;
    padding-left: 16%;
    padding-top: 6%; 
    float: left;
  }
  #mishpat {
    padding-top: 150px;
  }
}
@media (max-width: 1025px) {
  #profile {
    position: relative;
    margin-top: 3.5%;
    margin-left: 10%;
    padding-left: 16%;
    padding-top: 0px;
    float: left;
  }
  #mishpat {
    padding-top: 150px;
    padding-left: 0px;
  }
}
@media (max-width: 991px) {
  #profile {
    position: relative;
    margin-top: 1%;
    margin-left: 8%;
    float: left;
    bottom: 46px;
    margin-bottom: -150px;
  }
}
@media (max-width: 767px) {
  #profile {
    position: relative; 
    margin-top: 2%;
    margin-left: -15%; 
    float: left; 
    bottom: 46.5px;
  }
}
@media (max-width: 470px) {
  #profile {
    position: relative;
    margin-top: 18%;
    margin-left: -8%;
    float: left;
    max-width: 100%;
    padding-top: 25%;
  }
}
 <header class="masthead text-center text-white d-flex">
          <div class="layer">
          </div>
          <div class="container my-auto">
              <div class="row">
                  <div id="mishpat" class="col-lg-10 mx-auto">
                      <h1 class="text-uppercase">
                          <strong>ד"ר מריאנה ירון</strong>
                      </h1>
                      <hr>
                  </div>
                  <div class="col-lg-8 mx-auto">
                      <p class="text-faded mb-5">מומחית ברפואה פנימית ואנדוקרינולוגיה</p>

                  </div>
                  <div class="col-lg-10 mx-auto">
                      <img id="profile" src="C:\Users\alonbarel336\source\repos\WebSite1\yaron 2\img\portfolio\thumbnails\3.jpg" class="img-responsive" width="520" height="700">
                  </div>
              </div>
          </div>
      </header>

这里有一张图片来展示它的样子:

我怎样才能让它在它穿过蓝线之前停止(流到下一行)?

the new look after fixing with bootstrap 4

【问题讨论】:

  • 使用溢出:隐藏;到 css 中的特定图像标签
  • 没有改变任何东西@narayanmaity
  • 试试这个属性 z-index:1;到第 2 节或蓝色部分 z-index 仅适用于定位元素(绝对、固定、相对)尝试这也为该图像提供 z-index:0;

标签: html css twitter-bootstrap bootstrap-4


【解决方案1】:

要使图像具有响应性,请执行以下操作:

  1. img-responsive 替换为img-fluid。 (Bootstrap 4 中没有 img-responsive

  2. 删除width="520" height="700"

【讨论】:

  • 您能解释一下“删除所有自定义 css 并用本机 Bootstrap 4 类替换它”是什么意思吗?比如哪些课程,我如何在互联网上找到这些课程,以便了解我在做什么?
  • 删除 float:left 并用 Bootstrap 4 间距类替换您的边距和填充规则:getbootstrap.com/docs/4.0/utilities/spacing
  • 我删除了最后一点,因为这对于使图像“适合移动设备”并不是真正必要的。但是您的代码还有其他问题。但是,由于您尚未发布 minimal reproducible example,因此我的回答回答了有关使图像具有一般响应性的问题。
  • 你的意思是要查看整个html和css代码
  • 好的,我按照你说的做了,并且图像对左侧有响应(它坚持应该在左侧并远离文本的位置。)但水平线保持不变是的,所以当我改变窗口的大小时,它看起来像这样(编辑后的帖子),所以现在我唯一的问题是我希望图片粘在蓝线上。感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-01
  • 2023-03-15
  • 1970-01-01
  • 2022-12-31
  • 2017-04-04
  • 2018-05-08
  • 2019-06-26
相关资源
最近更新 更多