Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS transform skew without blur

I'm trying to create some drivers with a border and text. The drivers need to be tilted so I have applied the transform: skew(); CSS rule. However, now the font and the border have gone really blurry. I understand it is possible to add font smoothing to an element but I'm not sure how to smooth my border as well?

I would like these drivers to be full width of the browser, with no white space after the skew.

CSS -

.flex-inline{
   display: -webkit-box;
   display: -webkit-flex;
   display: -ms-flexbox;
   display: flex;
}
.driver-wrap{
   overflow: hidden;
   margin-bottom: 75px;
}   
.driver{
  flex: 1;
  background-color: #fff;
  min-height: 250px;
  position: relative;
  transform: skew(-15deg, 0deg);
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  cursor: pointer;
}      
.content{
  background-image: url('https://i.imgur.com/oKWAofK.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  position: absolute;
  top: 0;
  left: -50px;
  right: -50px;
  bottom: 0;
  transform: skew(15deg, 0deg);
}         
.text{
  position: absolute;
  bottom: 10px;
  left: 75px;
  width: 70%;
  transform: rotate(360deg);
}
h2{
  font-family: $heading;
  font-size: 28px;
  color: #fff;
  margin: 0px 0px;
  text-transform: capitalize;
}
p{
  color: #fff;
  font-size: 18px;
  margin-top: 5px;
}

.driver:nth-child(1){
  margin-left: -50px;
  border-right: 20px solid #fdcb6e;

}
.driver:nth-child(2){
  border-right: 20px solid #e84393;
}

HTML -

<div class="driver-wrap flex-inline">
    <div class="driver">
        <div class="content">
       <div class="text">
               <h2>Building training</h2>
          <p>lorem ipsum text here</p>
       </div>
        </div>
    </div>
    <div class="driver">
        <div class="content">
       <div class="text">
               <h2>Building training</h2>
          <p>lorem ipsum text here</p>
       </div>
        </div>
    </div>
    <div class="driver">
        <div class="content">
       <div class="text">
               <h2>Building training</h2>
          <p>lorem ipsum text here</p>
       </div>
        </div>
    </div>
</div>

JSFiddle - https://jsfiddle.net/zhhpm02y/10/

like image 516
Sam Avatar asked Feb 19 '18 21:02

Sam


2 Answers

I have yet to see any pure CSS solution to fix blurry text after a transform - but I'm happy to be proven wrong!

I've found it best to never skew or transform text and instead skew the image, border etc., then just position the text over the top. For example:

body {
  margin: 0;
}

nav {
  display: flex;
  margin-left: -54px;
  overflow: hidden;
}

article {
  position: relative;
  width: 100%;
}

section {
  min-width: 300px;
  margin-top: 130px;
  margin-left: 70px;
}

aside {
  background-image: url('https://i.redd.it/kvowi2zio7h01.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  position: absolute;
  top: 0;
  left: 0;
  transform: skew(-15deg, 0deg);
  transform-origin: bottom center;
  z-index: -1;
  width: 100%;
  height: 200px;
}

aside::after {
  content: "";
  height: 100%;
  position: absolute;
  border-right: 20px solid #fdcb6e;
}

article:nth-child(2n) aside::after {
  border-right-color: #e84393;
}

h2 {
  font-family: Verdana;
  font-size: 25px;
  color: #fff;
  margin: 0;
}

p {
  color: #fff;
  font-size: 18px;
  margin-top: 5px;
}
<nav>
  <article>
    <section>
      <h2>Building training</h2>
      <p>lorem ipsum text here</p>
    </section>
    <aside></aside>
  </article>
  <article>
    <section>
      <h2>Building training</h2>
      <p>lorem ipsum text here</p>
    </section>
    <aside></aside>
  </article>
  <article>
    <section>
      <h2>Building training</h2>
      <p>lorem ipsum text here</p>
    </section>
    <aside></aside>
  </article>
</nav>

Update: Following some comments below, the <nav> is 100% of the window width and shifted left to remove the initial gap created by the skew. The <aside> is now width: 110% which removes the end gap.

Update 2: I was never happy with the width:110% to remove the end gap so I've now used transform-origin: bottom center; to make the skew leave the bottom edge alone (so the transformation is around the middle point on the bottom edge), thereby never actually creating an end gap! A few margins were adjusted for the text in the latest code too.

like image 142
andyb Avatar answered Oct 31 '22 21:10

andyb


Remove property "-webkit-backface-visibility: hidden;" from your ::before ::after classes. so that it will work perfect.

It is worked For me. in Chrome, Firefox and Edge

body{ margin: 0; }
.top { height: 100px; }
.main { 
background: linear-gradient(0deg, #FFFFFF 0%, #d1d1d1 100%);
position: relative;
color: #fff;  
z-index: 1;
color: #fff;
font-family: arial, sans-serif;
margin: 100px 0;
padding: 10% 10px;
text-align: center;}

.main:before{
  content:  '';
  background: #d1d1d1; 
  display: block;
  height: 100%;
  left: 0;
  position: absolute;
  right: 0; 
  z-index: -1;
 /* -webkit-backface-visibility: hidden;*/
  top: 0;
  transform: skewY(-5deg); 
  transform-origin: 1%;
}

.main:after{
  background: #d1d1d1;
  content:  '';
  display: block;
  height: 100%;
  left: 0;
  position: absolute;
  right: 0; 
  z-index: -1;
 /* -webkit-backface-visibility: hidden; */
  top: 0;
  transform: skewY(5deg); 
  transform-origin: 1%;
}
<div class="top"></div>
<div class="main">
  <h1>CONTENT</h1>
</div>
like image 40
Srinivasan Kasiram Avatar answered Oct 31 '22 21:10

Srinivasan Kasiram