html - Div 元素在 float : right; 上变形

标签 html css

我希望此图像和文本向右浮动并在它们周围保持一定距离,但它们会拉伸(stretch)默认分辨率并在 float: right; 上过度 float 。

#pageMain {
  margin: 100px;
}

#aboutGame {
  float: right;
  width: 420px;
  padding: 10px;
}

#aboutGame span {
  width: ;
  font-size: 20px;
  font-family: 'Lato', sans-serif;
}

#aboutGame img {
  border: 3px solid black;
}
<section id="pageMain">
  <div id="aboutGame">
    <span>
			As if awakening from a deep sleep, you find yourself in a strange, contradictory world of ancient ruins and advanced technology. Tasked by your creator with solving a series of increasingly complex puzzles, you must decide whether to have faith, or to ask the difficult questions: Who are you? What is your purpose and what are you going to do about it? </span>
    <img src="http://cdn.akamai.steamstatic.com/steam/apps/257510/ss_ded5cd1a34df5b4d9015f71caf35db247b2579c4.1920x1080.jpg?t=1498680189" height="500px" width="800px" />
  </div>
</section>

最佳答案

#pageMain {
  margin: 100px;
  overflow: hidden;
}

#aboutGame {
  float: right;
  width: 420px;
  padding: 10px;
}

#aboutGame span {
  width: ;
  font-size: 20px;
  font-family: 'Lato', sans-serif;
}

#aboutGame img {
  border: 3px solid #000;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 20px 0;
}
<section id="pageMain">
  <div id="aboutGame">
    <span>
			As if awakening from a deep sleep, you find yourself in a strange, contradictory world of ancient ruins and advanced technology. Tasked by your creator with solving a series of increasingly complex puzzles, you must decide whether to have faith, or to ask the difficult questions: Who are you? What is your purpose and what are you going to do about it? </span>
    <img src="http://cdn.akamai.steamstatic.com/steam/apps/257510/ss_ded5cd1a34df5b4d9015f71caf35db247b2579c4.1920x1080.jpg?t=1498680189" height="500px" width="800px" />
  </div>
</section>

我认为这就是您想要做的,所以我为图像标记添加了一些样式并溢出:隐藏到父 #pageMain div。因为它的子元素是 float 的并且它有清除问题。

关于html - Div 元素在 float : right; 上变形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49456196/

相关文章:

android - 聚焦时无法设置 android 4.x 上的输入元素的样式

css - 隐藏的 Div 未正确显示

jquery - 浏览器和媒体查询中的不同分辨率

javascript - 强制在 HTML 或 JavaScript 中进行初始缩放

html - 如何创建响应式 .SVG 并将其用作 mask ?

javascript - 如何使用JQUERY或JAVASCRIPT将IOS键盘中的 "Return"按钮更改为 "Next"按钮?

android - 从WebView获取网站源码

html - 我如何垂直居中 ul 中的 li 元素? CSS

css - 针对不同分辨率优化页面

jquery - 仅针对父表添加 thead 并从 tbody 插入第一个 tr