Always keeping the screen in view within a div that is rotated along the Y-axis

Here is the code:

html

<div id="back">
   <div id="right_text">TEST</div>
   <div id="left_text">TEST2</div>
</div>
<div id="mid"></div>

css

#mid {
    border: 1px solid black;
    height: 100px;
    width: 100px;
    -webkit-animation: rotate linear 5s;
    -webkit-animation-iteration-count: infinite;
    margin:auto;
    margin-top:-125px;
    position: static;
}

@-webkit-keyframes rotate {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg);
  }
}
#back {
    width:auto;
    height: 150px;
    border: 1px solid red;
    -webkit-animation: rotateY linear 5s;
    -webkit-animation-iteration-count: infinite;
    position: static;
}
@-webkit-keyframes rotateY {
    from {
        -webkit-transform: rotateY(0deg)
    }
    to {
        -webkit-transform: rotateY(360deg)
    }
}
#right_text {
    border: 1px solid green;
    height: 75px;
    width: 75px;
    float: right;
    margin-top: 35px;
    text-align: center;
}
#left_text {
    border: 1px solid green;
    height: 75px;
    width: 75px;
    float: left;
    margin-top: 35px;
    text-align: center;
}

http://jsfiddle.net/bXhL8/

In this setup, both text-divs face away from the screen when not on their original side. I want them to always remain in view and follow the rotation of my back-div.

My query is whether achieving this effect is possible using only CSS or if JavaScript would be required.

Answer №1

To enhance your webpage, include the following CSS code:

#left_text, #right_text {
 -webkit-animation: rotateY linear 5s;
 -webkit-animation-iteration-count: infinite;
}

JSFiddle Link

Update:

Updated JSFiddle Link

Answer №2

Here is a snippet of my latest code. It's not a perfect circle yet, as I have just added 4 frames to my @keyframes animation. I am considering creating an actual circular rotation by incorporating a skew() element into the entire circular function or body - although I'm unsure if that approach will be successful.

Thank you for your assistance!

HTML:

<div id="right_text">
    <div id="right_text_text">TEST</div>
</div>
<div id="left_text">
    <div id="left_text_text">TEST2</div>
</div>
<div id="mid"></div>

CSS:

#mid {
    border: 1px solid black;
    background-color: red;
    height: 100px;
    width: 100px;
    -webkit-animation: rotate linear 5s;
    -webkit-animation-iteration-count: infinite;
    margin-top: 105px;
    margin-left: 210px;
    position: static;
}
@-webkit-keyframes rotate {
    from {
        -webkit-transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(-360deg);
    }
}

#right_text_text {
    border: 1px solid black;
    text-align: center;
    position: absolute;
    width: 50px;
    -webkit-animation: downupright linear 8s infinite;
}

#left_text_text {
    border: 1px solid black;
    text-align: center;
    position: absolute;
    width: 50px;
    -webkit-animation: updownleft linear 8s infinite;
}

@-webkit-keyframes downupright {
    0% { left: 490px; top: 150px;}
    25% { left: 245px; top: 100px; z-index: -10;}
    50% { left: 0px; top: 150px;}
    75% { left: 245px; top: 200px; z-index:10;}
    100% { left: 490px; top: 150px;}
}

@-webkit-keyframes updownleft {
    0% { left: 0px; top: 150px;}
    25% { left: 245px; top: 200px; z-index: 9;}
    50% { left: 490px; top: 150px;}
    75% { left: 245px; top: 100px; z-index: -9;}
    100% { left: 0px; top: 150px;}
}

http://jsfiddle.net/bXhL8/4/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for adjusting the default selection in a second dropdown menu

I have a dilemma with my two dropdown lists, "optionone" and "optiontwo". I am trying to alter the default selected value from "option value=3>3" to option value=3 selected>3 when the user selects 2 from the first dropdown list ("optionone"). <sc ...

Steps to make the placeholder in an MUI TextField component move to the top of the box instead of staying within the border:

I'm working on styling a text field in MUI to achieve the look shown in the image below: https://i.sstatic.net/JHhpf.png However, my current implementation looks like this: https://i.sstatic.net/5N7hH.png Currently, when I click inside the text fi ...

Tips for ensuring that all children within a flex-container have equal heights

I seem to be facing an issue with this problem. My goal is to ensure that all the child divs within a flex container have the same height as the tallest child div, which in this case is 100px. Additionally, I want them to be aligned at the center. I&apos ...

Tips for ensuring your background image is fully displayed and covers the entire size

My dilemma lies within the header div. My intention is to have it fully covered with a background image without any cropping. However, the current setup seems to be stretching and cutting off parts of the image. Here is my CSS code: .header { bor ...

The background color is showing the wrong shade

So, I recently created a simple HTML5 website and decided to set the background-color of the header div to #3D7D99. However, when I view it in the browser, it appears as #35728E. Can anyone explain what might be causing this discrepancy? UPDATE: Just to c ...

Looking for a skilled JavaScript expert to help create a script that will automatically redirect the page if the anchor is changed. Any t

Seeking a Javascript expert, In my custom templates, I have used a link as shown below: <a href='http://www.allbloggertricks.com'>Blogging Tips</a> I would like the page to redirect to example.com if the anchor text is changed from ...

Adjustable icon dimensions in Material-UI

My current setup involves utilizing material-UI icons <ArrowRightAlt/> I have been able to manipulate the size of the icon using the fontSize attribute <ArrowRightAlt fontSize="large" /> However, I am interested in having the size ...

Assigning attributes to each letter in a pangram

I am attempting to assign the appropriate class to a group of elements, representing each letter in the alphabet. The elements have IDs ranging from #alpha_0 to #alpha_25. If a letter appears just once in the input, it should be displayed in green. If a le ...

What is the best way to set up <Input> to restrict input to only include letters, spaces, and the backspace key

I have created a 15 by 15 matrix displayed as an HTML table where each cell contains an input box. I am looking to restrict user interaction so that they can only: Input English letters Delete characters using backspace Use the spacebar In the future, nav ...

Changing the value of a previous TD element using Javascript

My page features a button that, when clicked, triggers a function to change the value in the previous TD element from "No" to "Yes". Here is the HTML snippet: <tr class="odd"> <td class="">13.00</td> <td class="">DDR</td> ...

JavaScript: a single function and two calls to Document.getElementById() results in both returning "undefined"

Within my JavaScript file, I have a function that utilizes two variables: choice and courseChosen. The latter variable must be converted into an object first. In the HTML, the tags courseName and courseInfo are used for choice and courseChosen respectively ...

Introducing a new left overlay panel popup feature using jQuery Mobile

I'm currently developing a mobile app and I'm having trouble getting a popup to launch on the left overlay panel when clicked on "Sign out". I can't figure out where I'm going wrong. Can someone please provide some suggestions? Thank yo ...

Activate event starting from parent and ascending through child nodes

When I have a table inside a <div class="timely"></div>, and within that table is a <th class="prev"><i>previous</i></th>, Chrome developer tools show an event listener on the <th>. However, Firefox developer tools ...

Offering substitute text for directly copying and pasting

I remember doing something similar in the past, but I can't seem to find any information about it now. It's proving to be quite difficult to research this particular issue. What I want to achieve is showing one version (A) of text on the screen, ...

How can I add content to the body of a modal in Bootstrap 3?

My application has a button that, when clicked, is supposed to trigger a modal popup containing some data. I want the data in the modal to come from another application via a PHP file accessed through a URL. How can this be achieved? <?php echo '& ...

The validation process is functioning properly, however, the alert or message is failing to appear

After realizing that Safari is not compatible with the required HTML5 feature, I attempted to include a JavaScript validation script. Although the script successfully prevents the customer from advancing, the alert or message is not being displayed. <d ...

Is there a way to retrieve the value from a select tag and pass it as a parameter to a JavaScript function?

I would like to pass parameters to a JavaScript function. The function will then display telephone numbers based on the provided parameters. <select> <option value="name-kate">Kate</option> <option value="name-john">John& ...

"Maintaining Consistency: Ensuring The First Row is Repeated on Every

When trying to save a PDF using jspdf, I encountered an issue with tables in my HTML. The tables do not have headers, but JsPDF is automatically repeating the first row of the table on every page, causing overlap. I don't want headers on every new pag ...

Creating a sticky positioning effect in CSS

Can someone assist me in implementing the position: sticky as demonstrated below? Currently, the upcoming date overlaps the current date. This causes the opacity and shadow of the date to reach 100%, which can create a cluttered appearance if there are m ...

Transferring parameters from HTML to CSS using Less and addressing two key design problems

I am currently in the process of designing a webpage, and I've encountered three distinct issues - two are related to pure .css, while one is related to less. Firstly, I have set margin: auto and padding: auto on the body tag, but it's not cente ...