简体   繁体   English

媒体查询CSS麻烦

[英]Media Queries CSS trouble

I have 2 divs, with IDs re1 and re2 , both of their widths are set to 100% as their max-widths (800px and 400px) mean that both divs will stay on the same line in my container which has a max width of 1200px. 我有2个div,其ID为re1re2 ,两个宽度均设置为100%,因为它们的最大宽度(800px和400px)意味着两个div将停留在容器中的同一行上,最大宽度为1200px 。 This also means that on a mobile phone when the two divs become stacked each div will fill the width of the screen. 这也意味着在移动电话上,当两个div堆叠在一起时,每个div将填充屏幕的宽度。 The problem arises on mid sized screens ie. 问题出现在中等尺寸的屏幕上。 ipad, the size of the screen means that both of the divs go on a separate line, but due to their max-widths they have different sized widths which looks awful. ipad,屏幕的大小意味着两个div都位于单独的行上,但是由于它们的最大宽度,它们具有不同的大小宽度,看起来很糟糕。 So I tried to change their widths using media queries so they would stay on the same line for ipad but it doesn't seem to be working. 因此,我尝试使用媒体查询来更改其宽度,以使它们在ipad上保持一致,但似乎不起作用。

@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px)
and (-webkit-min-device-pixel-ratio: 1)  { 
#re1 { width: 66.67%; }
#re2 { width: 33.33%; }
}

I have tried using the above values as default without the media queries and it has the desired effect, so it is something to do with the query itself. 我尝试使用上述值作为默认值而不使用媒体查询,并且它具有所需的效果,因此这与查询本身有关。 How do I get the divs' widths to change to 66/33% only when viewed on screens of the above resolutions? 仅在上述分辨率的屏幕上查看时,如何才能使div的宽度更改为66/33%?

try this: 尝试这个:

@media all and (max-width: 1024px) and (-webkit-min-device-pixel-ratio: 1)  { 
#re1 { width: 66.67%; }
#re2 { width: 33.33%; }

}

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

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