【问题标题】:place an image and text side by side inside div将图像和文本并排放置在 div 内
【发布时间】:2018-08-17 17:42:27
【问题描述】:

我想放置一张图片和一些描述它的文字。 这应该是响应式的,即 img 和 text 应该在大屏幕上并排,在小屏幕上从上到下。 所以,基本上,在你标记之前,它与Two Divs next to each other, that then stack with responsive change

完全相同

但这不起作用。

下面是我的代码:

<!DOCTYPE html>
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Hello</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="groupi">
  <div id="one">
    <img src="hello.jpg" style="width:10vw"/>  </div>
  <div id="two">Hello World</a></div>
</div>
</body>
</html>

和css:

* {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  vertical-align: baseline;
  background: transparent;
}
body {
  margin:0;
  font-family: Arial, Helvetica, sans-serif;
}
.groupi { 
  border : 2px solid #000; 
  overflow:hidden;
}
.gruopi div {
   min-height: 200px;
   padding: 10px;
}
#one {
  float: left;
  padding-top:4vw; 
  margin-left:3vw; 
  margin-right: 1vw; 
  margin-bottom: 5vw; 
  width: 10vw;
  border-right:2px solid #000;
}
#two { 
  background-color: black;
  overflow:hidden;
  margin:1vw;
  border:2vw dashed #ccc;
  min-height:2vw;
}
@media screen and (max-width: 600px) {
  .topnav.responsive {position: relative;}
  .topnav.responsive .icon {
    position: absolute;
    right: 0;
    top: 0;
  }
  .topnav.responsive a {
    float: none;
    display: block;
    text-align: left;
  }
  #two{
  }
}

我很新,一些帮助将不胜感激。

【问题讨论】:

    标签: html responsive-design


    【解决方案1】:

    如果您希望您的第二个 div 元素 (#two) 在您的视点宽度小于 600 像素时堆叠,您可以将以下内容添加到您的媒体查询中:

    #one {
       float: none;
    }
    

    所以你的完整媒体查询是:

    @media screen and (max-width: 600px) {
      .topnav.responsive {position: relative;}
      .topnav.responsive .icon {
        position: absolute;
        right: 0;
        top: 0;
      }
      .topnav.responsive a {
        float: none;
        display: block;
        text-align: left;
      }
      #one{
        float: none;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-02-26
      • 1970-01-01
      • 2019-01-07
      • 2022-11-18
      • 2014-04-04
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多