How to center a rotated child div to a rotated parent div and stick to the top of parent div?

How to center a rotated child div to a rotated parent div and stick to the top of parent div?

Content Index :

How to center a rotated child div to a rotated parent div and stick to the top of parent div?
Tag : javascript , By : user130518
Date : November 29 2020, 12:01 PM

wish helps you Replace your whole CSS with this one and the orange diamond (.logo) will always be at the center top because it is set to position absolute and right 0.
Here's fixed CodePen https://codepen.io/lakialex/pen/LwyeOm
.box {
  margin-top: 200px;

.diamond-content {
    position: relative;
  display: flex;
  align-items: center;
      max-width: 1200px;


.diamond-shape {
    position: relative;
    width: 200px;
    height: 200px;
    transform: rotate(-45deg);
    transform-origin: 50% 50%;
    margin: 0 auto;
    overflow: hidden;

@media (min-width: 768px) {
    .diamond-shape {
        width: 350px;
        height: 350px;

@media (min-width: 992px) {
    .diamond-shape {
        width: 420px;
        height: 420px;

    .diamond-shape.right {
        margin: 0 auto 0 -100px;

@media (min-width: 1200px) {
    .diamond-shape {
        width: 480px;
        height: 480px;

/*Content Inside Diamond*/

.diamond-shape img {
    transform: rotate(45deg);

.diamond-shape .bg {
    position: absolute;
    width: 302px;
    margin: -57px 0px 0 -57px;

@media (min-width: 768px) {
    .diamond-shape .bg {
        width: 510px;
        margin: -100px 0px 0 -100px;

@media (min-width: 992px) {
    .diamond-shape .bg {
        width: 680px;

.diamond-shape .logo {
    position: absolute;
    width: 80px;
    z-index: 2;
    margin: 0;
    right: 0;
    margin-right: -11px;
    margin-top: -11px;

@media (min-width: 768px) {
    .diamond-shape .logo {
        width: 120px;
        margin-right: -17px;
        margin-top: -17px;

@media (min-width: 992px) {
    .diamond-shape .logo {
        width: 130px;
        margin-right: -17px;
        margin-top: -17px;

@media (min-width: 1200px) {
    .diamond-shape .logo {
        width: 150px;
        margin-right: -21px;
        margin-top: -21px;

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Center align rotated element contained within parent element

Tag : html , By : ck1
Date : March 29 2020, 07:55 AM
I hope this helps you . The reason that this doesn't appear to be centering is because you have rotated it. When css goes off of transformations, it does all of the normal styling, then transforms it. So if you were to remove the transform, you would see that the problem doesn't lie with the horizontal centering, it is the vertical centering that is the problem. To solve this, you must add
filter: alpha(opacity=50);

How to make the parent div adjust in size to contain the CSS-Rotated child div?

Tag : javascript , By : GunnarHafdal
Date : March 29 2020, 07:55 AM
I wish this help you Change the width of the div.container when rotated. Add negative margin and left margin to #rotator.deg90in CSS.
Look at this example :)
function to90() {
   var elm = document.getElementById("rotator");
   elm.className = "deg90";

//add these lines
   document.getElementById('container').style.width = "500px";
   document.getElementById('container').style.height = "200px";
#rotator.deg90 {
  /*add this*/
  margin-top: -150px;
  margin-left: 200px;

 -webkit-transform: rotate(90deg);

How to rotate a parent element to display rotated child elements in 3D space

Tag : css , By : Antony Briggs
Date : March 29 2020, 07:55 AM
hope this fix your issue The order of the rotations is important, as each rotation changes the axes for the next rotation.
In demo 2, it looks like you should be rotating Y before X:
-webkit-transform: rotateY(-90deg) rotateX(-90deg) rotateZ(0deg);

Horizontally center rotated div in smaller parent

Tag : javascript , By : Star Gryphon
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , First center the block (absolute positioning and a transform) then rotate it.
.parent {
  height: 80vh;
  width: 80vw;
  margin: 1em auto;
  position: relative;
  border: 1px solid grey;

.child {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-10deg);
  background: red;
  width: 110%;
  height: 50px;

.center {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: green;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
<div class="parent">
  <div class="child"></div>
  <div class="center"></div>

How to make parent div follow the height of a 45 degree rotated child div

Tag : jquery , By : Juice
Date : November 24 2020, 05:48 AM
will be helpful for those in need For maximum flexibility (no matter what size the green square has) - use javascript to calculate the new height by looking at this like a right triangle, and using the Pythagoras Theorem:
if the formula is: a²+b²=c²
let $a = $('.child-diamond').width(),
$b = $('.child-diamond').height(),
$c = Math.sqrt((Math.pow($a, 2)) + (Math.pow($b, 2)));

Related Posts Related QUESTIONS :
  • Three.js custom shader error on Chrome GL_INVALID_OPERATION: Active draw buffers with missing fragment shader outputs
  • My JavaScript doesn't work. How can I solve this problem?
  • Why is this async function is running synchronously?
  • Get updated variable from within react hook before return
  • I want to show all image preview but whenever I upload a new one the old one is gone
  • Would I be able to give access to specific electron APIs safely?
  • Why several clicks fire for each instance of a Class?
  • cant grab value from div using attr()
  • Make web service not accessible by browser?
  • Select DOM elements within template
  • How to customize angular ui-grid row background color?
  • Binding data in two respective $scope in AngularJS, how?
  • react put some props after import class
  • Variable is distributed among same components
  • switch class in jQuery/JavaScript for active/inactive state
  • How To Track Outbound Clicks Using Javascript
  • How to get total seconds elapsed since the beginning of the month?
  • Protractor: Stale element reference at "browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);"
  • Access to an array inside an object
  • Reseting an JavaScript Interval with different value?
  • Learning Angular for the first time - version 2 or 4?
  • Rendering RSS feed (XML) in React with jquery, why do object values parsed from the feed seem empty?
  • Node.js xml2js http.request tag matching
  • applying texture to custom plane geometry in Threejs
  • How do I pass an Event as a function parameter in HTML written inside JavaScript variable?
  • Interface of object parameter with default value and default property
  • Does using try / catch rather than `.catch` observable operator with XHR requests reduce performance?
  • In IE11 background colors not working on printing
  • TypeScript interface signature "(): string"
  • Is synchronous XMLHttpRequest supported in Internet Explorer 10 and 11?
  • Axios function not returning any values with js
  • How to use firestore TIMESTAMP to create time-stamp in JavaScript
  • Instantiate subclass without constructing
  • Outputing a created object in javascript to a server side JSON file
  • Transition the numeric labels in a bar chart
  • createBottomTabNavigator: hide just one tab from the tabBar
  • iife vs simple statement behavior with document.title
  • showDialogPopup Refresh Page after Click
  • Child component does not set the initial value passed from the parent: ReactJS
  • Nodejs javascript added to button not responding
  • Trying to define a promise.all
  • Python GEE to extract featurecollection timeseries from Landsat imageries
  • How to write negative binary number?
  • Unable to set property of individual object
  • Why Named Function Expression itself cannot assign Name to another Value?
  • How to reset scroll position on single page pagination
  • How to scroll to bottom of page, when a new message is sent - Socket.io
  • How to reconstruct audio blob from a base64 encoded String?
  • How to calculate numbers within an array of objects
  • Using JavaScript to change CSS properties of SVG circles for all circles that was not clicked
  • Is there value in propTypeing repeat required properties at every level of nested components?
  • Call function if variable does not exist in a filter
  • localStorage value doesn't get updated automatically
  • React not updating state with setState correctly inside promises
  • Direct native JavaScript or jQuery method to get containing block of an element
  • Dynamic JSON object to Html Table
  • How to send Id and file to same controller?
  • How to Make a jQuery Table Cell(td) clickable to Run a Function?
  • Prevent the duplicate function onchange event jQuery
  • Reactjs Input Upload doesn't return local URL
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com