简体   繁体   English

线性渐变对角阴影

[英]linear gradient diagonal shadow

I am attempting to add a shadow to the diagonally cut section of the div. 我正在尝试向div的对角切割部分添加阴影。 Please see code below. 请参见下面的代码。 Unfortunately, I am unable to do so, and can only get a box-shadow around the whole div. 不幸的是,我无法做到这一点,并且只能使整个div出现阴影。 How can I target the diagonal section? 如何定位对角线部分? Where the left hand side div meets Hulk Hogan, I want to include a shadow here. 在左侧div与Hulk Hogan相遇的地方,我想在此处添加阴影。 I hope this makes sense. 我希望这是有道理的。

See jsfiddle here 在这里看到jsfiddle

 .left-box { float: left; height: 361px; width: 68%; color: white; z-index: 1; } .right-box { right: 0; height: 361px; width: 55%; color: white; position: absolute; background: url("http://img.bleacherreport.net/img/images/photos/002/796/309/8288d50f6769ccb555f2b9010a4f6544_crop_north.jpg?w=543&h=361&q=75"); background-repeat: no-repeat; } .gradient{ position: relative; } .gradient.right { background: linear-gradient(to top left, transparent 50%, yellow 50%) no-repeat, linear-gradient(to top left, transparent 0.1%, yellow 0.1%) no-repeat; background-size: 41% 122%, 60% 100%; background-position: 100% 0%, 0% 0%; box-shadow: red 0 0 50px; } .gradient h3{ position: absolute; font-size: 40px; left: 5px; top: 5%; width: 50%; } .gradient p { position: absolute; left: 5px; top: 25%; width: 50%; font-size: 18px; } 
 <div class="gradient right left-box"> </div> <div class="right-box box"> </div> 

One option is to try to include it into the gradient: 一种选择是尝试将其包括在渐变中:

.gradient.right {
  background: linear-gradient(to top left, transparent 50%,
    rgba(255, 0, 0, 0) 50%, rgba(255, 0, 0, 1) 53%, yellow 53.5%) no-repeat,
    linear-gradient(to top left, transparent 0.1%, yellow 0.1%) no-repeat;
  background-size: 41% 122%, 60% 100%;
  background-position: 100% 0%, 0% 0%;
}

With the rgba(255, 0, 0, 0) 50%, rgba(255, 0, 0, 1) 53% you can specify the color of the shadow (they should be the same values for R, G and B). 使用rgba(255, 0, 0, 0) 50%, rgba(255, 0, 0, 1) 53%您可以指定阴影的颜色(R,G和B的值应相同)。

The result looks like this: 结果看起来像这样:

预期结果。

Here's the updated JSFiddle . 这是更新的JSFiddle

I have chosen a 0.5% increment (from 53% to 53.5% ) for the gradient from the red shadow to the yellow background so that the edge looks a bit smoother. 我为从红色阴影到黄色背景的渐变选择了0.5%的增量(从53%53.5% ),以使边缘看起来更平滑。 You can also calculate the values with the CSS3 calc function for more control. 您还可以使用CSS3 calc函数计算值,以进行更多控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM