gpt4 book ai didi

html - 如何向列表的 CSS 添加 block 颜色?

转载 作者:行者123 更新时间:2023-11-28 10:50:26 25 4
gpt4 key购买 nike

我正在使用 HTML 和 CSS3 制作图表,我能够轻松地为列表的整体颜色设置样式,但我只想为每个列表的前 30 像素设置样式

这是我的字符到目前为止的样子以及我想要实现的目标:

enter image description here

CSS:

body {
width:auto;
}

* {margin: 0; padding: 0;}

ul {
line-height:20px;
}

.tree ul {
padding-top: 20px; position: relative;

transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}

.tree li {
float: left; text-align: center;
list-style-type: none;
position: relative;
padding: 20px 5px 0 5px;

transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}



.tree li::before, .tree li::after{
content: '';
position: absolute; top: 0; right: 50%;
border-top: 1px solid #ccc;
width: 50%; height: 20px;
}
.tree li::after{
right: auto; left: 50%;
border-left: 1px solid #ccc;
}


.tree li:only-child::after, .tree li:only-child::before {
display: none;
}


.tree li:only-child{ padding-top: 0;}


.tree li:first-child::before, .tree li:last-child::after{
border: 0 none;
}

.tree li:last-child::before{
border-right: 1px solid #ccc;
border-radius: 0 0px 0 0;
-webkit-border-radius: 0 0px 0 0;
-moz-border-radius: 0 0px 0 0;
}
.tree li:first-child::after{
border-radius: 0px 0 0 0;
-webkit-border-radius: 0px 0 0 0;
-moz-border-radius: 0px 0 0 0;
}

/*Time to add downward connectors from parents*/
.tree ul ul::before{
content: '';
position: absolute; top: 0; left: 50%;
border-left: 1px solid #ccc;
width: 0; height: 20px;
}

.tree li a{
border: 1px solid #ccc;
padding: 5px 10px;
text-decoration: none;
color: #666;
font-family: arial, verdana, tahoma;
font-size: 13px;
display: inline-block;

border-radius: 0px;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;

transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}


.tree li a:hover, .tree li a:hover+ul li a {
background: #dae2f2; color: #000; border: 1px solid #94a0b4;
}

.tree li a:hover+ul li::after,
.tree li a:hover+ul li::before,
.tree li a:hover+ul::before,
.tree li a:hover+ul ul::before{
border-color: #2663A6;
}

HTML:

<div class="tree">
<ul>
<li>

<a href="#"><span>Chairman / Owner</span><p>Name</p></a>

<ul>
<li>
<a href="#">Managing Director</a>
<ul>

<li>
<a href="#">Director</a>
<li>
<a href="#">Director</a>
<li>
<a href="#">Director</a>

</ul>
</ul>



</li>
</ul>



</div>

http://jsfiddle.net/F3CQk/

最佳答案

有很多方法可以解决这个问题。这是一个。

http://jsfiddle.net/isherwood/F3CQk/4/

span.accent {
background-color: lightblue;
display: block;
margin: -5px -10px 5px;
padding: 5px;
}

<a href="#"><span class="accent">Chairman / Owner</span><span>Name</span></a>

关于html - 如何向列表的 CSS 添加 block 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21335193/

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