CSS: how to get class inside class - html

I am making a dropdown on hover, but I have a problem with CSS. I have class inside class inside a div etc. The problem is that the dropdown list doesn't show. I think that I am doing something wrong with CSS selectors.
This is html code:
<div id="header">
<div class="row-2">
<ul class="hover">
<li>Home</li>
<li><a>Pershkrimi</a>
<div class="button">
<ul class="file_menu">
<li>klzxd</li>
</ul>
</div>
</li>
<li>
Trailera
</li>
<li>
Kategorite
</li>
<li class="last">
Sitemap
</li>
</ul>
</div>
</div>
CSS:
#header .row-2 {
height:51px;
}
#header .row-2 ul {
width:100%;
overflow:hidden;
}
#header .row-2 ul li {
float:left;
font-size:20px;
line-height:2.4em;
margin-right:5px;
background-color:#000;
}
#header .row-2 ul li.last {
margin-right:0;
}
#header .row-2 ul li a {
text-decoration:none;
color:#f0f0f0;width:184px;
height:56px;float:left;
background-image:url(images/nav-bg.gif);b
ackground-repeat:no-repeat;
background-position:0 0;
text-align:center;
}
#header .row-2 ul li a:hover, #header .row-2 ul li a.active {
color:#d72a18;
background-image:url(images/nav-act.gif);
}
/*Dropdown*/
#header .row-2 ul li div.button {
height: 32px;
width: 184px;
margin: auto;
}
#header .row-2 ul li div.button ul, li {
margin: 0;
padding: 0;
list-style: none;
}
#header .row-2 ul li div.button ul .file_menu {
display: none;
width: 300px;
border: 1px solid #1c1c1c;
}
#header .row-2 ul li div.button ul.file_menu li {
background-color: #302f2f;
}
#header .row-2 ul li div.button ul .file_menu li a {
color:#FFFFFF;
text-decoration:none;
padding:10px;
display:block;
}
#header .row-2 ul li div.button ul .file_menu li a:hover {
padding:10px;
font-weight:bold;
color: #F00880;
}
/SLIDESHOW/
#slogan
{
width:100%;
height:auto;
position:relative;
background:url(images/banner-bg.gif) no-repeat left top;
color:#1d1d1d
}
#slogan .image
{
position:absolute;
right:-30px;
top:-11px;
z-index:100;
width:100%;
height:auto;
overflow: hidden;
background:url(images/banner-img.png) no-repeat left top
}
#slogan p
{
margin-bottom:23px
}
#slogan .inside
{
padding: 0 0 25px;
width:939px
}
#page1 #content .box
{
margin:0
}
#page1 #header .row-2 ul li a
{
height:56px
}
#page1 #header .row-2 ul li.last a:hover
{
position:relative;z-index:2
}
.slideshow
{
position:relative;
width:500px;
height:332px;
}
.slideshow img
{
position:absolute;
left:4px;
top:10px;
}
NOTE: I just added slideshow CSS, that i think is overwriting dropdown
Thank You,

There are a lot of things I would do differently with how you've got your CSS laid out, but if you're looking for a simple answer, use the > child selector instead of just a space in order to select only those lists that are in your row-2 class. For example,
#header .row-2>ul
will get only <ul> elements whose parent is a .row-2 element, which seems to be what you're looking for.

Related

Place logo in-between menu items

I want to put the logo in-between the navigation menus but I can't figure out how to do it in the theme that I have because I'm having trouble finding it in the backend. I'm sure it's just a matter of reordering something or adding a margin and a space for the photo... Under the header section of the CSS this is the code:
#header { padding:0 20px;margin-bottom:8px;}
#logo { float:left; }
#logo { text-transform:capitalize; padding:35px 0; }
#logo img { max-width:100%; }
#navigation { float:right; margin-right:20px; }
#navigation ul { list-style:none; position:relative; }
#navigation ul li { float:left; padding-left:30px; font-size:12px; display:block; position:relative; font-weight:bold; }
#navigation ul li a { color:#888; padding-bottom:10px; padding-top:35px; display:block; }
#navigation ul li ul { position:absolute; border:1px solid #e9e9e9; display:none; left:15px; padding-bottom:15px; z-index:9999; }
#navigation ul li ul li { min-width:150px; margin-left:15px; margin-right:15px; padding:15px 0 10px 0; border-bottom:1px solid #f6f6f6; font-weight:normal; font-size:10px; }
#navigation ul li ul li:last-child { border:0; padding-bottom:0; }
#navigation ul li ul li a { border:0; display:block; padding:0; }
#navigation li:hover ul { display:block; }
#navigation select { display:none; -webkit-appearance: none; border-radius: 0; }
#navigation ul li#magic-line { position: absolute; left: 0; width: 100px; height: 4px; padding-left:0; display:none; }
I suppose u are using wordpress theme ? If so, each li has its own classes. So you should create one "empty" menu, and add it as background of that link, you can make link to be home page. Text you can hide with text-indent:-9999px;
If u have exact link, i can be more helpful, check how i pulled it out here: http://itsgoran.com/cider
Update:
code should be like this:
li#menu-item-15 {
background-image: url(http://www.new.sheisbiddy.com/wp-content/uploads/2015/11/SHEISBIDDYmainlogoandslogan1.png);
width: 470px;
height: 130px;
background-repeat: no-repeat;
text-indent: -9999px;
}
but i suggest firstly to create smaller logo image, then use that image for this, and ofcourse add smaller width and height which would be width/height of that smaller image.

Horizontal menu center elements

I have the following files:
html file
<nav>
<ul>
<li><b>Alle Rezepte</b></li>
<li><b>Alle Zutaten</b></li>
</ul>
</nav>
css file
nav {
}
nav ul {
text-align: center;
}
nav ul li {
display: inline;
}
And it looks like this in the browser
But I want the two elements two be center in their own half, like this
|----------li1-----------|---------li2------------|
instead of
|---------------------li1|li2---------------------|
What do I have to add to my code have it the way I want it?
Try this:
http://jsfiddle.net/GCu2D/691/
CSS:
nav ul {
text-align: center;
margin:0;
padding:0;
list-style-type:none;
white-space:nowrap;
}
nav ul li {
float:left;
width:50%;
}
try like this: Updated Demo
nav {
margin:0 auto;
text-align: center;
width:100%;
background-color:#ccc;
border:1px solid #666;
}
nav ul {
margin:0 auto;
}
nav ul li {
display:inline-block;
padding:10px 15px;
list-style-type:none;
background-color:#ccc;
border-right:1px solid #666;
text-align: center;
}
nav ul li a {
font-weight:bold;
display:block;
text-align: center;
}
Use float and text-align:
li {float: left; width: 50%; text-align: center; list-style: none;}
li a {display: block;}
http://jsfiddle.net/5gLkdaw5/
Give the li a width.
see it all here http://codepen.io/mike-grifin/pen/bdVZJP
CSS:
nav ul {
top: 0;
left: 0;
}
nav ul li {
}
.example {
background-color: green;
display: inline-block;
padding: 20px;
margin: 0;
width: 46%;
text-align: center;
}
HTML:
<nav>
<ul>
<li class="example"><b>Alle Rezepte</b></li>
<li class="example"><b>Alle Zutaten</b></li>
</ul>
</nav>
See jsFiddle
You can use display:table;
nav ul {
text-align: center;
display:table;
table-layout:fixed;
width:100%;
}
nav ul li {
display: table-cell;
}

CSS multi level menu with nested list

(source: torrent-invites.com)
I want to make pure CSS multi level menu like the picture above. I have tried some tutorial but its not working for me. Menu "xxxxx" and "yyyyy" appear below menu "bbbbb" for my CSS code below.
What I want to make is 3 level menu like the picture above.
This is my HTML for the menu:
<span id="nav">
<ul>
<li>ssss
<ul>
<li>aaaaa</li>
<li>bbbbb
<ul>
<li>xxxxx</li>
<li>yyyyy</li>
</ul>
</li>
</ul>
</li>
<li>ttttt</li>
<li>uuuuu</li>
</ul>
</span>
And this is my minimized CSS code:
li {
list-style:none !important;
}
#nav, #nav ul {
list-style: none;
padding:0;
margin:0;
}
#nav li {
line-height:20px;
float:left;
}
#nav li ul{
display:none;
}
#nav ul li ul {
margin-top:-3em;
margin-left:7em;
}
#nav ul li:hover ul {
z-index:99999;
display:list-item !important;
position:absolute;
margin-top:2px;
margin-left:0px;
padding: 5px 15px;
background: #8ac312;
}
#nav ul li:hover ul li {
float:none;
padding: 2px 0px;
}
#nav ul li:hover ul li > a:before {
content: '» ';
}
Any help would be very appreciated to make my CSS code working like the illustration picture above. Thanks.
I think your problem is position relative and absolute. I remove your style and do on my own (simpler, uglier). Code is here jsFiddle
And the code is:
CSS:
ul { padding:0; margin:0; }
li { list-style:none; }
li > ul { display: none; }
li:hover > ul { display: block; }
.lvl1 li { margin-right: 10px; display: inline; position:relative; }
.lvl2 { position: absolute; }
.lvl2 li { position: relative; }
.lvl3 { position: absolute; top:0px; left: 50px; }
HTML:
<span id="nav">
<ul class='lvl1'>
<li>ssss
<ul class='lvl2'>
<li>aaaaa</li>
<li>bbbbb
<ul class='lvl3'>
<li>xxxxx</li>
<li>yyyyy</li>
</ul>
</li>
</ul>
</li>
<li>ttttt</li>
<li>uuuuu</li>
</ul>
</span>
I've edited your code a bit ... check this fiddle http://jsfiddle.net/kau5h/
li {
list-style:none !important;
position:relative;
}
#nav, #nav ul {
list-style: none;
padding:0;
margin:0;
}
#nav li {
line-height:20px;
float:left;
}
#nav li a {display:block;}
#nav li ul{
display:none;
z-index:99999;
/*display:list-item !important;*/
position:absolute;
/*margin-top:2px;*/
margin-left:0px;
background: #8ac312;
}
#nav li ul ul {left: 100%; top:0;}
#nav ul li ul {
/*margin-top:-3em;
margin-left:7em;*/
}
#nav ul li:hover > ul {
display: block;
}
#nav ul li:hover ul li {
float:none;
/*padding: 2px 0px;*/
}
#nav ul ul li {
padding: 5px 15px;
display: block;
}
#nav ul ul li > a:before {
/*content: '» '; */
}

How can I make my horizontal navigation bar a drop down menu?

I've tried making horizontal drop down navigation bars following tutorials, however they are never centered and I can't figure out how to center them. I tried going in the opposite direction and centering my navigation bar first, and then attempting to make it a drop down menu, though this seems to throw everything off. This is the code I have.
EDIT: The problem I am having is that the submenu is displayed when the page is loaded, along with a bullet point, which I'm sure can be fixed by setting the list-style to none, however I'm not sure where in the CSS this should be.
I'm trying to create a menu similar to THIS. I understand this uses joomla and I am not.
#header {
height: 100px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
#content {
max-width: 700px;
margin-left: auto;
margin-right: auto;
padding: 20px;
}
#footer {
height: 85px;
padding-top: 40px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
#menu {
margin: 0 auto;
display: inline-block;
list-style: none;
padding: 0;
border-top: 1 solid #ccc;
border-left: 1 solid #ccc;
border-bottom: 1 solid #ccc;
}
#menu li {
float: left;
}
#menu li a {
display: block;
padding: 10px 10px;
text-decoration: none;
font-weight: bold;
}
#menu li a:hover {
color: #c00;
}
<ul id="menu">
<li>Home
</li>
<li>Kandi
<ul>
<li>Claim Kandi
</li>
</li>
<li>Events
</li>
<li>Artists
</li>
<li>Community
</li>
<li>Merchandise
</li>
</ul>
Add this CSS:
#menu, #menu ul {
margin:0 auto;
padding:0;
}
#menu li {
float: left;
position: relative;
list-style: none;
}
#menu > li:hover > ul {
display: block;
}
#menu > li > ul {
display: none;
position: absolute;
}
#menu li a {
white-space: nowrap;
}
http://jsfiddle.net/tcKvH/1/
use this css
#menu{
position:absolute;
top:150px;
left:8%;
padding:0;
margin:0;
}
#menu ul{
padding:0;
margin:0;
line-height:30px;
}
#menu li{
position:relative;
float:left;
list-style:none;
background:rgba(0,0,0,1);
border-radius:5px;
}
#menu ul ul{
position:absolute;
visibility:hidden;
padding:0;
margin:0;
top:30px;
}
#menu ul li a{
text-align:center;
font:"Arial Black", Arial;
font-size:24px;
color:rgba(255,255,255,9);
width:150px;
height:30px;
display:block;
text-decoration:none;
}
#menu ul li:hover{
background-color:rgba(128,128,128,1);
text-decoration:none;
}
#menu ul li:hover ul{
visibility:visible;
z-index:1;
}
#menu ul li:hover ul li a{
background:rgba(0,0,0,9);
z-index:1;
border-bottom:1px solid rgba(160,160,164,1);
opacity:0.9;
text-decoration:none;
border-radius:5px;
}
#menu ul li ul li:hover{
background:rgba(128,128,128,1);
opacity:0.8;
text-decoration:underline;
}
with this html code
<div id="menu">
<ul>
<li>Home</li></ul>
<ul>
<li>Video <!--This is in main menu-->
<ul>
<li>Technology</li> <!--This is in drop downmenu-->
<li>Tutorial</li> <!--This is in drop downmenu-->
</ul>
</li>
</ul>

set all nested li's to be width of widest li

How do I make nested li's the same width?
When I use the below code each nested li is only as wide as it's text + margin.
I'd like all of the li's to be as wide as the widest li under the parent ul.
eg:
<ul id="menu">
<li Menu a</li>
<li Menu b</li>
<li Nested Menu
<ul>
<li <a href="#" title="Menu Item">Menu Item</li>
<li Long Menu Item</li>
<li Longer Menu Item</li>
</ul>
</li>
<li Menu z</li>
</ul>
with css:
<style type="text/css" media="all">
* {
padding:0;
margin:0;
}
body, html {
width: 100%;
height: 100%;
}
#wrapper {
width: 800px;
height: 100%;
margin: auto;
}
#menu {
margin: 0 0 0 8px;
padding: 0;
font-size: 14px;
font-weight: normal;
}
#menu ul {
list-style-type:none;
list-style-position:outside;
position:relative;
z-index:300;
height: 32px;
font-weight:bold;
white-space: nowrap;
padding:0;
}
#menu a {text-decoration:none;
line-height: 32px;
}
#menu a:hover {
}
#menu li {
float:left;
position:relative;
display: inline;
height: 100%;
list-style-type: none;
padding: 0 20px;
background: #ccc;
}
#menu ul {
position:absolute;
display:none;
left:0px;
background: #BDCCD4;
width:100%;
}
#menu ul a, #menu li a {
display: block;
}
#menu li ul {
background: #BDCCD4;
display:block;
}
#menu li ul a {
font-weight: normal;
height:auto;
float:left;
}
#menu ul ul {
padding: 0 9px;
display:block;
}
#menu li ul li {
padding: 0 9px;
background: #BDCCD4;
}
#menu li:hover {
background: #ddd;
height: 32px;
}
#menu li li:hover, #menu li li li:hover {
background: #ddd;
height: 32px;
}
#menu li a:link, #menu li a:visited {
text-decoration: none;
color: #003E7E;
margin: auto;
}
Simply adding width: 100% for #menu li ul li works for me. To make it work for even longer items, use width: auto on #menu li ul. EDIT 2: Added padding workaround.
The new CSS:
<style type="text/css" media="all">
* {
padding:0;
margin:0;
}
body, html {
width: 100%;
height: 100%;
}
#wrapper {
width: 800px;
height: 100%;
margin: auto;
}
#menu {
margin: 0 0 0 8px;
padding: 0;
font-size: 14px;
font-weight: normal;
}
#menu ul {
list-style-type:none;
list-style-position:outside;
position:relative;
z-index:300;
height: 32px;
font-weight:bold;
white-space: nowrap;
padding:0;
}
#menu a {text-decoration:none;
line-height: 32px;
}
#menu a:hover {
}
#menu li {
float:left;
position:relative;
display: inline;
height: 100%;
list-style-type: none;
padding: 0 20px;
background: #ccc;
}
#menu ul {
position:absolute;
display:none;
left:0px;
background: #BDCCD4;
width:100%;
}
#menu ul a, #menu li a {
display: block;
}
#menu li ul {
background: #BDCCD4;
display:block;
width: auto;
}
#menu li ul a {
font-weight: normal;
height:auto;
float:left;
}
#menu ul ul {
padding: 0 0 0 9px;
display:block;
}
#menu li ul li {
padding: 0 9px;
background: #BDCCD4;
width: 100%;
}
#menu li:hover {
background: #ddd;
height: 32px;
}
#menu li li:hover, #menu li li li:hover {
background: #ddd;
height: 32px;
}
#menu li a:link, #menu li a:visited {
text-decoration: none;
color: #003E7E;
margin: auto;
}
The result is here: http://jsfiddle.net/y83zm/2/
EDIT 2 Added fix to solve a weird padding issue, see http://jsfiddle.net/y83zm/5/
You'll need to use JavaScript to set all LIs the same width as the widest LI. Here's the code if you want to use the jQuery library:
$(document).ready(function(){
$("#menu > li > ul").each(function() { // Loop through all the menu items that got submenu items
var Widest=0; // We want to find the widest LI... start at zero
var ThisWidth=0; // Initiate the temporary width variable (it will hold the width as an integer)
$($(this).children()).each(function() { // Loop through all the children LIs in order to find the widest
ThisWidth=parseInt($(this).css('width')); // Grab the width of the current LI
if (ThisWidth>Widest) { // Is this LI the widest?
Widest=ThisWidth; // We got a new widest value
}
});
Widest+='px'; // Add the unit
$(this).parent().css('width',Widest);
$(this).children().css('width',Widest);
});
});
CSS change:
#menu li ul li {
padding: 0 9px;
background: #BDCCD4;
padding: 0 20px;
}
Check it out at JSFiddle.
Edit: Fixed my misunderstanding. :)
There would be a very simple dynamic solution. To your CSS, as you posted it in the Question, just add
#menu ul {
display: inline-block;
min-width: 100px;
}
#menu ul li, #menu ul li a{
width: 100%;
display:block;
}
and then it will be exactly as you want it to be.
You can see how it looks here:
<style type="text/css" media="all">
* {
padding:0;
margin:0;
}
body, html {
width: 100%;
height: 100%;
}
#wrapper {
width: 800px;
height: 100%;
margin: auto;
}
#menu {
margin: 0 0 0 8px;
padding: 0;
font-size: 14px;
font-weight: normal;
}
#menu ul {
list-style-type:none;
list-style-position:outside;
position:relative;
z-index:300;
height: 32px;
font-weight:bold;
white-space: nowrap;
padding:0;
}
#menu a {text-decoration:none;
line-height: 32px;
}
#menu a:hover {
}
#menu li {
float:left;
position:relative;
display: inline;
height: 100%;
list-style-type: none;
padding: 0 20px;
background: #ccc;
}
#menu ul {
position:absolute;
display:none;
left:0px;
background: #BDCCD4;
width:100%;
}
#menu ul a, #menu li a {
display: block;
}
#menu li ul {
background: #BDCCD4;
display:block;
}
#menu li ul a {
font-weight: normal;
height:auto;
float:left;
}
#menu ul ul {
padding: 0 9px;
display:block;
}
#menu li ul li {
padding: 0 9px;
background: #BDCCD4;
}
#menu li:hover {
background: #ddd;
height: 32px;
}
#menu li li:hover, #menu li li li:hover {
background: #ddd;
height: 32px;
}
#menu li a:link, #menu li a:visited {
text-decoration: none;
color: #003E7E;
margin: auto;
}
#menu ul {
display: inline-block;
min-width: 100px;
}
#menu ul li, #menu ul li a{
width: 100%;
display:block;
}
<ul id="menu">
<li Menu a</li>
<li Menu b</li>
<li Nested Menu
<ul>
<li <a href="#" title="Menu Item">Menu Item</li>
<li Long Menu Item</li>
<li Longer Menu Item</li>
</ul>
</li>
<li Menu z</li>
</ul>
To make all of the list items the same length as the longest, you will need to manually set the widths. There is no pure CSS method of achieving this automatically as far as I know.
li{width:100%} Will make the list items fill the width of their container. If that is not set, then it will be the width of the user's browser window.
A simple jQuery solution worked for me:
$(document).ready(function(){
$('.sub-menu').each(function(){
$(this).width(2000);
var width = 0;
$(this).children('li').each(function(){
if ($(this).children('a').width() > width)
width = $(this).children('a').width();
});
$(this).width(width);
});
});
I used following CoffeeScript to achieve described behavior:
$ ->
menu_toggle = (e, show) ->
ul = $(e).find('ul')
ul.toggle()
computed = ul.hasClass 'computed_width'
if show && !computed
ul.width 2000 # enormous with to be sure that li’s’ texts are not wrapped
max_width = 0
ul.find('li').each ->
li = $(this)
width = li.width()
max_width = width if width > max_width
ul.width max_width + 30 if max_width # 20 is 2 * padding + some reserve
ul.toggleClass 'computed_width' # no need to compute every time
$('li').has('ul').hover ->
menu_toggle this, true
, ->
menu_toggle this, false