A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/html-css-exercise/css-properties/transform-origin-answer.php below:

Website Navigation


CSS Properties: How to set a rotated element's base placement

CSS Properties: How to set a rotated element's base placementLast update on February 24 2024 12:26:11 (UTC/GMT +8 hours)

Go to Exercise page

Solution:

HTML Code :

<!DOCTYPE html><!-- Declares the document type and version of HTML -->
<html><!-- Begins the HTML document -->
<head><!-- Contains metadata and links to external resources -->
<title>How to set a rotated element's base placement</title><!-- Sets the title of the document -->
<style type="text/css"> /* Starts CSS styling */
#div1 {
    position: relative; /* Sets the positioning context for the div */
    height: 100px; /* Sets the height of div1 to 100 pixels */
    width: 100px; /* Sets the width of div1 to 100 pixels */
    margin: 50px; /* Sets the margin around div1 */
    padding: 10px; /* Sets the padding inside div1 */
    border: 2px solid #CC0099; /* Sets the border style and color of div1 */
}

#div2 {
    padding: 18px; /* Sets the padding inside div2 */
    position: absolute; /* Positions div2 absolutely within its nearest positioned ancestor */
    border: 1px solid #990000; /* Sets the border style and color of div2 */
    background-color: #0000CC; /* Sets the background color of div2 */
    -ms-transform: rotate(30deg); /* Applies a rotation transformation for Microsoft browsers */
    -ms-transform-origin: 20% 30%; /* Sets the origin of the rotation for Microsoft browsers */
    -webkit-transform: rotate(30deg); /* Applies a rotation transformation for WebKit-based browsers */
    -webkit-transform-origin: 20% 30%; /* Sets the origin of the rotation for WebKit-based browsers */
    transform: rotate(30deg); /* Applies a rotation transformation for other browsers */
    transform-origin: 20% 15%; /* Sets the origin of the rotation for other browsers */
}
</style><!-- Ends CSS styling -->
</head><!-- Ends the head section -->
<body><!-- Begins the body of the document -->
<h1><strong>w3resource Tutorial</strong></h1><!-- Displays a level 1 heading with bold text "w3resource Tutorial" -->
<div id="div1"><!-- Starts a div with id "div1" -->
<div id="div2">Web Development Tutorial</div><!-- Starts a div with id "div2" inside div1 -->
</div><!-- Ends div1 -->
</body><!-- Ends the body section -->
</html><!-- Ends the HTML document -->

Explanation:

Live Demo:

See the Pen transform-origin-answer by w3resource (@w3resource) on CodePen.

See the solution in the browser

Supported browser

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4