PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 16, 2022

[FIXED] How to align div to parent div?

 November 16, 2022     alignment, css, html, vertical-alignment     No comments   

Issue

suppose we have 4 dives. the first div is outer div. i want to create a HTML that the second div size be 50% first and be in middle bottom of first div. the third div size be 50% second and be in middle left of second div. the fourth div size be 50% third div and be in middle top of third div.

how can i do it?

enter image description here


Solution

Is this your desired output? It’s made using position, top and bottom, and translate to make sure it’s centered right.

.div1 div { /* makes every small div 50% the size of the previous */
    width: 50%;
    height: 50%;
}
.div1 {
    width: 200px;
    height: 200px;
    background-color: red;
}
.div2 {
    background-color: green;
    position: relative;
    top: 100%;
    left: 50%;
    transform: translate(-50%, -100%);
}
.div3 {
    background-color: pink;
    position: relative;
    top: 50%;
    transform: translate(0, -50%);
}
.div4 {
    background-color: lightblue;
    position: relative;
    left: 50%;
    transform: translate(-50%, 0);
}
<div class="div1">
    <div class="div2">
        <div class="div3">
            <div class="div4">
                
            </div>
        </div>
    </div>
</div>



Answered By - Davedude
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing