简体   繁体   English

绝对正方形的响应网格

[英]Responsive grid of absolute squares

I'm trying to create an responsive grid of absolutely defined squares. 我正在尝试创建一个绝对定义的正方形的响应式网格。 By that, I mean that I need the squares to be in certain positions within their parent element, and so when the page re-sizes I want the squares to scale with their parent but not to shift between lines. 那样的话,我的意思是我需要将正方形放置在其父元素内的某些位置,因此,当页面调整大小时,我希望正方形与它们的父元素一起缩放而不在行之间移动。

Say for instance, I have a grid of 3x3 squares: 举例来说,我有一个3x3正方形的网格:

----------------
| A  | B  | C  |
----------------
| D  | E  | F  |
----------------
| G  | H  | I  |
----------------

I need the whole thing to be able to resize easily, with the rows and columns of the squares inside staying the same. 我需要整个东西能够轻松调整大小,而正方形的行和列保持不变。

I've had a couple of tries at this, but I always run into problems getting the heights to work well. 我对此进行了几次尝试,但始终遇到问题,无法使高空工作正常。

If you have any ideas, they would be greatly appreciated! 如果您有任何想法,将不胜感激!

John 约翰

May be you can use this? 也许您可以使用此功能?

Fiddle: http://jsfiddle.net/Preben/dkeccbwo/ 小提琴: http : //jsfiddle.net/Preben/dkeccbwo/

I don't know if you are going to have text or images as content, so this is as far as I can take it right now. 我不知道您是否将文字或图像作为内容,所以据我目前所知。 You of course need to adjust more to your liking and purpose: 您当然需要根据自己的喜好和目的进行更多调整:

<div class="myrow">
  <div class="box">A</div>
  <div class="box">B</div>
  <div class="box">C</div>
</div>

<div class="myrow">
  <div class="box">D</div>
  <div class="box">E</div>
  <div class="box">F</div>
</div>

<div class="myrow">
  <div class="box">G</div>
  <div class="box">H</div>
  <div class="box">I</div>
</div>

CSS: CSS:

.myrow {width:100%;border:1px dashed grey; margin-bottom:10px;display:table;}
.box {width:29%;min-height:80px;float:left;margin:2%;background-color:#cecece;}

在此处输入图片说明

IN the div.box you can add square images that are set to be width:100% and then they will scale down and keep the aspect ratio. 在div.box中,您可以添加设置为width:100%的正方形图像,然后它们将按比例缩小并保持纵横比。

OR you may like to use tables (yes, for some content and purposes tables are still worth to look into). 或者您可能想使用表格 (是的,出于某些内容和目的,表格仍然值得研究)。 For instance a Bootstrap table if you already use Bootstrap CSS: http://getbootstrap.com/css/#tables 例如,如果您已经使用Bootstrap CSS,则使用Bootstrap表: http : //getbootstrap.com/css/#tables

 function resizeChild(){ var wid = $('.child:first').width(); $('.child').css('height', wid); } $(function(){ resizeChild(); $(window).resize(resizeChild); }); 
 .parent{ max-width: 900px; font-size: 0; } .child{ display: inline-block; font-size: 14px; width: 33.33%; text-align: center; border: 1px dotted #000; box-sizing: border-box; } .child::after{ content: ""; width: 1px; height: 100%; position: relative; display: inline-block; vertical-align: middle; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="parent"> <div class="child">a</div> <div class="child">b</div> <div class="child">c</div> <div class="child">d</div> <div class="child">e</div> <div class="child">f</div> <div class="child">g</div> <div class="child">h</div> <div class="child">i</div> </div> 

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

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