gpt4 book ai didi

html - 如何使用 CSS3 使用数据属性值设置具有交替行颜色或图像的右 Angular 设计

转载 作者:行者123 更新时间:2023-11-28 07:24:58 25 4
gpt4 key购买 nike

我有一个场景,我将在包装器下放置多个部分标签,每个部分标签将数据 Angular 作为数据属性,我需要使用 CSS3 创建背景透明的右 Angular 设计。我有两种情况,

  1. 我使用交替行颜色,使用 css nth-child(odd)/(even) 将白色设置为奇数,将灰色设置为偶数。

  2. 在同一部分中,一些占位符也可以有背景图片。所以我需要为页面下的所有部分设置透明 Angular 设计。所以请告诉我如何使用 CSS3 实现这一点。请不要使用 jquery。

Code pen 上查看

CSS 代码

.main-wrap > section:nth-child(odd) {
background-color: #fff;
}

.main-wrap > section:nth-child(even) {
background-color: #e0e0e0;
}

.main-wrap > section {
height: 100px;
position-relative;
margin: 0;
padding: 20px 50px 20px 20px
}

section:before {
content: "";
position: absolute;
top: 0%;
right: 0%;
width: 0px;
height: 0px;
border-bottom: 60px solid transparent;
border-right: 60px solid transparent;
}

section:after {
position: absolute;
top: 0%;
right: 0%;
width: 0px;
height: 0px;
border-top: 60px solid transparent;
border-left: 60px solid transparent;
}

section[data-background="image"] {
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}

HTML代码

<html>
<body>
<div class="main-wrap">
<section data-background="image" style='background-image:url("http://i1.wp.com/static.web-backgrounds.net/uploads/2012/08/City_Landscape_Background.jpg")'>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex doloremque possimus, facilis libero cumque temporibus, aliquid quaerat voluptas adipisci perspiciatis officia dolores excepturi voluptatem modi iure officiis, dicta ullam beatae.</div>

</section>
<section>
<div>Quis dolorem recusandae id. Veniam dolorum a nemo est ducimus sed laboriosam unde laudantium aspernatur accusamus officia ab fugiat dicta maxime inventore, excepturi eaque, velit iste quaerat? Nobis, inventore, hic.</div>
</section>
<section>
<div>Quis dolorem recusandae id. Veniam dolorum a nemo est ducimus sed laboriosam unde laudantium aspernatur accusamus officia ab fugiat dicta maxime inventore, excepturi eaque, velit iste quaerat? Nobis, inventore, hic.</div>
</section>
</div>
</body>

</html>

示例模型设计: Sample Mockup design

最佳答案

这是我针对特定设计问题的解决方案。它是使用的 css 的变体 here .

/* bevel size, left offset and color settings next 3 lines */ 
.bvc {
width: 600px; /* width of overall box, variable or fixed */
margin: 0;
position: relative;
margin-top: -15px;
text-align:center;
font-weight:bolder;
}
.nomarg {
margin-top:0px !important;
}

.trwhite { border-right-color: white !important; }
.trtrans { border-right-color: #EEE !important; }
.trred { border-right-color: red !important; }
.trgray { border-right-color: gray !important; }

.red, .red > div {
background:red;
background-color:red;
}
.red > div {
border-color:red;
}
.white, .white > div {
background:white;
background-color:white;
}
.white > div {
border-color:white;
}
.gray, .gray > div {
background:gray;
background-color:gray;
}
.gray > div {
border-color:gray;
}
.black, .black > div {
background:black ;
background-color:black ;
color:white;
}
.black > div {
border-color:black;
}

.bevel, .content { border-width: 15px }
.bevel, .content { border-color: #efefef; border-style:solid; }
.tr, .bevel {
height: 0px;
width: 100%;
border-right-color: transparent;
border-top: 0;
}

.content {
background: #efefef no-repeat;
border-top: 0;
border-bottom: 0;
width:100%;
height:80px;
}

body {
margin: 20px;
font-family:tahoma;
font-size:18px;
background:#EEE;
}
<div class="bvc white nomarg">
<div class="bevel tr trtrans"></div>
<div class="content">Section 1</div>
</div>

<div class="bvc red ">
<div class="bevel tr trwhite"></div>
<div class="content">Section 2</div>
</div>

<div class="white bvc">
<div class="bevel tr trred"></div>
<div class="content">Section 3</div>
</div>

<div class="gray bvc">
<div class="bevel tr trwhite"></div>
<div class="content">Section 4</div>
</div>

<div class="white bvc">
<div class="bevel tr trgray"></div>
<div class="content">Section 5</div>
</div>

<div class="black bvc">
<div class="bevel tr trwhite"></div>
<div class="content">I need this design</div>
</div>

关于html - 如何使用 CSS3 使用数据属性值设置具有交替行颜色或图像的右 Angular 设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31871461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com