Answers for "CSS responsive square div"

CSS
0

how to make a square div in css

.square {
    background-color: #000;
    width: 50vw;
    height: 50vw;
}
.square h1 {
    color: #fff;
}
/* It works */
Posted by: Guest on May-26-2021
1

responsive square css

<!-- HTML -->
<div class='square-box'>
    <div class='square-content'>
        <h3>test</h3>
    </div>
</div>

<!-- CSS -->
<style>
.square-box{
    position: relative;
    width: 50%;
    overflow: hidden;
    background: #4679BD;
}
.square-box:before{
    content: "";
    display: block;
    padding-top: 100%;
}
.square-content{
    position:  absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    color: white;
    text-align: center;
}
</style>
Posted by: Guest on June-10-2021

Browse Popular Code Answers by Language