Skip to content

CSS Box Web Design


HTML CODE:

<!DOCTYPE html>
<html>
<head>
    <title>page</title>
    <link rel="stylesheet" type="text/css" href="web7.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
</head>
<body>
    <div class="container">
        <!-- box 1 -->
        <div class="box">
            <div class="thumb">
                <img src="https://images.pexels.com/photos/109255/pexels-photo-109255.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" width="100%;">
            </div>
            <div class="details">
                <div class="content">
                    <i class="fas fa-gift" aria-hidden="true"></i>
                    <h3>Lorem</h3>
                    <a href="#">Read More</a>
                </div>
            </div>
        </div>
        <!-- box 2 -->
        <div class="box">
            <div class="thumb">
                <img src="https://images.pexels.com/photos/374074/pexels-photo-374074.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" width="100%;">
            </div>
            <div class="details">
                <div class="content">
                    <i class="fas fa-globe-americas" aria-hiddem="true"></i>
                    <h3>Lorem Ipsum</h3>
                    <a href="#">Read More</a>
                </div>
            </div>
        </div>

        <!-- box 3 -->
        <div class="box">
            <div class="thumb">
                <img src="https://images.pexels.com/photos/34088/pexels-photo.jpg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" width="100%;">
            </div>
            <div class="details">
                <div class="content">
                    <i class="fas fa-glass-martini" aria-hidden="true"></i>
                    <h3>Lorem Ipsum</h3>
                    <a href="#">Read More</a>
                </div>
            </div>
        </div>

        <!-- box 4 -->
        <div class="box">
            <div class="thumb">
                <img src="https://images.pexels.com/photos/594452/pexels-photo-594452.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" width="100%;">
            </div>
            <div class="details">
                <div class="content">
                    <i class="fas fa-graduation-cap" aria-hidden="true"></i>
                    <h3>Lorem Ipsum</h3>
                    <a href="#">Read More</a>
                </div>
            </div>
        </div>

    </div>

</body>
</html>

CSS CODE:

body{
    margin: 0;
    padding: 0;
    font-family: sans-serif;
    background-color: #20024a
}
.container{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    width: 1000px;
    height: 500px;
    display: flex;
}
.container .box{
    position: relative;
    width: 250px;
    height: 500px;
    background-color: #ccc;
    transition: .5s;
}
.container .box:hover{
    transform: scale(1.1);
    z-index: 1;
    box-shadow: 0 5px 20px rgba(0,0,0,1)
}
.container .box .thumb{
    position: absolute;
    width: 100%;
    height: 250px;
    overflow: hidden;
}
.container .box .details{
    position: absolute;
    width: 100%;
    height: 250px;
    overflow: hidden;
    background-color: #262626;
}
.container .box:nth-child(odd) .thumb{
    bottom: 0;
    left: 0;
}
.container .box .thumb img{
    width: 100%;
    height: 100%;
}
.container .box:nth-child(even) .details{
    bottom: 0;
    left: 0;
}
.container .box:nth-child(1) .details{
    background-color: #8553cb;
}
.container .box:nth-child(2) .details{
    background-color: #fe8f01;
}
.container .box:nth-child(3) .details{
    background-color: #79d400;
}
.container .box:nth-child(4) .details{
    background-color: #ff3b34;
}
.container .box .details .content{
    position: absolute;
    top: calc(50% + 16px);
    transform: translateY(-50%);
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    text-align: center;
    transition: .5s;
}
.container .box:hover .details .content{
    top: calc(50%)
}
.container .box .details .content .fas{
    font-size: 80px;
    color: #fff;
}
.container .box .details .content h3{
    margin: 0;
    padding: 0;
    padding: 10px 0;
    color: #fff;
}
.container .box .details .content a{
    display: inline-block;
    padding: 5px 20px;
    color: #fff;
    border: 2px solid #fff;
    text-decoration: none;
    transition: .5s;
    border-radius: 20px;
    transform: scale(0);
}
.container .box:hover .details .content a{
    transform: scale(1);
}
.container .box .details .content a:hover{
    background-color: #fff;
    color: #262626;
}
@media (max-width: 1000px){
    .container{
        width: 100%;
        height: auto;
        padding: 20px;
        box-sizing: border-box;
    }
    .container .box{
        height: 250px;
    }
    .container .box .thumb{
        display: none;
    }
}
@media (max-width: 770px){
    .container{
        display: initial;
    }
    .container .box{
        width: 50%;
        height: 250px;
        float: left;
    }
}
@media (max-width: 480px){
    .container{
        top: 0;
        left: 0;
        transform: translate(0);
    }
    .container .box{
        width: 100%;
        height: 250px;
        float: none;
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: