I have a inline element (a <span>
) nested in a <h1>
tag. I applied a transform property to the h1
( skew so it looks like a parallelogram).
I need to transform the span tag to "unskew" it and its text. But this only seems to work in IE.
Here is an example of the HTML and CSS:
h1 { background: #f00; padding: .25em .5em; text-align: right; transform: skew(-15deg); } h1 span { color: #fff; transform: skew(15deg); }
<h1><span>This is a Title</span></h1>
Solution: Set the display property of the span to inline-block or block . This will let you apply transforms to the span element. It also works for other inline elements like <a> <em> <strong> ...
The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.
You can tilt or rotate a SPAN or any HTML element at a specified angle using CSS transform property. This property has many useful functions and one of them is the rotate() function, using which you can easily rotate a SPAN element at a given angle, without using any script.
The transform CSS property lets you rotate, scale, skew, or translate an element.
Here is the list of transformable elements from the CSS Transforms Module Level 1. Set the display property of the span to inline-block or block. This will let you apply transforms to the span element. It also works for other inline elements like <a> <em> <strong> ... (see the list of inline elements on MDN ).
You can tilt or rotate a SPAN or any HTML element at a specified angle using CSS transform property. This property has many useful functions and one of them is the rotate () function, using which you can easily rotate a SPAN element at a given angle, without using any script.
Definition and Usage The transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, skew, etc., elements. To better understand the transform property, view a demo.
You can use the HTML span tag as a container to group inline elements together so you can style or manipulate them with JavaScript. In this article, I will show you how to use the span tag to make a certain part of your content distinct from the rest. Then you should be able to start using it in your coding projects. What is the span tag used for?
Explanation:
A <span>
is an inline elements and Transform property doesn't apply on inline elements.
List of transformable elements on the CSS Transforms Module Level 1.
Solution:
Set the display property of the span to inline-block
or block
. This will let you apply transforms to the span element.
It also works for other inline elements like <a> <em> <strong>
... (see the list of inline elements on MDN).
Here is a demo with the <span>
element :
h1 { background: #f00; padding: .25em .5em; text-align: right; transform: skew(-15deg); } h1 span { color: #fff; display: inline-block; /* <- ADD THIS */ transform: skew(15deg); }
<h1><span>This is a Title</span></h1>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With