Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use CSS3 transform on a span?

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>
like image 815
jenhan Avatar asked Jul 25 '14 17:07

jenhan


People also ask

Does transform work on span?

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> ...

Can we apply CSS on span?

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.

How do you rotate a span in CSS?

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.

Which actions are possible using the CSS3 transforms?

The transform CSS property lets you rotate, scale, skew, or translate an element.

How do I transform a span in CSS?

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 ).

How to tilt or rotate a span element in CSS?

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.

What is the transform property in CSS?

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.

How do you use the span tag in HTML?

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?


1 Answers

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>
like image 150
web-tiki Avatar answered Nov 09 '22 03:11

web-tiki