I have nested elements, the container has a border style of one sort and I want some of the elements inside it to have their own border overlapping the container's border. I tried using negative margin, but the border of the child is hidden underneath the parent's (seems to be overflow issue).
HTML:
<div class="right">
<div class="itemlist">
<ol>
<li>Abc</li>
<li class="special">Abc</li>
<li>Abc</li>
<li>Abc</li>
<li class="special">Abc</li>
<li>Abc</li>
<li>Abc</li>
</ol>
</div>
</div>
CSS:
.right {
position: fixed;
right: 0;
top: 0;
width: 200px;
height: 100%;
z-index: 100;
display: flex;
flex-direction: column;
border-left: 3px solid #76ff03;
}
.right .itemlist {
flex: 1;
overflow-y: auto;
}
.itemlist > ol > li {
border-bottom: 1px solid #76ff03;
padding-left: 20px;
}
.itemlist > ol > li:hover, .itemlist > ol > li.special {
border-left: 10px solid #2196f3;
border-bottom: 1px solid #2196f3;
margin-left: -3px;
}
I've seen some examples of this done and can make it work in some cases, but not consistently. I have an example JSFiddle with some layout, below is a picture of whet two of the list elements look like and what I want them to look like.
http://jsfiddle.net/jkondratowicz/e6uunLa4/1/
Here is a way to do it removing the margin on it's parent container and adding it to each row individually
.right {
position: fixed;
right: 0;
top: 0;
width: 200px;
background: #78909c;
height: 100%;
z-index: 100;
display: flex;
flex-direction: column;
}
.itemlist > ol > li {
border-bottom: 1px solid #76ff03;
border-left: 3px solid #76ff03;
padding-left: 20px;
}
Here are the styles you need using box-shadow
.itemlist > ol > li {
box-shadow: inset 3px -1px 0px 0px #76ff03;
padding-left: 20px;
}
.right .itemlist {
flex: 1;
overflow-y: auto;
box-shadow: inset 3px 0px 0px 0px #76ff03;
}
.itemlist > ol > li:hover, .itemlist > ol > li.special {
box-shadow: inset 10px -1px 0px 0px #2196f3;
padding-left: 25px;
}
.right {
position: fixed;
right: 0;
top: 0;
width: 200px;
background: #78909c;
height: 100%;
z-index: 100;
display: flex;
flex-direction: column;
}
http://jsfiddle.net/xnjn17uL/2/
Related
I understand that my parent-child relationship is what is hindering my z-index from working properly. But of the solutions I have seen, I am not able to fix without losing the hierarchy needed for my future development (The active class functionality, which is not yet implemented).
Background Info:
I'm making a tabs component, and my goal is mirror this design (note the slanted tab ends):
Here's what I was able to do:
The only issue with this is that this code is using float: right; for the li elements instead of what I want float: left;.
So because of that my tabs are ordered 4-1 instead of the proper order of 1-4.
When I do use float: left;, this issue comes up where my divs for the slanted tab ends are hidden behind the li elements:
Only the last tab's slanted div is left visible, as it is the only one not blocked.
Here's the Code:
ul.tabs {
margin: 0px;
// overflow: hidden;
clip-path: inset(0 -100vw 0 0);
display: inline-block;
}
ul.tabs>li.active {
// z-index: 2;
float: left; // text-align:right;
padding-right: 40px;
padding-top: 6px;
padding-left: 40px;
height: 56px;
background: lightblue;
box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
max-width: 222px;
position: relative;
z-index: 1;
box-sizing: border-box;
border: 1px solid #10172E;
}
.tab-slice.active:after {
content: '';
position: relative;
width: 10%; //40px
height: 100%;
top: 36px;
right: 1px;
border-right: 18px solid transparent;
border-bottom: 54.5px solid lightblue;
z-index: 3;
}
ul.tabs>li {
float: left;
padding-right: 40px;
padding-top: 6px;
padding-left: 40px;
height: 56px;
background: darkblue;
box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
max-width: 222px;
position: relative;
z-index: 1;
box-sizing: border-box;
border: 1px solid #10172E;
}
ul.tabs>li>a {
display: inline-block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
text-decoration: none;
color: $alis-white;
}
.tab-slice {
content: '';
position: absolute; //relative;
width: .5%;
height: 100%;
bottom: -1px;
right: -20px;
border-right: 18px solid transparent;
border-bottom: 56px solid #10172E;
z-index: 4;
}
.tab-slice:after {
content: '';
position: relative;
width: 10%; //40px
height: 100%;
top: 36px;
right: 1px;
border-right: 18px solid transparent;
border-bottom: 54.5px solid darkblue;
z-index: 4;
}
<div class="breadcrumb-container">
<div class="flight-search "><a (click)="openSearch"><mat-icon>search</mat-icon></a></div>
<ul class="tabs">
<li>
Tab 1
<div class="tab-slice "></div>
</li>
<li class="active">
Tab 2
<div class="tab-slice active"></div>
</li>
<li>
Tab 3
<div class="tab-slice"></div>
</li>
<li>
Tab 4
<div class="tab-slice"></div>
</li>
</ul>
</div>
The second to last option proposed in that article, almost works. but winds up looking like this:
I did this by commenting out the position attribute.
ul.tabs>li {
// position: relative;
}
How do I fix this layering issue?
This is the best I can fix it, the core solution is to reverse the elements when you add them in html. Then you can use the flex property flex-direction: row-reverse; so that the pseudo elements always come on the top!
Was not able to find a solution for the border thing for the pseudo element!
ul.tabs {
margin: 0px;
clip-path: inset(0 -100vw 0 0);
display: inline-flex;
flex-direction: row-reverse;
list-style: none;
align-items: center;
justify-content: center;
}
ul.tabs>li.active {
// z-index: 2;
float: left; // text-align:right;
padding-right: 40px;
padding-top: 6px;
padding-left: 40px;
height: 56px;
background: lightblue;
box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
max-width: 222px;
position: relative;
z-index: 1;
box-sizing: border-box;
}
ul.tabs>li {
padding-right: 40px;
padding-top: 6px;
padding-left: 40px;
height: 56px;
background: darkblue;
box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
max-width: 222px;
position: relative;
z-index: 1;
box-sizing: border-box;
border: 1px solid #10172E;
border-right:1px;
display:flex;
align-items: center;
justify-content: center;
}
ul.tabs>li>a {
display: inline-block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
text-decoration: none;
color: $alis-white;
}
ul.tabs>li:after {
content: '';
position: absolute;
width: 10%;
height: 0;
top: 0px;
left: calc(100% - 1px);
border-right: 18px solid transparent;
border-bottom: 56px solid darkblue;
}
li.active:after {
border-right: 18px solid transparent !important;
border-bottom: 56px solid lightblue !important;
}
<div class="breadcrumb-container">
<div class="flight-search ">
<a (click)="openSearch">
<mat-icon>search</mat-icon>
</a>
</div>
<ul class="tabs">
<li>
Tab 4
</li>
<li>
Tab 3
</li>
<li class="active">
Tab 2
</li>
<li>
Tab 1
</li>
</ul>
</div>
I want to create a tree diagram with last child's of the nodes should be in nth(last row of the tree) level. I am taking reference from here. As of now i am getting output like this(left), trying to get as right image.
I have tried with height and margin top in :before and :after, The links between the nodes are not coming correct. I am iterating the data for tree dynamically, there may be more levels if have more tree data. so need to set the line connection between node as generic. How can i get this? Suggestions please.
* {
margin: 0 auto;
padding: 0;
text-align: center;
color: black;
font-family: tahoma;
}
.items ul {
padding-top: 20px;
position: relative;
}
/* Make all children "inline" */
.items li {
/*float: left;*/
display: inline-block;
text-align: center;
list-style-type: none;
position: relative;
padding: 20px 5px 0 5px;
}
/* Add horizontal connector. Note: they are 2 pseudo-elements */
.items li::before, .items li::after {
content: '';
position: absolute;
top: 0;
right: 50%;
width: 55%;
height: 42px;
z-index: -1;
border-top: 1px solid #CCC;
}
.items li::after {
border-left: 1px solid #CCC;
left: 50%;
right: auto;
}
/* Remove left and right connector from a single child */
.items li:only-child::after, .items li:only-child::before {
display: none;
}
.items li:only-child {
padding-top: 0;
}
/* Remove "outer" connector */
.items li:first-child::before, .items li:last-child::after {
border: 0 none;
}
/* Add back the down connector for last node */
.items li:last-child::before {
border-right: 1px solid #CCC;
border-radius: 0 5px 0 0;
}
/* Add curve line to the first child's connector */
.items li:first-child::after {
border-radius: 5px 0 0 0;
}
/* Add down connector from parent */
.items ul ul::before {
content: '';
border-left: 1px solid #CCC;
z-index: -1;
height: 20px;
position: absolute;
top: 0px;
left: 50%;
width: 0;
}
/* Add cosmetic for each item */
.items li a {
font-size: 12px;
background-color: white;
border: 1px solid #CCC;
padding: 5px 10px;
height: 14px;
text-decoration: none;
display: inline-block;
border-radius: 4px;
}
/* Change bg-color while hovering each item */
.items li a:hover {
background-color: #EEF;
}
/* EXPERIMENTAL for multiple parents */
/* Add margin for the parents */
.items li a:not(:only-of-type) {
position: relative;
margin-bottom: 16px;
}
/* Add "down" connector (vertical line) from each multi-parent, EXCEPT the last one */
.items li > a:not(:last-of-type)::after{
content: '';
position: absolute;
border-left: 1px solid #CCC;
border-bottom: 1px solid #CCC;
top: 20px;
width: 75%;
height: 20px;
left: 50%;
z-index: -1;
}
/* Special case for the last multiple-parent, using border-right */
.items li > a:not(:only-of-type):last-of-type::after {
content: '';
position: absolute;
border-right: 1px solid #CCC;
border-bottom: 1px solid #CCC;
top: 20px;
width: 50%;
height: 20px;
right: 50%;
z-index: -1;
border-bottom-right-radius: 5px;
}
/* Give the curve line to the first multiple parent .... */
.items li > a:not(:only-of-type):first-child::after {
border-bottom-left-radius: 5px;
}
/* The middle element of multi-parents*/
.items li > a:not(:first-child):not(:last-of-type)::before {
content: '';
position: absolute;
border-bottom: 1px solid #CCC;
top: 40px;
width: 50%;
right: 50%;
z-index: -1;
}
.items ul:last-of-type li {
padding-left: 0;
padding-right: 0;
}
<div class="items">
<ul>
<li>
Dagon
Veil of Discord
Other Parent Item
<ul>
<li>
Null Talisman
<ul>
<li>Circlet</li>
<li>Mantle of Intelligence
<ul>
<li>earth
<ul>
<li>marsh</li>
<li>Mantle of agiled</li>
</ul>
</li>
<li>quick sun</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
According to a trick found in Stack overflow, I can change the background of the parent element hovering a child like this:
parent sibling { }
parent sibling:hover { }
parent:hover sibling { }
But I need to change the background color hovering different child elements. For example, hovering the Facebook button, the background goes blue, while hovering the Google + button, the backgroud goes red.
I've tried this:
<div class="share_box">
<div class="white-container">
<div class="facebook-sibling"/>
<a class="facebook-child-button"/>
<div class="twitter-sibling"/>
<a class="twitter-child-button"/>
<div class="googleplus-sibling"/>
<a class="googleplus-child-button"/>
</div>
</div>
but for multiple buttons it didn't work. The result I expect is similar to:
If you set the parent position: relative, it will contain any position: absolute children.
Create a new element inside the end of the parent, then make it position: absolute and position and size it so that it fills the parent.
Then use z-index: -1 to set it behind the rest of the content (e.g. the buttons).
Then you can use the General Sibling Combinator (~) to select the new element after the hovered element.
.facebook:hover ~ .background { background-color: rgb(50, 100, 150); }
.twitter:hover ~ .background { background-color: rgb(50, 150, 250); }
.google:hover ~ .background { background-color: rgb(250, 75, 50); }
.share {
position: relative;
}
.background {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
} /* Following styling for demo purposes only, not relevant */ .facebook:before { background-position:-46px -28px; width:101px; } .twitter:before { background-position:-151px -28px; width:90px; } .google:before { background-position:-245px -28px; width:94px; } .button:before { display:inline-block; content: ""; height:36px; background-image:url("http://i.stack.imgur.com/AXvMk.png"); border-radius: 3px; box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.2); } .button { display:inline-block; padding: 2px; } .white-container { padding: 10px 20px; font-size: 0; background: #fff; border-radius: 3px; } .background { background: #fff; } body { margin: 0 4px; border: 1px solid #aaa; border-top: 0px; box-shadow: 0px 2px 5px 0px rgba(0,0,0,0.1) } .share { padding: 10px 15px; box-shadow: 0px 5px 5px -5px rgba(0,0,0,0.3) inset } body:before { content: ''; height: 4px; display: block; background: #fff; border-bottom: 1px solid #aaa } html { background: #efefef }
<div class="share">
<div class="white-container">
<div class="background"></div>
</div>
</div>
Is this what you want?
DEMO 1: http://jsfiddle.net/t73431y8/
DEMO 2: http://jsfiddle.net/t73431y8/2/
HTML:
<div class="PARENT">
<div class="RED">RED</div>
<div class="BLUE">BLUE</div>
<div class="GREEN">GREEN</div>
</div>
CSS:
.PARENT{
position: relative;
}
.RED{
display: inline-block;
margin: 5px;
padding: 5px;
color: #BB0000;
background: #FFF;
}
.RED:hover:after{
display: block;
width: 100%;
height: 100%;
background: #BB0000;
position: absolute;
top: 0px;
left: 0px;
content: ' ';
z-index: -1;
}
.BLUE{
display: inline-block;
margin: 5px;
padding: 5px;
color: #0000BB;
background: #FFF;
}
.BLUE:hover:after{
display: block;
width: 100%;
height: 100%;
background: #0000BB;
position: absolute;
top: 0px;
left: 0px;
content: ' ';
z-index: -1;
}
.GREEN{
display: inline-block;
margin: 5px;
padding: 5px;
color: #00BB00;
background: #FFF;
}
.GREEN:hover:after{
display: block;
width: 100%;
height: 100%;
background: #00BB00;
position: absolute;
top: 0px;
left: 0px;
content: ' ';
z-index: -1;
}
I'm trying to center an anchor tag which is displayed as a CSS3 shape (a large "play"-arrow) in a div.
My markup is as follows:
<div class="element halfcol">
<div class="inner beige-bg fullheight">
<div class="element-content">
</div>
</div>
</div>
And the CSS is:
.element {
float: left;
margin-right: 20px;
margin-bottom: 20px;
}
.element .inner {
border: 2px solid #94111e;
min-height: 50px;
border-radius: 10px;
background-color: #fcf9e3;
height: inherit;
-moz-box-shadow: 2px 2px 6px #646464;
-webkit-box-shadow: 2px 2px 6px #646464;
box-shadow: 2px 2px 6px #646464;
}
.element .inner .element-content {
padding: 10px 15px;
height: inherit;
}
.element .inner .no-padding {
padding: 0px;
}
.element .beige-bg {
background-color: #fcf9e3;
}
.element .red-bg {
background-color: #94111e;
}
.element .transparent-bg {
background-color: transparent;
}
.element .white-bg {
background-color: #ffffff;
}
.element .smallheight,
.element .doubleheight,
.element .fullheight {
overflow-y: hidden;
}
.element .smallheight {
height: 90px;
}
.element .doubleheight {
height: 220px;
}
.element .doubleheight .element-content {
position: relative;
}
.element .fullheight {
height: 350px;
}
.element .no-padding {
padding: 0px !important;
}
/**** Shapes ****/
.play-button {
display: block;
margin: 0 auto;
border-left: 100px solid #94111e;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
}
Which gives me this:
What I'm looking for is this:
I could just give it a margin top/left to center it, but the .element container is of variable height and width.
Anyone know how to achieve this? :-)
Thanks in advance!
You need to make the .element-content be position:relative and then
add
position:absolute;
top:50%;
left:50%;
margin-top:-60px;
margin-left:-50px;
to the .play-button
Demo at http://jsfiddle.net/jKs6F/
I changed your .play-button class as follows:
.play-button {
display: block;
margin: 0 auto;
border-left: 100px solid #94111e;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
margin-left: -50px; /* half border-left value */
margin-top: -60px; /* border-top value */
position: relative; left: 50%; top: 50%;
}
See demo
I'm trying to use :after selector to draw a inside-border in every div I hover. Now the ":after" pseudo class doesn't work? any idea why this selector doesn't work? if I just use the :hover pseudo class works, the thing is that I want to use both classes!
Have a look at this EX
thanks!
<body>
<h1>Example Six</h1>
<p>Grade: A</p>
<p>this is the thing</p>
<div class="w3c">
<div id="tab16">
cars
<div class="test">
<div><img alt="" src="http://placehold.it/176x106/" /></div>
</div>
</div> <!-- ends tab16 -->
<div id="tab17">
othercars
<div>
<div><img alt="" src="http://placehold.it/180x110/" /></div>
<div><img alt="" src="http://placehold.it/180x110/" /></div>
</div>
</div> <!-- ends .w3c -->
</body>
The css:
#charset "utf-8";
/* CSS Document */
.w3c {
min-height: 250px;
position: relative;
width: 554px;
}
.w3c > div {
display: inline;
}
.w3c > div > a {
margin-left: -1px;
position: relative;
left: 1px;
text-decoration: none;
color: #fff;
background: #666666;
display: block;
float: left;
padding: 5px 10px;
border: 1px solid #ccc;
border-bottom: 1px solid white;
}
.w3c > div:not(:target) > a {
border-bottom: 0;
background: #b0b0b0;
/*-moz-linear-gradient(top, white, #eee); */
}
.w3c > div:target > a {
background: white;
color: #b0b0b0;
}
.w3c > div > div {
background: white;
z-index: 0;
left: 0;
top: 30px;
bottom: 0;
right: 0;
padding: 10px;
border: 1px solid #ccc;
width: 596px;
height: 133px;
}
.w3c div div > div {
border: 1px solid red;
float: left;
width: 180px;
height:110px;
margin-left: 10px;
}
.w3c div div > div:hover:after {
border: 1px solid black;
width:178px;
height: 108px;
}
/* .w3c > div > div > a > img:after {
border: 2px solid black;
width:178;
height: 108px;
} */
.w3c > div:not(:target) > div {
position: absolute;
}
.w3c > div:target > div {
position: absolute;
z-index: 1;
}
For the :after pseudo-element to show up you need to give it content and display it as a block.
Then, absolutely position the :after and relatively position the div itself:
.w3c div div > div {
position: relative;
border: 1px solid red;
float: left;
width: 180px;
height: 110px;
margin-left: 10px;
}
.w3c div div > div:hover:after {
display: block;
content: '';
position: absolute;
border: 1px solid black;
width: 178px;
height: 108px;
}
I've found out what the problem is.
::after is used to add content after an existing element, not to style elements that come after things.
You might want to use nth-child() to target the x elements, or every x element.
.w3c div div > div:nth-child(2):hover {
border: 1px solid black;
}
http://css-tricks.com/how-nth-child-works/