简体   繁体   English

响应式图像3列布局的问题

[英]Problems with responsive image 3 column layout

I am a student and working on a school project. 我是一名学生,正在做一个学校项目。 I'm working on a responsive grid with 3 columns whenever u resize the widow the image should stay at 100% and only be visible once. 每当您调整寡妇的大小时,我都会在3列响应式网格上工作,图像应保持100%且仅可见一次。

I came into an error with it, when full screen it takes up the full width but when i resize the widow the section overlay each other and only come back to full width (like they are supposed to be at phone size, mediaquery) 我遇到了一个错误,当全屏显示时会占用整个宽度,但是当我调整寡妇的大小时,该部分会相互重叠,并且只会返回到全宽度(例如,它们应该是手机尺寸,mediaquery)

code snippet: 代码段:

 .container { width:100%; height:700px; } .columns { float:left; width:33.33%; height:100vh; } .blue { background-color: #92d2fc; background-image: url(https://placeholdit.imgix.net/~text?txtsize=33&txt=460%C3%97800&w=460&h=800); } .yellow { background-color: #fad74e; background-image: url(https://placeholdit.imgix.net/~text?txtsize=33&txt=460%C3%97800&w=460&h=800); } .red { background-color: #f88888; background-image: url(https://placeholdit.imgix.net/~text?txtsize=33&txt=460%C3%97800&w=460&h=800); } .blue img, .red img, .yellow img { width:100%; } @media screen and (max-width: 700px){ .columns { width:100%; } } 
 <div class="container"> <section class="columns blue"> <h3>About us</h3> <p class="margin-top">How the gym became a reality</p> </section> <section class="columns yellow"> <h3>Manifesto</h3> <p class="margin-top">Respect the rules</p> </section> <section class="columns red"> <h3>Contact us</h3> <p class="margin-top">Have a chat with us</p> </section> </div> 

Thanks in advance! 提前致谢! Distortion 失真

If I'm correct, this is what you are after. 如果我是正确的话,这就是你所追求的。 I make benefit of the 100vw and 100vh values. 我利用了100vw100vh值。

vh 1/100th of the height of the viewport. vh视口高度的1/100。
vw 1/100th of the width of the viewport. vw视口宽度的1/100。

Read more about length at MDN . 了解有关MDN长度的更多信息

Together with the display: flex; 连同display: flex; property ( MDN reference ) it comes in handy to get the whole space filled out. 属性( MDN参考 ),它可以很方便地填充整个空间。

The CSS3 Flexible Box, or flexbox, is a layout mode providing for the arrangement of elements on a page such that the elements behave predictably when the page layout must accommodate different screen sizes and different display devices. CSS3灵活框(即flexbox)是一种布局模式,用于在页面上排列元素,以便当页面布局必须容纳不同的屏幕尺寸和不同的显示设备时,元素的行为可预测。

Also, I started mobile first , so that the min-width is set to 700px , instead of the other way around. 另外,我首先开始移动 ,所以将min-width设置为700px ,而不是相反。 In that way you can scale easily to any size you want. 这样,您可以轻松扩展至所需的任何大小。 You can also use calc(value) function to get 1/3th of the width of your screen width ( MDN reference ). 您还可以使用calc(value)函数来得到的1 / 3TH width屏幕宽度(的MDN参考资料 )。 In that case, replace the width: 33.3%; 在这种情况下,请替换width: 33.3%; with width: calc(100% / 3); width: calc(100% / 3);

 body, html { margin: 0; padding: 0; } .wrapper { width: 100vw; height: 100vh; } .container { width: 100%; height: 100%; display: flex; flex-flow: row wrap; } .columns { width: 100%; } .blue { background-color: #92d2fc; } .yellow { background-color: #fad74e; } .red { background-color: #f88888; } @media screen and (min-width: 700px) { .container { width: 100%; height: 100%; flex-flow: column wrap; } .columns { height: 100%; width: 33.3%; } } 
 <div class="wrapper"> <div class="container"> <section class="columns blue"> <h3>About us</h3> <p class="margin-top">How the gym became a reality</p> </section> <section class="columns yellow"> <h3>Manifesto</h3> <p class="margin-top">Respect the rules</p> </section> <section class="columns red"> <h3>Contact us</h3> <p class="margin-top">Have a chat with us</p> </section> </div> </div> 

I'm not sure I 100% understand your question, but it sounds like your problem is the fixed-width of the background image? 我不确定我是否100%理解您的问题,但是听起来您的问题是背景图片的固定宽度? Try something like background-size: contain; 尝试类似background-size: contain; in your .columns class, or giving the background-size some percentage values. 在您的.columns类中,或为背景尺寸设置一些百分比值。

I upadated your media query and added a class="clearfix" to your container 我更新了您的媒体查询,并向您的容器添加了class="clearfix"

 .container { width:100%; height:700px; } .clearfix:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } .columns { float:left; width:33.33%; height:100vh; } @media screen and (min-width: 700px){ .blue { background-color: #92d2fc; background-image: url(http://previews.123rf.com/images/jaysi/jaysi1112/jaysi111200023/11753777-Golden-temple-near-beautiful-lake-Japan-Vertical-image-Stock-Photo.jpg); } .yellow { background-color: #fad74e; background-image: url(http://previews.123rf.com/images/jaysi/jaysi1112/jaysi111200023/11753777-Golden-temple-near-beautiful-lake-Japan-Vertical-image-Stock-Photo.jpg); } .red { background-color: #f88888; background-image: url(http://previews.123rf.com/images/jaysi/jaysi1112/jaysi111200023/11753777-Golden-temple-near-beautiful-lake-Japan-Vertical-image-Stock-Photo.jpg); } } .blue img, .red img, .yellow img { width:100%; } @media screen and (max-width: 700px){ .columns { width:100%; } .container{ background-image: url(http://previews.123rf.com/images/jaysi/jaysi1112/jaysi111200023/11753777-Golden-temple-near-beautiful-lake-Japan-Vertical-image-Stock-Photo.jpg); background-size:cover; height:auto; } } 
 <div class="container clearfix"> <section class="columns blue"> <h3>About us</h3> <p class="margin-top">How the gym became a reality</p> </section> <section class="columns yellow"> <h3>Manifesto</h3> <p class="margin-top">Respect the rules</p> </section> <section class="columns red"> <h3>Contact us</h3> <p class="margin-top">Have a chat with us</p> </section> </div> 

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

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