I have this drop down menu, that when it's hovered some of the content is going behind another div. It looks like this:
The css for the menu is like this:
.nav-m {
height: 50px;
width: 60px;
display: block;
position: absolute;
z-index: 9999;
overflow-y: hidden;
text-align: center;
position: absolute;
}
.nav-m:hover {
width: 140px;
height: 210px;
}
.nav-m a {
display: none;
text-indent: -9999px;
position: relative;
height: 20px;
padding: 13px 0;
color: #fff !important;
}
nav a:first-child:hover {
text-indent: -9999px;
}
.nav-m:hover>a {
display: block;
}
.nav-m:hover>a:first-child:after {
color: #6daeaf;
background: #505664;
}
.nav-m a:first-child {
display: block;
text-align: center;
margin-bottom: 16px;
cursor: default;
}
.nav-m a:after {
position: absolute;
top: 0;
padding: 12px 0;
width: 60px;
color: #fff;
font-family: 'icons';
font-size: 24px;
display: block;
text-indent: 0;
background: #6daeaf;
}
nav a:hover {
text-indent: 0px;
text-align: left;
margin-left: 70px;
}
.nav-m a:hover:after {
color: #999;
background: #fff;
text-align: center;
margin-left: -70px;
}
.nav-m a:first-child:before {
position: absolute;
text-indent: 0;
top: 55px;
left: 23px;
content: "";
width: 0;
height: 0;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #6daeaf;
}
.nav-m a:first-child:hover:before {
margin-left: -70px;
}
.nav-m a:first-child:after {
left: 0;
content: "m";
background: #656d7e;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.nav-m a:nth-child(2):after {
content: "p";
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.nav-m a:nth-child(3):after {
content: "s";
}
.nav-m a:last-child:after {
content: "e";
-webkit-border-bottom-left-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-moz-border-radius-bottomleft: 5px;
-moz-border-radius-bottomright: 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
Below the menu div is .container, .row and then a div with class='span12' (I'm using bootstrap)
The HTML looks like this:
<div id="topbg">
<div class="span9">span9 content here</div>
<div class="span3 avatar-holder" >
<nav class="nav-m" onmouseover="">
Menu
Account
Settings
Email
Email
Email
Email
Email
Email
Email
</nav>
</div>
</div>
</div><!--end row-->
</div><!--end topbg-->
<div class='container' style='margin-top:20px;'>
<div class='row'>
<div class='span12' style='margin:0;'>
span 12 content
</div><!--end span12-->
</div><!--end row-->
So, I've tried setting the z-index to -1 on the following divs: .row, .container, .span12 with no luck. I've also tried settings the overflow to visible on every possible div. I can't find the problem here.
Can anyone help me out?
The div is not overlaping the menu. It is the menu items which are not visible.
You have text-indent: -9999px on .nav-m a menu items and you reverted that for first three items thanks to following CSS
.nav-m a:nth-child(3):after {
content: "s";
}
.nav-m a:nth-child(2):after {
content: "p";
}
.nav-m a:first-child:after {
content: "m";
}
Now look at general styles for all your menu items:
.nav-m a:after {
position: absolute;
top: 0;
padding: 12px 0;
width: 60px;
color: #FFF;
font-family: 'icons';
font-size: 24px;
display: block;
text-indent: 0;
background: #6DAEAF;
}
It misses the content property which is crucial here. Without it the pseudo-element :after won't be rendered at all.
To prove that, I prepared a JSFIDDLE with your code (no modifications). It doesn't contain this overlaping div at all but the problem is still present.
If you want to stay with this approach I'd suggest a minor change which will spare you lots of CSS.
To every menu item anchor add an attribute data-shortcut which will hold the first letter of the menu item
Settings
and so on... Now you can access this attribute in CSS content property
content: attr(data-shortcut);
Thanks to that you don't need to define CSS for every menu item with different first letter.
Try to give z-index value more than div on which it is overlapping.
Example : If div1 contains z-index 10, then give greater z-index to <nav>which is hiding behind `div1'.
Z-index only effects elements that have a position set to them. Make sure you have position:relative or position:absolute set to both the dropdown and the div covering it.
Related
I have a list component with a custom bullet defined as a before pseudoelement:
li:before {
display: inline-flex;
width: .8rem;
height: .8rem;
margin-right: 1.5rem;
margin-left: -2.9rem;
background-color: #00c878;
border-radius: .375rem;
content: "";
}
It all works fine as long as the li content doesn't overflow the container. Then, the whole content just jumps down a few pixels and leaves a weird top margin between the bullet and the content.
I have recreated it here.
I have managed to make it disappear using work-break: break-all, but that is of course not a susteinable solution.
Any tips?
So many solutions. but this one worked best
Please Set position to absolute on the pseudo element and remove margin. My solution uses positioning to get wrapped lines automatically line up correctly.
Advantages:
very compact code
works with any font size (no absolute pixel values contained)
aligns rows perfectly (no slight shift between first line and following lines)
.container {
width:170px;
border:1px solid red;
}
ul {
margin: 0;
padding: 0;
}
li {
padding-left: 35px;
margin-bottom: 24px;
margin-top: 0;
font-size: 16px;
line-height: 24px;
list-style-type: none;
position:relative;
word-break: break-all;
}
li::before {
width: 4px;
height: 4px;
background-color: #00c878;
border-radius: 375px;
content: "";
position: absolute;
left: 10px;
top: 9px;
}
<div class="container">
<div class="list unordered">
<h3 class="text-grey-150 h5 "> Branchen ETFs </h3>
<ul class="">
<li>Technologie ETF
<br>
</li>
<li style="/* word-break: break-all; */">Finanzdienstleistungen ETF</li>
<li>Gesundheitswesen ETF
<br>
</li>
<li>Immobilien ETF
<br>
</li>
<li>Industrie ETF</li>
</ul>
</div>
</div>
When doing custom pseudo-elements it's better to position them absolute and relative to the li. See example below, this has fixed your issue:
li {
padding-left: 35px;
margin-bottom: 24px;
margin-top: 0;
font-size: 16px;
line-height: 24px;
list-style-type: none;
position: relative;
}
li::before {
display: inline-flex;
width: 4px;
height: 4px;
margin-right: 15px;
margin-left: -29px;
background-color: #00c878;
border-radius: 375px;
content: "";
position: absolute;
top: 9px;
}
You can use top and left properties to re-position as per your needs.
I'm creating a chat bubble with CSS and HTML.
If there is no text in the chat bubble I do not want it to display.
I can get body of the chat bubble to go away using :empty but I cannot get the triangle part of the chatbox to disappear because it was created with the pseudo selector :before and content: ' '.
My code is below. Is there anyway to make this little triangle go away if the h4 element is empty?
/* CSS talk bubble */
.myFeedback h4:empty {
display: none;
}
.talk-bubble {
margin-top: 220px;
left: 390px;
display: inline-block;
position: absolute;
width: 200px;
height: auto;
background-color: purple;
}
.round {
border-radius: 10px;
}
.tri-right.right-in:before {
content: '';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -20px;
top: 38px;
bottom: auto;
border: 12px solid;
border-color: purple transparent transparent purple;
}
/* talk bubble contents */
.talktext {
padding: 10px;
text-align: center;
line-height: 1.5em;
}
.talktext p {
/* remove webkit p margins */
-webkit-margin-before: 0em;
-webkit-margin-after: 0em;
}
/* end of talk bubble stuff */
<div class="myFeedback">
<div id='guess-feedback' class="talk-bubble tri-right round right-in">
<h4 class="talktext"></h4>
</div>
</div>
/* CSS talk bubble */
h4:empty {
display: none;
}
.talk-bubble {
margin-top: 220px;
left: 390px;
display: inline-block;
position: absolute;
width: 200px;
height: auto;
background-color: purple;
}
.round{
border-radius: 10px;
}
.tri-right.right-in h4:before {
content: '';
position: absolute;
width: 0;
height: 0;
left: auto;
right: -20px;
top: 38px;
bottom: auto;
border: 12px solid;
border-color: purple transparent transparent purple;
}
/* talk bubble contents */
.talktext{
padding: 10px;
text-align: center;
line-height: 1.5em;
}
.talktext p{
/* remove webkit p margins */
-webkit-margin-before: 0em;
-webkit-margin-after: 0em;
}
/* end of talk bubble stuff */
<div class="myFeedback">
<div id='guess-feedback' class="talk-bubble tri-right round right-in">
<h4 class="talktext"></h4>
</div>
</div>
<div class="myFeedback">
<div id='guess-feedback' class="talk-bubble tri-right round right-in">
<h4 class="talktext">With Text</h4>
</div>
</div>
Change below code in your CSS
From:
.tri-right.right-in:before
To
.tri-right.right-in h4:before
I'm looking for a solution to group html elemts with a background. The real problems are the rounded corners highlighted in the picture. Is there a way to achieve this?
This solution still needs some work, but it's pretty close.
FIDDLE
Basically, I add a pseudo element before each list item using nth-child to group them with a particular color.
Also I set a lower z-index for each group.
I might be possible to play with the clip property to perfect this.
Markup
<ul>
<li></li><li></li><li class="last"></li>
<li></li><li></li><li></li><li></li><li></li><li class="last"></li>
<li></li><li></li><li></li><li class="last"></li>
</ul>
CSS
ul
{
list-style:none;
width: 350px;
}
li:before
{
content: '';
border-radius: 10px;
display: inline-block;
position: absolute;
top: -10px;
left: -10px;
height:70px;
width: 80px;
z-index:-1;
}
li:nth-child(-n+3):before
{
background: brown;
z-index: -2;
}
li:nth-child(n+4):nth-child(-n+9):before
{
background: green;
z-index: -3;
}
li:nth-child(n+10):nth-child(-n+13):before
{
background: pink;
z-index: -4;
}
li
{
width: 50px;height: 50px;
background: black;
border-radius: 10px;
margin: 5px 5px 10px 5px;
display: inline-block;
position:relative;
}
.last:before
{
z-index: -1!important;
width: 70px;
}
.last + li:before
{
border-radius: 10px 10px 10px 0;
}
/* clip the last item in each row */
li:nth-child(5n):before
{
width: 70px;
}
I experience some strange text alignment, can you give me a hint where the Problem is:
I was trying to create a speechbubble:
.round
{
margin-top: 5px;
border-radius:50%;
background-color:#3d5177;
width:50px;
height:50px;
float: left;
}
.number {
color: white;
padding: 8px 17px;
font-size: 30px;
font-weight: normal;
}
.faq_container {
overflow: hidden;
}
.talkbubble {
left: 80px;
position: relative;
width: 340px;
height: 100px;
padding: 0px;
background: #aaaaaa;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
.talkbubble:after {
content: '';
position: absolute;
border-style: solid;
border-width: 10px 13px 10px 0;
border-color: transparent #aaaaaa;
display: block;
width: 0;
z-index: 1;
left: -13px;
top: 22px;
}
.talkbubble_text {
display: block;
text-align: left;
padding: 10px;
}
http://jsfiddle.net/Lf4sr/
Thanks
The problem is with the <div class="round"> CSS. The width of the element is pushing the text over to the right.
Add this to the .round class:
.round {
top: 0;
left: 0;
position: absolute;
}
And add this to the .faq_container class:
.faq_container {
position: relative;
}
Demo
Note: You can remove float: left; from .round.
Correct CSS should be:
.talkbubble {
left: 30px; /* or Whatever you may want the distance from the circle to be */
position: relative;
width: 340px;
height: 100px;
padding: 10px;
background: #aaaaaa;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
float: left;
}
.talkbubble_text {
display: inline;
text-align: left;
/* padding: 10px; ( remove this )*/
}
try adding float:left to the .talkbubble container
You can try this:
Fiddle here
.talkbubble_text {
display: inline-block;
text-align: left;
padding: 10px;
line-height:16px;
}
Good Luck...:)
I think the issue is that your last line of text is not inline with the others. This is due to the way you are laying out your code. Your text is being pushed across by your round element, which is a set height. Any text after this is not being pushed across, a quick fix would be to add a margin on the bottom of the number circle.
.round
{
margin-top: 5px;
border-radius:50%;
background-color:#3d5177;
width:50px;
height:50px;
float: left;
margin-bottom : 50px;
}
http://jsfiddle.net/Lf4sr/4/
But would probably be better to restructure your code a little to stop this happening in the first place.
Change positions, add overflow:hidden to .talkbubble_text to prevent float left align. Fiddle.
Updated: http://jsfiddle.net/Bushwazi/Lf4sr/8/
There are a lot of things that could be cleaned up in this example. There is lots of extra html. But the core problem is that if you are using float for one part, you have to use it for both. So you need to add float:left or right to .talkbubble and remove the left value.
.talkbubble {
/* left: 80px; */
position: relative;
width: 340px;
height: 100px;
padding: 0px;
background: #aaaaaa;
float:left;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
I did a bunch of other stuff in the fiddle to simplify and eliminate extra html/css too. But the core problem was mixing positioning with float and choosing just one.
I have a (CSS) stacking question.
The tab-boxes on my development site below have z-index set as -1 so that their border appears behind the tabs above them, so that the active tab's white bottom border covers it. But on all browsers but Opera this makes descendants of the tab-boxes (links, forms, etc.) unclickable. You can see this at:
http://od.philosofiles.com/
Can anyone help? Here's the bare bones of the HTML and CSS, though examining the link above with Firebug would probably be more illuminating:
<ul class="odtabs">
<li id="tab-Authors1" class="first active">Tab</li>
</ul>
<div id="tab_content-Authors1" class="odtab-content">
<p>Tab Box</p>
</div>
<style type="text/css">
<!--
.odtabs li {
float: left;
background-color: #ddd;
width: 80px;
height: 19px;
list-style-type: none;
}
.odtabs li.active {
background-color: white;
border-bottom-color: white;
}
.odtab-content {
border: 1px solid #babcbd;
margin-top: -1px;
clear: both;
position: relative;
top: -1px;
z-index: -1;
}
-->
</style>
Set z-index to -100.
.odtab-content {
border:1px solid #BABCBD;
clear:both;
font-size:0.9166em;
margin-top:-1px;
padding:0 1em;
position:relative;
top:-1px;
z-index:-100;
}
I finally fixed this myself, after a lot of experimentation with line-by-line reconstruction. I believe the problem was due to the z-index being negative; however, the only way to make it work with a positive z-index and a higher positive z-index was to set position: relative on the tabs, which required quite a different approach. (Apparently z-index only works on absolute, relative or fixed positioned elements.) Here, for those interested/with similar problems, is the full CSS I used:
ul.odtabs {
display: inline;
margin: 0;
padding: 0;
}
.odtabs li {
float: left;
background-color: #ddd;
border: 1px solid #babcbd;
width: 80px;
height: 19px;
margin-right: 2px;
text-align: center;
list-style-type: none;
position: relative;
z-index: 2;
}
.odtabs li.active {
background-color: white;
border-bottom-color: white;
}
.odtabs a {
color: #78797c;
font-size: 0.75em; /* 9px = 12*0.75 */
font-weight: bold;
margin-top: 0px;
padding-top: 0px;
}
.odtabs .last {
margin-right: 0px;
}
.odtab-content {
font-size: 0.9166em;
border: 1px solid #babcbd;
padding: 0px 1em; /* ie. 12px */
clear: both;
position: relative;
top: -1px;
z-index: 1;
}