html - 使 div 水平工作

标签 html css responsive-design

我的网站上有 3 个单选按钮。这些单选按钮水平对齐。现在的问题是,我设计了响应式网站,我希望只要屏幕分辨率小于 768px,单选按钮就可以垂直显示。 我到目前为止所做的是 HTML

<div style="float:left;width:60%;">
                <div class="radio"><input type="radio">Confirm</div>
                <div class="radio"><input type="radio">Not Confirm</div>
                <div class="radio"><input type="radio">Extend</div>
</div>  

CSS

.radio{
   float:left; 
   width:33%;
}

这适用于单选按钮的水平对齐。

但这是我尝试的垂直,它没有响应

@media only screen and (max-width: 768px) {
   .radio{
    width:33%;
 }
}

请帮忙

最佳答案

你需要添加clear:both;

@media only screen and (max-width: 768px) {
   .radio{
    width:33%;
    clear:both;
 }
}

如果使用float left所有会出现的元素就不会使用clear: both;

这个通用的方法

.clearfix:after {
     visibility: hidden;
     display: block;
     font-size: 0;
     content: " ";
     clear: both;
     height: 0;
     }
.clearfix { display: inline-block; }
/* start commented backslash hack \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* close commented backslash hack */

关于html - 使 div 水平工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24568873/

相关文章:

jquery - 每当我单击文本区域时页面就会刷新,不允许我填写任何文本

html - 在鼠标悬停时在光标下方添加图像

php - 我想修复响应式 WordPress 功能框

css - sass 媒体查询最小宽度的意外行为

javascript - maplibre-gl-js : load offline (local) glyphs, sprites 和 mbtiles - HTML 网站

html - 将 div 悬停在 div 中

html - 是否有实现此设计的响应方式?

html - 为什么在移动设备上使用百分比设置默认 html 字体大小会导致问题

javascript - 所以我有这个书签,但我不喜欢窗口的位置。我怎样才能把它放在左下角,而不是右上角?

css - 仅限 Chrome : Fixed Div w/Google Map scrolls when other div scrolls