html - 如何让这个带有 float 响应的div?

标签 html css responsive-design

我做了一个小的 html 字段,现在我试图让它响应。 为了清楚起见,我制作了一张图片,显示在较小的屏幕上时字段应该如何移动。 How it should be

在弄清楚几个小时后,我得到了这个解决方案,它在桌面上运行良好,但在较小的屏幕上运行不佳。 Logo 没有移动到顶部,而是保留在左侧。

有人可以帮我解决这个问题吗?

代码如下:

    <div style="background-color: orange; color: white; width: 30%; padding: 4px 4px; text-align: center; margin:0">Stackoverflow</div>
<div style="background-color: #f9f9f9; border: 2px solid orange; max-width:800px; overflow: auto;">
    <div style="float: left;width: 30%; overflow: auto;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7A3wAuudoXw8butMA-wxJdWYdUlNbWjC6EOV3iXnrUf08dwX3PA" /></div>
    <div style="float:left;width:70%">
            <div style="text-align: center; font-size: 12pt; background-color:lightgreen">Some Informations
            </div>  
            <div>     
              <div style="float: left; background-color: lightblue; width:50%">
                  <ul>
                <li>Owner: Stack Exchange, Inc.</li>
                <li>Available in: Englisch, Spanisch, Russian, Portuguese ...</li>
                <li>Type of site: Knowledge markets</li>
              </ul> 
          </div>
          <div style="float: right; background-color: lightgrey; width:50%; padding:5px">
              <ul>
                <li>Website: stackoverflow.com</li>
                <li>Commercial: Yes</li>
                <li>Registration: Optional</li>
              </ul>

            <div style="float: left; width: auto; background-color:yellow">Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming.
            </div>
            <div style="clear:both;text-align: center;"><a href="https://www.stockoverflow.com"> <input type="button" value="Go to the Website" /></a>
            </div>

    </div>
</div>

最佳答案

为了根据屏幕分辨率更改样式,您可以使用媒体查询

@media (max-width: 1024px) { 
   .logo{
      width: 100%;
   }
}

将类添加到您的元素,以便能够使用特定的 css 规则来定位它们:

<div style="float: left;width: 30%; overflow: auto;">

成为

<div class = "logo">
...
<style>
    .logo{
      float: left;
      width: 30%;
      overflow: auto;
    }
</style>

关于html - 如何让这个带有 float 响应的div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54027049/

相关文章:

javascript - 切换菜单未显示 - Bootstrap 3

html - 使用 flexbox 在 DIV 中居中左对齐元素

html - 如何使用 CSS 定位此图像,使其与 div 重叠但内联显示?

html - 响应式 css 不适用于横向

css - 基金会的网格系统 : Hiding an element when screen becomes smaller doesn't work

javascript - 使用 jQuery 从一个字符串输入中获取动态输入值

javascript - 为&lt;script&gt;标签添加动态头参数值,用于加载js文件

html - 哪个 CSS 属性可用于控制控件的伸缩性?

javascript - 通过合并对象属性在表中添加列

twitter-bootstrap - 如何从 Twitter Bootstrap 3 中完全关闭响应功能?