With the following simplified code,
$("[data-position]").each(function() {
$(this).css({
position: 'absolute',
left: $(this).data('position')[0] + '%',
top: $(this).data('position')[1] + '%',
})
});
ul {position: relative;
width: 15em;height: 15em;
background: #0af;
list-style: none}
strong,em {padding: .5em}
strong {background: #000; color: #fff;z-index:50}
em {display: none;background: #fff;z-index:-1}
li:hover em{display: block}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li data-position="[20,20]">
<strong>A</strong>
<em>This is an ay</em>
</li>
<li data-position="[10,10]">
<strong>B</strong>
<em>This is a bee</em>
</li>
<li data-position="[30,30]">
<strong>C</strong>
<em>This is a see</em>
</li>
</ul>
The :hover-displayed element gets hidden by following siblings.
I tried to look at many similar questions and answers on this website but could not come up with an interesting answer. Changing the z-index or opacity levels do not work.
What could bring a hover-displayed element to the very top of z-index, whatever the position of siblings in the dom?
Go through the link to get the solution
em {
background: #fff none repeat scroll 0 0;
display: none;
position: relative;
z-index: 1000;
}
You need to add z-index:1;position:relative in em class.
$("[data-position]").each(function() {
$(this).css({
position: 'absolute',
left: $(this).data('position')[0] + '%',
top: $(this).data('position')[1] + '%',
})
});
ul {position: relative;
width: 15em;height: 15em;
background: #0af;
list-style: none}
strong,em {padding: .5em}
strong {background: #000; color: #fff;z-index:50}
em {display: none;background: #fff;z-index:1;position:relative}
li:hover em{display: block}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li data-position="[20,20]">
<strong>A</strong>
<em>This is an ay</em>
</li>
<li data-position="[10,10]">
<strong>B</strong>
<em>This is a bee</em>
</li>
<li data-position="[30,30]">
<strong>C</strong>
<em>This is a see</em>
</li>
</ul>
Related
This question already has answers here:
Does UL have default margin or padding [duplicate]
(2 answers)
Closed 1 year ago.
I've seen other posts similar to this but they didn't seem to provide a solution. I'm kaing a js calendar and the days are inside a however I cannot get the items to align left, it seems like they are padded on the left side see img below.
I am hoping someone can tell me if theres a way to remove this ghost padding?
many thanks :)
I have included my current code and the css classes I'm currently using. I have a few vue inline styles but
<!--jan-->
<div v-if="month==1" class="month">
<div>
<div>
<b>January</b><br><span> {{this.year}}</span>
</div>
<div>
<ul v-bind:style="{ 'display': 'flex', 'justify-content':'space-between'}">
<li class="prev">❮</li>
<li class="next">❯</li>
</ul>
</div>
</div>
<ul class="weekdays">
<li class="days">Mo</li>
<li class="days">Tu</li>
<li class="days">We</li>
<li class="days">Th</li>
<li class="days">Fr</li>
<li class="days">Sa</li>
<li class="days">Su</li>
</ul>
<ul class="daysList">
<li class="daynum">1</li>
<li class="daynum">2</li>
<li class="daynum">3</li>
<li class="daynum">4</li>
<li class="daynum">5</li>
... etc
</ul>
</div>
<!--jan-->
////css//////
.daysList{
width: 100%;
list-style: none;
display: flex;
flex-wrap: wrap;
text-align: left;
justify-content: left;
background: rgb(231, 131, 131);
}
.daysList li{
background-color: lime;
display: inline;
margin: .5em;
width: 22px;
padding: 5px;
}
.daysList li:hover{
cursor:pointer;
color:white;
background-color: blue;
}
The <ul> has some margin and padding added by the user agent stylesheet. You can remove them from your calendar component's <ul>s with:
<style scoped>
ul {
margin: 0;
padding: 0;
}
</style>
demo
This HTML list (ordered but my special order),
<ul class="custom">
<li value="II">Alpha</li>
<li value="III">Beta</li>
<li value="☸" >Gamma</li>
<li value="MXX">Delta</li>
</ul>
With CSS
.custom { list-style: none; }
.custom li:before {
content: attr(value) ". ";
}
Shows the list, but I not see how to align "numbers" as in usual list.
See the point-align problem at https://jsfiddle.net/0yb7aee8/
In default list the number are in the ul/ols padding.
You can make st. similar like this.
.listaEspecial {
list-style: none;
list-style-position: outside;
padding-left: 0;
margin-left: 0;
}
.listaEspecial li:before {
content: attr(value) ". ";
text-align: right;
display: inline-block;
width: 45px;
padding-right: 10px;
}
Build-in list:
<ul class="listaEspecial">
<li value="II">Alpha</li>
<li value="III">Beta</li>
<li value="☸" >Gamma</li>
<li value="MXX">Delta</li>
</ul>
<hr/>
Standard list (better spacing and point-align):
<ol type="I" start="2">
<li>Alpha</li>
<li>Beta</li>
<li value="100000" >Gamma</li>
<li>Delta</li>
</ol>
The ul/ols padding is 40px, I used 55px (45px width + 10px padding for :before because of longer number.
Look that in default lists there is a problem with longer number too, 40px is too short for gamma and delta items.
I'm trying to make a vertical navigation that is in a skewed parent div. My goal is to have all the list items follow the same path as the edge of the parent div, I'm not quite certain how to go about it.
I typed up a sample in codepen showing the default behaviour.
http://codepen.io/anon/pen/YWYQmd
<div class="parent">
<ul class="navigation">
<li><a>text</a></li>
<li><a>text</a></li>
<li><a>menu</a>
<ul class="submenu">
<li><a>text</a></li>
<li><a>text</a></li>
<li><a>menu</a>
<ul class="submenu">
<li><a>text</a></li>
<li><a>text</a></li>
</ul>
</li>
</ul>
</li>
<li>text</li>
<li>text</li>
<li>text</li>
</ul>
</div>
.parent {
background: rgba(123,23,55,0.2);
width: 500px;
text-align: right;
transform: skew(-20deg);
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
li {
transform: skew(20deg);
}
.submenu{
transform: skew(-20deg);
}
Any tips to make it line up like I want? Thanks!
The issue comes from 'unskewing' the li elements: in the case the li element has another ul, then the whole block becomes unskewed.
What you need to do is 'unskew' only the content of the li, not the li itself. Assuming all your text will be within an a tag, then just replace your 'unskew' with:
li a{
display: inline-block;
transform: skew(20deg);
}
See result here: http://codepen.io/anon/pen/VjyzYq
Question: How do I get this to work for tabbing, using CSS only? (Tabbing already works).
#menu:before {
content:"Menu \25bc";
font-weight:bold;
width:100%;
}
#menu:hover:before {
content:"Menu \25b2";
}
#menu li {
position:absolute;
left:-9999px;
}
#menu:hover li {
position:relative;
left:0;
}
<html>
<title>Test</title>
<body>
<header>
Link to homepage
</header>
<nav>
<ul id="menu">
<li>Menu item 1</li>
<li>Menu item 2</li>
</ul>
</nav>
<main>
<p>Other text with maybe a link here.</p>
</main>
</body>
</html>
EDIT: Original question follows.
I have a menu:
<ul id="menu">
<li>Menu item 1</li>
<li>Menu item 2</li>
</ul>
However, I want to hide it at a narrow page width, so I apply the following CSS:
#media (max-width: 768px) {
#menu:before {
content:"Menu \25bc";
}
#menu:hover:before {
content:"Menu \25b2";
}
#menu a {
position:absolute;
left:-9999px;
}
#menu:hover a {
position:relative;
left:0px;
}
}
This hides the menu, adds the word "Menu" in it's place, with a down or up arrow, depending on the hover state, which also shows the menu when you hover over it.
The problem is that, while :hover works just fine, I cannot get both to show by tabbing to one of the tags, using the :focus pseudo class. (Alas, :root will not work like other pseudo classes, so something like #menu a:focus:root #menu a { position:relative; left:0; } won't work, as far as I can see).
Does anyone have any ideas as to how I could approach this, using only CSS? Or have I dug myself into a hole?
Based on OP comment below:
I'm happy to change the HTML, but how would :target work here?
here is a snippet with :target
nav {
height: 0;
overflow: hidden;
position: relative;
}
nav:target {
height: auto;
}
nav + div a:before {
content: "Menu \25bc";
font-weight: bold;
width: 100%;
}
nav:target + div a:before {
content: "Menu \25b2";
}
nav:target + div .open,
nav + div .close {
display: none;
}
nav:target + div .close,
nav + div .open {
display: block;
position: absolute;
top: 0
}
<nav id="menu">
<ul>
<li>Menu item 1
</li>
<li>Menu item 2
</li>
</ul>
</nav>
<div>
<a class="open" href="#menu"></a>
<a class="close" href="#"></a>
</div>
When trying to add an box with content inside it on a menu on a hover "drop down menu", it does something like this:
(source: gyazo.com)
I want the drop down to popup when I hover on the categories menu item.
This is the code I used for it:
<div class="secondheader">
<div class="container">
<div class="span12">
<ul class="nav6">
<li>Home</li>
<li class="dropdown1">Categories </li>
<li>Buy</li>
<li>Sell</li>
<li>Forums</li>
<li>Contact</li>
<li>item 1</li>
<li>Forums</li>
<li>Contact</li>
<li>item 1</li>
</ul>
</div>
</div>
</div>
</div>
The CSS:
.secondheader {
background-image: url("../img/second.png");
width: 100%;
height: 66px;
border-bottom: solid 6px #f0e8ce;
}
.nav6 {
list-style: none;
font-family: 'Dosis', sans-serif;
float: left
font-size: 20px;
margin-top: 13px;
margin-left: -35px;
}
.nav6 li {
display: inline;
margin: 0px;
font-size: 18px;
font-family: 'Dosis', sans-serif;
float: left;
margin-top: 10px;
}
.nav6 a {
color: #7d7253;
padding-top: 20px;
padding-bottom: 20px;
padding-left: 20px;
padding-right: 20px;
}
.nav6 a:hover {
background-image: url("../img/hoverbg.png");
color: #53410f;
text-decoration: none;
}
I've tried using tutorials but I don't really understand on how to make the same thing for my layout I mean it has different ways and classes.
Do you want something like http://jsfiddle.net/b76Qc/?
Edit:
In your case the submenu is horizontal because you use descendant selectors instead of child selectors:
replace .nav6 li with .nav6>li and .nav6 li ul with .nav6>li>ul
See my jsfiddle if you want the complete code.
Edit 2:
If you want each element to have a different background,
<li class="dropdown1">Categories
<ul>
<li style="background:red">Buy</li>
<li style="background:blue">Sell</li>
<li style="background:green">Forums</li>
...
</ul>
</li>
But can you provide a link to your site instead of images? The square shown in http://gyazo.com/35835f003d0d8b776248196632cc1d4a.png is weird, but I can't know what's happening just with images...
Edit 3:
You have to change
.nav6 a {
color: #7D7253;
padding: 20px;
}
into
.nav6>li>a {
padding: 20px;
}
.nav6 a {
color: #7D7253;
}
And
.nav6 a:hover {
background-image: url("../img/hoverbg.png");
color: #53410F;
text-decoration: none;
}
into
.nav6 a:hover {
color: #53410F;
text-decoration: none;
}
.nav6 > li > a:hover {
background-image: url("../img/hoverbg.png");
}
Edit 4:
Sorry I didn't explain why I was telling you to use selectors with >, I thought you knew it.
Your html is like this:
<ul class="nav6">
<li>Home</li>
<li class="dropdown1">Categories
<ul>
<li>Buy</li>
<li>Sell</li>
<li>Forums</li>
<li>Contact</li>
<li>item 1</li>
<li>Forums</li>
<li>Contact</li>
<li>item 1</li>
</ul>
</li>
</ul>
If you use .nav6 a, the style will be applied to all <a> inside .nav6. That's a descendant selector.
Then, this will be applied both to menu's links and submenu's links:
<ul class="nav6">
<li>Home</li>
<li class="dropdown1">Categories
<ul>
<li>Buy</li>
<li>Sell</li>
...
</ul>
</li>
</ul>
But if you use a child selector like .nav6>li>a, the style is applied only to the links which are childs of a <li> which is a child of .nav6 (only menu's links). This way we can set which styles we want to apply to all links and which to menu's links:
<ul class="nav6">
<li>Home</li>
<li class="dropdown1">Categories
<ul>
<li>Buy</li>
<li>Sell</li>
...
</ul>
</li>
</ul>
Edit 5:
To fix the problem with backgrounds,
change
.nav6 a:hover {
color: #53410F;
text-decoration: none;
}
to
.nav6>li:hover>a, .nav6 .dropdown1 li:hover>a {
color: #53410F;
text-decoration: none;
}
and
.nav6 > li > a:hover
background-image: url("../img/hoverbg.png");
}
to
.nav6>li:hover>a {
background-image: url("../img/hoverbg.png");
}
To show you how little code is actualy required to make this work i set up a small example here: http://jsfiddle.net/fS5WV/
I put the explanations in the css.
The key lies in nesting the menu's properly, and giving the submenus a position absolute to prevent them from pushing the content down.
I hope it makes sense. Feel free to ask if you need further explanation.