⊗mkSpRsTG 127 of 128 menu

ადაპტური ბლოკები (ფილები) CSS-ში გარეთა არჩით

ახლა მოდით გავაკეთოთ ბლოკები (ფილები) გარეთა არჩით. აი მაგალითი იმისა, თუ რა უნდა მივიღოთ:

დავიწყოთ მშობელი ელემენტის სტილების გაკეთებით:

.parent { display: flex; flex-wrap: wrap; width: 95%; margin: 50px auto; }

ახლა მივცეთ სტილები თავად ბლოკებს, მათ სიგანეს არ ვანიჭებთ, მაგრამ ვანიჭებთ ქვედა გარეთა არჩს პროცენტებში:

.child { box-sizing: border-box; height: 100px; padding: 20px; margin-bottom: 1.5%; border: 1px solid green; }

ახლა დავწეროთ კოდი, რომელიც ზედიზედ ოთხ ბლოკს დადებს, შესაბამისი გარეთა არჩების მინიჭებით:

@media (min-width: 1000px) { .child { width: calc(100% / 4 - 1.5% * 3 / 4); } .child:not(:nth-child(4n)) { margin-right: 1.5%; } }

ახლა კი ზედიზედ სამი ბლოკი დავდოთ:

@media (min-width: 700px) and (max-width: 1000px) { .child { width: calc(100% / 3 - 1.5% * 2 / 3); } .child:not(:nth-child(3n)) { margin-right: 1.5%; } }

ახლა კი ზედიზედ ორი ბლოკი დავდოთ:

@media (min-width: 400px) and (max-width: 700px) { .child { width: calc(100% / 2 - 1.5% * 1 / 2); } .child:not(:nth-child(2n)) { margin-right: 1.5%; } }

ერთი ბლოკი ზედიზედ:

@media (max-width: 400px) { .child { width: 100%; } }

მოდით, მთელი კოდი ერთად შევკრიბოთ:

.parent { display: flex; flex-wrap: wrap; width: 95%; margin: 50px auto; } .child { box-sizing: border-box; height: 100px; padding: 20px; margin-bottom: 1.5%; border: 1px solid green; } @media (max-width: 400px) { .child { width: 100%; } } @media (min-width: 400px) and (max-width: 700px) { .child { width: calc(100% / 2 - 1.5% * 1 / 2); } .child:not(:nth-child(2n)) { margin-right: 1.5%; } } @media (min-width: 700px) and (max-width: 1000px) { .child { width: calc(100% / 3 - 1.5% * 2 / 3); } .child:not(:nth-child(3n)) { margin-right: 1.5%; } } @media (min-width: 1000px) { .child { width: calc(100% / 4 - 1.5% * 3 / 4); } .child:not(:nth-child(4n)) { margin-right: 1.5%; } }

გააკეთეთ ბლოკები (ფილები), რომლებიც ეკრანის შევიწროებისას თავდაპირველად ექნება ზედიზედ რვა ელემენტი, შემდეგ ზედიზედ ოთხი ელემენტი, შემდეგ კი ზედიზედ ორი ელემენტი. დაე, ელემენტებს შორის გარეთა არჩი იყოს 0.75%.

შეცვალეთ წინა ამოცანა ისე, რომ ელემენტებს შორის გარეთა არჩი იყოს ფიქსირებული მნიშვნელობა 20px.

ქართული
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEnglishEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語Қазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
ვებსაიტის მუშაობის, ანალიტიკისა და პერსონალიზაციისთვის ვიყენებთ ქუქი-ფაილებს. მონაცემთა დამუშავება ხდება Კონფიდენციალურობის პოლიტიკის შესაბამისად.
ყველას მიღება პარამეტრები უარყოფა