我怎样才能拥有 css 的背景形状?
how can i have background shapes with css?
我使用 div 和 css 属性 变换实现了类似的效果:skew();
但是我希望它在上升的地方有一条曲线,所以如果你能给我一个正确方向的步骤或者告诉我更多关于插入响应式 svg 图形的最简单方法特别是元素的 背景 或页面本身的艺术,将不胜感激
编辑:这是CSS使用的
.skewed-bg{
background: #830024;
-webkit-transform: skew(0deg, -9deg);
transform: skew(0deg, -9deg);
margin-top: -200px;
}
.skewed-bg .container{
-webkit-transform: skew(0deg, 9deg);
transform: skew(0deg, 9deg);
padding-top: 200px;
color: white;
}
您可以将倾斜变换应用于伪元素(如 ::after
)而不使用 SVG 或影响主要元素(也减少了对额外 HTML 元素的需求):
header {
background: #CCC;
padding: 2em;
}
.skewed-bg {
background: #830024;
color: #FFF;
padding: 2em;
position: relative;
min-height:300px;
overflow:hidden;
}
.skewed-bg::after {
content: '';
position: absolute;
bottom: -75%; left: 0; right: 0;
height:100%;
background:#FFF;
transform: skew(0deg, -9deg);
}
<header>Power</header>
<div class="skewed-bg">
Quienes Somos.
</div>
jsFiddle: https://jsfiddle.net/w6690acn/1/
你也可以使用 linear-gradient
(再次),实际上是 2 和 background-size
body {
width: 80%;/* whatever , can be a fixed width , basicly to show behavior on resize */
margin: auto;
}
body>div {
background:
linear-gradient(to bottom right, #830024 50%, transparent 50.5%) no-repeat bottom,
/* bottom part */
linear-gradient(0deg, #830024, #830024) no-repeat top;
/* top portion */
color: white;
padding-bottom: 3em;
background-size: 100% 7em, 100% calc(100% - 7em)
}
<div>
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
</div>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
我使用 div 和 css 属性 变换实现了类似的效果:skew();
但是我希望它在上升的地方有一条曲线,所以如果你能给我一个正确方向的步骤或者告诉我更多关于插入响应式 svg 图形的最简单方法特别是元素的 背景 或页面本身的艺术,将不胜感激
编辑:这是CSS使用的
.skewed-bg{
background: #830024;
-webkit-transform: skew(0deg, -9deg);
transform: skew(0deg, -9deg);
margin-top: -200px;
}
.skewed-bg .container{
-webkit-transform: skew(0deg, 9deg);
transform: skew(0deg, 9deg);
padding-top: 200px;
color: white;
}
您可以将倾斜变换应用于伪元素(如 ::after
)而不使用 SVG 或影响主要元素(也减少了对额外 HTML 元素的需求):
header {
background: #CCC;
padding: 2em;
}
.skewed-bg {
background: #830024;
color: #FFF;
padding: 2em;
position: relative;
min-height:300px;
overflow:hidden;
}
.skewed-bg::after {
content: '';
position: absolute;
bottom: -75%; left: 0; right: 0;
height:100%;
background:#FFF;
transform: skew(0deg, -9deg);
}
<header>Power</header>
<div class="skewed-bg">
Quienes Somos.
</div>
jsFiddle: https://jsfiddle.net/w6690acn/1/
你也可以使用 linear-gradient
(再次),实际上是 2 和 background-size
body {
width: 80%;/* whatever , can be a fixed width , basicly to show behavior on resize */
margin: auto;
}
body>div {
background:
linear-gradient(to bottom right, #830024 50%, transparent 50.5%) no-repeat bottom,
/* bottom part */
linear-gradient(0deg, #830024, #830024) no-repeat top;
/* top portion */
color: white;
padding-bottom: 3em;
background-size: 100% 7em, 100% calc(100% - 7em)
}
<div>
<h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
</div>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>