Created
November 26, 2018 11:52
-
-
Save manojd929/6827a67e142aca8580a505269dfd085a to your computer and use it in GitHub Desktop.
css problems - centering a div
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
* { | |
box-sizing: border-box; | |
} | |
.outer { | |
background-color: blue; | |
position: relative; | |
width: 300px; | |
height: 300px; | |
} | |
.inner { | |
background-color: salmon; | |
position: absolute; | |
width: 150px; | |
height: 150px; | |
left: 150px; | |
top: 150px; | |
transform: translate(-50%, -50%); | |
} | |
.outer-flex { | |
background-color: blue; | |
width: 300px; | |
height: 300px; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
} | |
.inner-flex { | |
background-color: salmon; | |
width: 150px; | |
height: 150px; | |
} | |
.outer-align { | |
background-color: blue; | |
width: 300px; | |
height: 300px; | |
text-align: center; | |
padding: 75px 0px; | |
} | |
.inner-align { | |
background-color: salmon; | |
width: 150px; | |
height: 150px; | |
display: inline-block; | |
} | |
.outer-margin { | |
background-color: blue; | |
width: 300px; | |
height: 300px; | |
padding: 75px 0px; | |
} | |
.inner-margin { | |
background-color: salmon; | |
width: 150px; | |
height: 150px; | |
margin: 0px auto; | |
} | |
.flex-container { | |
display: flex; | |
justify-content: flex-start; | |
align-items: center; | |
} | |
.flex-item { | |
background-color: salmon; | |
width: 25px; | |
height: 25px; | |
margin-left: 5px; | |
} | |
.flex-item:last-child { | |
margin-left: auto; | |
} | |
.triangle { | |
border-left: 100px solid pink; | |
border-top: 100px solid transparent; | |
border-bottom: 100px solid transparent; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="outer"> | |
<div class="inner"> | |
</div> | |
</div> | |
<hr /> | |
<div class="outer-flex"> | |
<div class="inner-flex"> | |
</div> | |
</div> | |
<hr /> | |
<div class="outer-align"> | |
<div class="inner-align"> | |
</div> | |
</div> | |
<hr /> | |
<div class="outer-margin"> | |
<div class="inner-margin"> | |
</div> | |
</div> | |
<hr /> | |
<div class="flex-container"> | |
<div class="flex-item"> | |
</div> | |
<div class="flex-item"> | |
</div> | |
<div class="flex-item"> | |
</div> | |
</div> | |
<hr /> | |
<div class="triangle"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment