简体   繁体   English

移动设备上3格的宽度从33.33%更改为100%

[英]3 Divs with 33.33% width change to 100% width on mobile

I know how to do this with javascript I'm just wondering if there is some fancy css that can do this. 我知道如何用JavaScript做到这一点,我只是想知道是否有一些花哨的CSS可以做到这一点。 I want it so that when I go mobile each div takes the entire screen. 我想要它,这样当我移动时每个div都会占据整个屏幕。 Here's what it currently looks like. 这是目前的样子。

我目前的样子

Here's some css for each div. 这是每个div的一些CSS。

.center{


background-color:#ffffff;
  width:33.33%;
  height: 100%;
  display: inline-block;

}

.left{
  background-color:#ffffff;
  width:33.33%;
  height: 100%;
  float:left;
    overflow: hidden;

}

.right{
  background-color:#ffffff;
  width:33.33%;
  height: 100%;
  float:right;
   overflow: hidden; 
}

Decide at what resolution you want the divs to take up all the width, and apply different styling based on media queries . 确定您希望div占据所有宽度的分辨率,并根据媒体查询应用不同的样式。 This is how bootstrap does it. 引导程序就是这样做的。

Basic Example at a 600px wide breakpoint. 600px宽断点处的基本示例。

@media (max-width: 600px) {
  .mybox {
    width:100%;
  }
}

Definitely there are 'fancy' ways in css too which you can use for the same. 肯定在css中也有“花哨”的方法,您也可以使用这些方法。 First you can use the bootstrap library to make you html responsive. 首先,您可以使用引导程序库使您的HTML响应。 you can refer the following link: http://getbootstrap.com/ 您可以参考以下链接: http : //getbootstrap.com/

Also, you can use the css media queries which can do the same task. 另外,您可以使用可以执行相同任务的CSS媒体查询。 here is the link for the same: https://www.w3.org/TR/css3-mediaqueries/ 这是相同的链接: https : //www.w3.org/TR/css3-mediaqueries/

choose the resolution which you want and apply the you css. 选择所需的分辨率并应用CSS。

@media (min-width:320px)  { /* smartphones, iPhone, portrait 480x320 phones */ }
@media (min-width:481px)  { /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */ }
@media (min-width:641px)  { /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ }
@media (min-width:961px)  { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
@media screen and (max-width: 600px) {
    .center,
    .left,
    .right {
        width: 100%;
    }
}

If screen width is smaller than 600px then divs became 100% width. 如果屏幕宽度小于600像素,则div变为100%宽度。

You can change value of max-width adapting to yours need 您可以根据需要更改最大宽度的值

For conditional formatting with css, you can use media queries. 对于使用CSS的条件格式,可以使用媒体查询。 Unfortunatly there is no media query for mobile. 不幸的是,没有针对手机的媒体查询。 You can however set a max. 但是,您可以设置最大 width. 宽度。 For example: 例如:

@media only screen and (max-device-width: 600px){ 
    ... 
}

This way, any device with a screen width smaller then 600px will get the css that is on the ... . 这样一来,有屏幕的任何设备宽度则600px的将获得的CSS是在...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM