HTML   发布时间:2022-04-15  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了html – 在中间创建一个CSS双边框线大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图通过严格的CSS和 HTML来实现这一点(PiC),这个标题可以在移动设备上显示.我能够做到这一点,尽管我相信我的做法可能是错误的.我将它们添加到两个容器中,使它们对齐并连接正好,几乎是不可能的.

这是我的CSS:

#shape1:before{
  position: absolute;
  bottom: 30px; left: -4px;
  content: '';
  height: 15px;
  width: 41%;
  border-bottom: 3.5px solid #000000;
  border-right: 4.5px solid #000000;
  transform: skew(-45deg);
}
#shape1:after{
  position: absolute;
  content: '';
  bottom: 24px; left: 0px;
  height: 16px;
  width: 41%;
  border-bottom: 3.5px solid #000000;
  border-right: 4.5px solid #000000;
  transform: skew(-45deg);
  z-index: -1;
}
#shape1{
  position: relative;
  height: 79.5px;
  width: 400px;
  z-index: -1;
}
#shape:before{
  position: absolute;
  content: '';
  right: 0px;
  width: 57.5%;
  top: 31.2px;
  z-index: -1;
  border-bottom: 3px solid #000000;
  box-shadow: 1px 2px 5px rgba(0,.3);
}
#shape:after{
  position: absolute;
  content: '';
  top: 36px;
  width: 56.5%;
  z-index: -1;
  right: 0px;
  border-bottom: 3px solid #000000;
  box-shadow: 1px 3px 5px rgba(0,.3);
}
#shape {
  height: 71px;
  width: 400px;
}

任何链接或共享知识将不胜感激.目前我似乎找不到任何东西.我也不会在这里添加一些阴影,这就是为什么你会在那里找到一些box-shadow代码,但还没有达到100%.

解决方法

使用CSS变换:

为了实现使用CSS的双边框,没有任何问题使它们正确对齐,偏斜变换是最好的选择,因为我们可以随时修正变换发生的点(从而消除任何潜在的对齐问题).然而,我们不能使用这种方法的双边框,因为偏斜变换将导致角形边上的边界线看起来比顶部和底部更接近.为了克服这个问题,我们必须使用一个额外的子元素.

输出是完美的响应,这可以通过查看全页的片段输出来验证.

.double-outer-border {
  position: relative;
  border-top: 1px solid;
  height: 100px;
  width: 100%;
  overflow: hidden;
}
.double-outer-border:before,.double-outer-border:after,.double-inner-border:before,.double-inner-border:after {
  position: absolute;
  content: '';
  height: 20px;
  bottom: 0px;
  width: 50%;
  transform: skew(-45deg);
}
.double-outer-border:before {
  left: -2px;
}
.double-outer-border:after {
  right: -2px;
}
.double-inner-border:before {
  left: -4px;
  bottom: 4px;
}
.double-inner-border:after {
  right: 0px;
  bottom: 4px;
}
.double-outer-border:before,.double-inner-border:before {
  border-bottom: 3px solid;
  border-right: 4px solid;
  transform-origin: right bottom;
}
.double-outer-border:after,.double-inner-border:after {
  border-top: 3px solid;
  border-left: 4px solid;
  transform-origin: left bottom;
  box-shadow: inset 2px 2px 2px rgba(0,.3);
}
<div class='double-outer-border'>
  Some content
  <div class='double-inner-border'></div>
</div>

使用CSS渐变:

下面是一个比较早的一个非常复杂的方法,但是我在这里发贴只是给出一些不同的想法.可以使用线性渐变(以及一点转换)来实现具有倾斜的整个双边框.然这会产生预期的产出,但我不会推荐它.使用这种方法只能得到一些想法,可以做什么所有可以做的渐变:)

.double-border {
  position: relative;
  height: 100px;
  width: 100%;
  border-top: 1px solid;
  overflow: hidden;
}
.double-border:before {
  position: absolute;
  content: '';
  height: 100%;
  width: calc(50% + 10pX);
  left: -10px;
  top: 0px;
  BACkground: linear-gradient(to right,black 99.9%,transparent 99.9%),linear-gradient(to right,transparent 99.9%);
  BACkground-repeat: no-repeat;
  BACkground-position: -4.5px 97px,-9px 91px;
  BACkground-size: 100% 3px;
}
.double-border:after {
  position: absolute;
  content: '';
  height: 100%;
  width: calc(50% + 10pX);
  left: -10px;
  top: 0px;
  BACkground: linear-gradient(to right,rgba(0,0.3) 99.9%,transparent 99.9%);
  BACkground-repeat: no-repeat;
  BACkground-position: -7.5px 75px,-9px 81px,-8.5px 77px,-10px 83px;
  BACkground-size: 100% 3px;
  transform: scaleX(-1);
  transform-origin: right;
}
.slanted-border {
  position: absolute;
  height: 25px;
  width: 25px;
  bottom: 3px;
  left: 50%;
  transform: translateX(-50%) rotate(-45deg);
  BACkground: linear-gradient(to right,black 99%,transparent 99%),black 95%,transparent 95%),0.3) 99%,0.3) 95%,transparent 95%);
  BACkground-repeat: no-repeat;
  BACkground-position: 0px 11px,-2px 17px,0px 13px,-2px 19px;
  BACkground-size: 100% 3px;
}
<script src="https://cdnjs.cloudFlare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div class='double-border'>
  Some Content
  <div class='slanted-border'></div>
</div>

使用SVG:

通常,绘制这种形状或复杂线条的最简单的方法是SVG(其也具有响应能力并且可以适应任何尺寸变化的益处),但是对于该SVG使用SVG有一些缺点:

>如果您的标题的高度是恒定的,并且只有宽度根据设备而改变,则SVG将必须拉伸/缩小以适应容器(取决于原始尺寸),这将使中间的倾斜线看起来蜷缩(或)细长. (以全页模式查看该片段.)
> SVG中的笔画也默认缩放.这可以通过将vector-effect属性设置为非缩放笔画来避免,但目前IE不支持此属性,因此此解决方案不兼容于跨浏览器.

path {
  stroke: black;
  fill: none;
  stroke-width: 2;
}
svg {
  height: 100px;
  width: 100%;
  border-top: 1px solid;
}
<svg viewBox='0 0 500 100' preserveaspectratio='none'>
  <path d='M0,98 240,98 260,75 500,75' vector-effect='non-scaling-stroke'/>
  <path d='M0,94 237.5,94 257.5,71 500,71' vector-effect='non-scaling-stroke'/>
</svg>

大佬总结

以上是大佬教程为你收集整理的html – 在中间创建一个CSS双边框线全部内容,希望文章能够帮你解决html – 在中间创建一个CSS双边框线所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。