-1

I want to apply a webkit transformation to a div (in this case, skew), but don't want the text to be affected. How would I go about this? My current code is below:

.main_div {
        width:200px;
        height:100px;
        background:red;
        margin-left:55px;
        margin-top: 25px;
        position:relative;
        -webkit-transform: skew(-30deg);         
    }

    <div class="main_div">
        Dummy Text Here 
        <input type="field" value="" name="" ></input>
    </div>
Sinister Beard
  • 3,570
  • 12
  • 59
  • 95

2 Answers2

3

Just add one more div and apply the transform to normal one like below.

HTML

<div class="main_div">
  <div class="normal">
    <label>Dummy Text Here </label>
    <input type="field" value="" name="" ></input>
  </div>
</div>

CSS

 .main_div {
    width:200px;
    height:100px;
    background:red;
    margin-left:55px;
    margin-top: 25px;
    position:relative;
    -webkit-transform: skew(-30deg);         
 }
 .normal{-webkit-transform: skew(30deg);}

DEMO

IDEA 2:

CSS

 .main_div {
    width:200px;
    height:100px;
    background:red;
    margin-left:55px;
    margin-top: 25px;
    position:relative;
    -webkit-transform: skew(-30deg);         
 }
 .main_div > *{-webkit-transform: skew(30deg);}

HTML

 <div class="main_div">    
    <div>Dummy Text Here </div>
    <input type="field" value="" name="" ></input>   
 </div>

DEMO

Suresh Ponnukalai
  • 13,820
  • 5
  • 34
  • 54
0

You need to apply separate styles to your text and input, also you need to wrap your text in <p> tags:

<div class="main_div">
    <p>Dummy Text Here</p> 
    <input type="field" value="" name="" ></input>
</div>

.main_div {
 width:200px;
 height:100px;
 background:red;
 margin-left:55px;
 margin-top: 25px;
 position:relative;
  -webkit-transform: skew(-30deg);
}

p {
width: 100px; 
color: black; 
font-size: 18px;
}

input{
width: 120px;
margin: 0 auto; 
display: block
}
4dgaurav
  • 11,360
  • 4
  • 32
  • 59
Pixelomo
  • 6,373
  • 4
  • 47
  • 57