تخطيط الشبكة - Grid Layout
تخطيط الشبكة Grid Layoutتوفر CSS Grid Layout Module نظام تخطيط قائم على الشبكة ، مع صفوف وأعمدة ، مما يسهل تصميم صفحات الويب دون الحاجة إلى استخدام floats و positioning.
مثال عملي للتخطيط بالGrid
الكود الكامل
<!DOCTYPE html>
<html>
<head>
<base href="https://test-app-host.web.app/img/">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/boxicons@latest/css/boxicons.min.css" />
<link href="https://fonts.googleapis.com/css2?family=Almarai:wght@300&family=Cairo:wght@200&display=swap" rel="stylesheet">
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body, button, div, html, input, label, p, select, span, textarea {
font-family: 'Almarai', sans-serif;
font-family: 'Cairo', sans-serif;
}
a {
color: #2c3e50;
text-decoration:none;
}
ol, ul {
padding: 0;
margin: 0;
}
ul {
list-style: none;
}
html, img {
max-width: 100%;
}
span {
font-style: inherit;
font-weight: inherit;
}
img {
height: auto;
max-width: 100%;
}
.container{
width: 100%;
flex-grow: 1;
margin: 0 auto;
position: relative;
width: auto;
}
.product-center {
display: grid;
grid-template-columns: repeat(4,1fr);
gap: 15px;
}
.product {
height: auto;
background-color: #fff;
box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 15%);
border-radius: 5px;
transition: all .3s ease-in-out;
padding: 0!important;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.product:hover{
box-shadow:0 .5rem 1.5rem rgba(0,0,0,.25)
}
.product:hover .product-header:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
border-radius: 1rem 1rem 0 0;
background-color: rgba(0, 0, 0, 0.5);
transition: all 0.5s ease-in-out;
z-index: 1;
}
.product-header {
position: relative;
background-color: #f6f2f1;
transition: all .3s ease-in-out;
z-index: 0;
}
.product-header img {
width: 100%;
height: auto;
}
.product-footer {
padding: 10px;
line-height:1.8rem;
}
.nav, .nav-b {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
flex-direction: row;
align-items: center;
}
.section {
padding: 3rem 1.5rem;
}
.product:hover .icons {
opacity: 1;
transform: translateY(-50%) scale(1);
}
.product-header .icons {
position: absolute;
right: 5%;
top: 50%;
transform: translateY(-50%) scale(0);
z-index: 2;
opacity: 0;
transition: all .5s ease-in-out;
}
.product-header .icons span {
background-color: #fff;
color:#799;
font-size: 1.7rem;
display: block;
border-radius: 50% ;
padding: 0.8rem 0.8rem;
cursor: pointer;
transition: all .3s ease-in-out;
display: flex;
align-items: center;
justify-content: center;
}
.product-header .icons span:not(:last-child) {
margin-bottom: 1rem;
}
.product-header .icons span:hover {
background-color: #ff7d9d;
color: #fff;
}
.product-header .icons span i {
transition: all 500ms ease-in-out;
}
.product-header .icons a {
display: block;
margin-bottom: 1rem;
}
.rating {
color: #ffc107;
font-size:18px;
}
.tag:not(body).is-danger {
background-color: #f14668;
color: #fff;
padding-left: 0.75em;
padding-right: 0.75em;
border-radius:3px;
font-size: 12px;
}
@media screen and (min-width: 1408px){
.container:not(.is-max-desktop):not(.is-max-widescreen) {
max-width: 1344px;
} }
@media screen and (min-width: 1216px){
.container:not(.is-max-desktop) {
max-width: 1152px;
}
}
@media only screen and (min-width: 1200px){
.container {
max-width: 1170px;
}}
@media screen and (min-width: 1024px){
.container {
max-width: 960px;
}}
@media (max-width: 850px){
.product-center {
grid-template-columns: repeat(3,1fr);
}
}
@media (max-width: 640px){
.product-center {
grid-template-columns: repeat(2,1fr);
}
.product-header .icons span {
background-color: #fff;
color:#799;
font-size: 1.3rem;
}
.product-header .icons span:not(:last-child) {
margin-bottom: 0.5rem;
}
}
@media (max-width: 370px){
.product-center {
grid-template-columns: repeat(1,1fr)!important;
}}
</style>
</head>
<body dir='rtl'>
<div class="container">
<div class="section">
<div class="product-center">
<div class="product">
<div class="product-header">
<img src="product-1.ede54a5b.jpg" alt="">
<ul class="icons">
<span><i class="bx bx-heart"></i></span>
<span><i class="bx bx-shopping-bag"></i></span>
<span><i class="bx bx-search"></i></span>
</ul>
</div>
<div class="product-footer">
<a href="#"><h3>لحم طازج بقري</h3></a>
<div class="nav">
<div class="rating">
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bx-star"></i>
</div>
<div>( 65 )</div>
</div>
<div class="nav">
<h4 class="price">$50</h4>
<h4 class="tag is-danger">sall 20% </h4>
</div>
</div>
</div>
<div class="product">
<div class="product-header">
<img src="product-4.6fe66382.jpg" alt="">
<ul class="icons">
<span><i class="bx bx-heart"></i></span>
<span><i class="bx bx-shopping-bag"></i></span>
<span><i class="bx bx-search"></i></span>
</ul>
</div>
<div class="product-footer">
<a href="#"><h3>عنب طازج</h3></a>
<div class="nav">
<div class="rating">
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bx-star"></i>
</div>
<div>( 65 )</div>
</div>
<div class="nav">
<h4 class="price">$50</h4>
<h4 class="tag is-danger">sall 20% </h4>
</div>
</div>
</div>
<div class="product">
<div class="product-header">
<img src="product-2.eebc4b18.jpg" alt="">
<ul class="icons">
<span><i class="bx bx-heart"></i></span>
<span><i class="bx bx-shopping-bag"></i></span>
<span><i class="bx bx-search"></i></span>
</ul>
</div>
<div class="product-footer">
<a href="#"><h3>عنب طازج</h3></a>
<div class="nav">
<div class="rating">
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bx-star"></i>
</div>
<div>( 65 )</div>
</div>
<div class="nav">
<h4 class="price">$50</h4>
<h4 class="tag is-danger">sall 20% </h4>
</div>
</div>
</div>
<div class="product">
<div class="product-header">
<img src="product-3.ff13436e.jpg" alt="">
<ul class="icons">
<span><i class="bx bx-heart"></i></span>
<span><i class="bx bx-shopping-bag"></i></span>
<span><i class="bx bx-search"></i></span>
</ul>
</div>
<div class="product-footer">
<a href="#"><h3>عنب طازج</h3></a>
<div class="nav">
<div class="rating">
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bxs-star"></i>
<i class="bx bx-star"></i>
</div>
<div>( 65 )</div>
</div>
<div class="nav">
<h4 class="price">$50</h4>
<h4 class="tag is-danger">sall 20% </h4>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>