Div ul list css menu - html

How can I have a child div appear when I hover on the parent div? Please view.Fiddle My apologies if my code is incorrect.
Thank you

I know you have not mentioned jQuery as your tag but here is a solution which does the trick.
If you can use jQuery then I suggest you to use to achieve what you want because changing CSS property of one element when another element is hovered on is bit tricky and has many limitations,
Here is a simplified fiddle with jQuery
This is the jQuery script that you can add in your file,
$(document).ready(function(){
$("#a11").mouseover(function(){
$("#submenu11").show();
});
$("#a11").mouseout(function(){
$("#submenu11").hide();
});
});
One more thing, it is not advisable to have id that starts with number, in your case id="11" might have issues in some browsers, that's why I have substituted id=11 with id="a11"
If due to some reasons you don't want to use jQuery then I can give you an alternative approach using JavaScript

#submenu11 {
width:550px;
height:400px;
float:none;
padding-left:1px;
padding-top:1px;
margin-right; 10px;
font: 15px/30px sans-serif;
clear: left;
margin-left: 181px;
border: 1px solid blue;
border-bottom: 5px solid blue;
}
#left1, #right1 {
width: 35%;
float:left;
margin-top: -85px;
}
#left1 {
margin-right: 1px;
border: 1px solid green;
box-sizing: inline-block;
height: 100%;
}
#right1 {
display: inline-block;
box-sizing: border-box;
width: 60%;
height: 100%;
border: 1px solid red;
}
#abc_11 {
font: 15px/30px sans-serif;
height: 300px;
width:170px;
display: inline-block;
line-height:30px;
background-color:white;
float:left;
padding-right:10px;
border-right: 1px solid #0057A4;
clear:left;
}
submenulist ul li {
list-style-type: none;
clear: left;
margin-left: -40px ;
}
a.menu1 {
font: 15px/30px sans-serif;
height: 30px;
width: 170px;
display: inline-block;
line-height: 30px;
background-color: white;
float: left;
padding-left:20px;
border-right: 1px solid blue;
margin-left: -10px;
clear:left;
text-decoration: none;
color: black;
}
a.submenulink1 {
border-right: 0px solid #E1E1E1;
border-top: 0px solid #444;
color: black;
display: block;
text-align: left;
padding-left: 10px;
text-decoration: none;
width: 100%;
font: 15px/30px sans-serif;
height: 30px;
}
a.submenulink1:hover {
background: lime;
color: white;
}
.hide
{
display:none;
}
#abc_11:hover#abc_11 + #submenu11{
display:block;
}
<div>
<div id="abc_11">
<a class="menu1" href="#">GALAXY 11</a>
</div>
<div id="submenu11" class="hide">
<div id="left1">
<ul class="nav1">
<li class="submenulist"><a class="submenulink1" href="#">GALAXY S6 Edge</a></li>
<li class="submenulist"><a class="submenulink1" href="#">GALAXY S6</a></li>
<li class="submenulist"><a class="submenulink1" href="#">GALAXY S5</a></li>
<li class="submenulist"><a class="submenulink1" href="#">GALAXY S4 Mini</a></li>
<li class="submenulist"><a class="submenulink1" href="#">GALAXY S3 Mini VE</a></li>
</ul>
</div>
<div id="right1">
<img src="http://www.samsung.com/uk/next/img/estore-recommend- images/mobiles/S6edgegreen.jpg" alt=""></img>
GALAXY S6 Edge information
</div>
</div>
</div>
I guess there is some issue with id being a number.

For the sake of simplicity, you may want to look into a readymade menu solution like this one:
http://users.tpg.com.au/j_birch/plugins/superfish/examples/
The advantage is that you will get a crossbrowser compatible solution.

Related

How to place navbar menu below logo?

I have built this header using custom CSS and bootstrap class names. I have tried z-index, float: initial properties already. Thanks in advance
.branding-preview {
height: 75px;
margin-left: 15px;
margin-right: 15px;
background-color: #0071bb;
}
.branding-logo {
float: left;
height: 50px;
font-size: 18px;
padding: 15px 15px;
}
.branding-logo img {
width: 300px;
height: 50px;
}
.branding-powered-by-logo {
float: right;
height: 50px;
color: white;
font-size: 15px;
padding: 2px 10px;
}
.preview-menu {
margin: 30px 0 0 0;
}
.preview-menu > li > a {
margin: 0 3px;
color: white;
text-transform: uppercase;
border-bottom: solid 1px transparent;
background-color: transparent !important;
}
<div class="branding-preview">
<div class="branding-logo">
<img id="branding-logo" src="/path/to/logo">
</div>
<div class="branding-powered-by-logo">
<span>Powered By</span>
<img id="branding-powered-by-logo" src="/path/to/logo" height="30">
</div>
<ul class="navbar-nav navbar-right nav preview-menu">
<li><a>Start</a></li>
<li><a>Plan</a></li>
<li><a>Manage</a></li>
<li><a>Learn</a></li>
<li><a>Admin</a></li>
</ul>
</div>
This is the result that I am getting with the current code,
actual result:
This is what I'm hoping it will look like, expected result:
Isn't simple without all the css rules, but the concept is: Create a wrapper floated to right and inside create 2 lines, one for the branding-powered-by-logo and display:block the second line is depend from actual CSS but probably works without modify anything.
If you can post the real page we can help you with more precision.
Hope this help you.
.branding-preview {
display:block;
height: 75px;
margin-left: 15px;
margin-right: 15px;
background-color: #0071bb;
}
.branding-logo {
float: left;
height: 50px;
font-size: 18px;
padding: 15px 15px;
}
.branding-logo img {
width: 300px;
height: 50px;
}
.branding-powered-by-logo {
/* ADDED */
display:block;
text-align:right;
height: 50px;
color: white;
font-size: 15px;
padding: 2px 10px;
}
.preview-menu {
margin: 0px 0 0 0;
}
.preview-menu > li > a {
margin: 0 3px;
color: white;
text-transform: uppercase;
border-bottom: solid 1px transparent;
background-color: transparent !important;
}
/* ADDED */
.wrapper-logo-navbar {
float: right;
}
.preview-menu > li {
display: inline-block;
}
<div class="branding-preview">
<div class="branding-logo">
<img id="branding-logo" src="/path/to/logo">
</div>
<div class="wrapper-logo-navbar">
<div class="branding-powered-by-logo">
<span>Powered By</span>
<img id="branding-powered-by-logo" src="https://cdn.pixabay.com/photo/2012/05/02/19/27/head-46086_960_720.png" height="30">
</div>
<ul class="navbar-nav navbar-right nav preview-menu">
<li><a>Start</a></li>
<li><a>Plan</a></li>
<li><a>Manage</a></li>
<!-- removed some elements for the rendering on StackOverflow -->
</ul>
</div>
</div>
I think you just need add
position:absolute; right:0px;
to your .preview-menu class.

hide element in another parent

How would i go about hiding or showing an element that is contained in a container, based on another container's hover state?
Here's what i have so far, as an example:
HTML5
<div class="left-menu-container">
<div class="left-menu-inner-container">
<div class="left-menu-item-container">
<a href="AppsDashboard" class="left-menu-link">
<div class="left-menu-item-first">
Find an Application
</div>
</a>
<div class="sub-menu">
<input type="text" value="Enter app name here" onclick="Clear(this, 'Enter app name here');" onblur="Reset(this, 'Enter app name here');" />
</div>
</div>
</div>
</div>
CSS3
div.left-menu-container {
float: left;
width: 19%;
padding-right: 1%;
}
div.left-menu-inner-container {
width: 100%;
}
div.left-menu-item-container
{
width:100%;
}
div.left-menu-item-first {
width: 93%;
border: 1px solid #999;
-webkit-border-top-right-radius: 10px;
-moz-border-radius-topright: 10px;
border-top-right-radius: 10px;
transition: 0.15s ease-in-out;
color: black;
min-height: 26px;
padding-left: 1%;
}
div.left-menu-item-first:hover {
width: 97%;
border: 1px solid #999;
color: white;
background-image: linear-gradient(rgb(44,119,208),rgb(27,90,159));
padding-left: 3%;
}
div.left-menu-item-container .sub-menu {
width: 97%;
border: 1px solid #999;
color: white;
background-image: linear-gradient(rgb(44,119,208),rgb(27,90,159));
padding-left: 3%;
display: none;
}
div.left-menu-item-first:hover left-menu-item-container.sub-menu {
position:absolute;
width: 80%;
border: 1px solid #999;
color: white;
background-image: linear-gradient(rgb(44,119,208),rgb(27,90,159));
float:left;
display: block;
z-index: 1000;
float: left;
}
However, that simply does not work. Hovering over the left-menu-item-first div does not show the submenu contained in the left-menu-item-container parent. Do they really and absolutely must be children of the parent for this to work with Pure CSS? I can and already had a JQuery version setup and going but i wanted to do it via CSS only if possible.
You can only alter child elements and sibling elements on hover, never a completely different element.
if you put the submenu right after the first menu element, you can use the sibling selector + as follows:
div.left-menu-container {
float: left;
width: 19%;
padding-right: 1%;
}
div.left-menu-inner-container {
width: 100%;
}
div.left-menu-item-container
{
width:100%;
}
div.left-menu-item-first {
width: 93%;
border: 1px solid #999;
-webkit-border-top-right-radius: 10px;
-moz-border-radius-topright: 10px;
border-top-right-radius: 10px;
transition: 0.15s ease-in-out;
color: black;
min-height: 26px;
padding-left: 1%;
}
div.left-menu-item-first:hover {
width: 97%;
border: 1px solid #999;
color: white;
background-image: linear-gradient(rgb(44,119,208),rgb(27,90,159));
padding-left: 3%;
}
div.left-menu-item-container .sub-menu {
width: 97%;
border: 1px solid #999;
color: white;
background-image: linear-gradient(rgb(44,119,208),rgb(27,90,159));
padding-left: 3%;
display: none;
}
.left-menu-link:hover + .sub-menu {
position:absolute;
width: 80%;
border: 1px solid #999;
color: white;
background-image: linear-gradient(rgb(44,119,208),rgb(27,90,159));
float:left;
display: block;
z-index: 1000;
float: left;
}
<div class="left-menu-container">
<div class="left-menu-inner-container">
<div class="left-menu-item-container">
<span class="AppsDashboard">
<a href="AppsDashboard1" class="left-menu-link">
<div class="left-menu-item-first">
Find an Application
</div>
</a>
<div class="sub-menu">
<input type="text" value="Enter app name here" onclick="Clear(this, 'Enter app name here');" onblur="Reset(this, 'Enter app name here');" />
</div>
</span>
</div>
</div>
</div>
Since there is no CSS parent selector, try altering your html such that the hovered item is a sibling of left-menu-item-container.sub-menu
Try using a CSS sibling selector:
Change:
div.left-menu-item-first:hover left-menu-item-container.sub-menu
to
div.left-menu-item-first:hover + left-menu-item-container.sub-menu
Or
Change:
div.left-menu-item-first:hover left-menu-item-container.sub-menu
to
.left-menu-link:hover + left-menu-item-container.sub-menu

Change div height when tab is selected

I have a tabbed content that has 4 tabs and in each there are going to be two divs that make up the border design. The problem that I'm running into is that I have no idea how to animate the divs to change height when the tab they're located in is selected. I have a fiddle for reference and the markup is below.
HTML
<div class="container">
<ul class="tabs">
<li class="tab-link current" data-tab="tab-1" id="welcome_selector">Welcome</li>
<li class="tab-link" data-tab="tab-2">Tab Two</li>
<li class="tab-link" data-tab="tab-3">Tab Three</li>
<li class="tab-link" data-tab="tab-4">Tab Four</li>
</ul>
<div class="tabcontentcontainer">
<div id="tab-1" class="tab-content current"> <div class="bordertop_animate"> </div>welcome tab will be empty, save for the borders <div class="borderbottom_animate"></div></div>
<div id="tab-2" class="tab-content"><div class="bordertop_animate"></div> tab 2 content<div class="borderbottom_animate"></div> </div>
<div id="tab-3" class="tab-content"><div class="bordertop_animate"></div> tab 3 content<div class="borderbottom_animate"></div> </div>
<div id="tab-4" class="tab-content"><div class="bordertop_animate"></div> tab 4 content<div class="borderbottom_animate"></div>
</div>
</div>
</div>
CSS
.container {
width: 1000px;
min-height: 400px;
margin: 0 auto;
}
ul.tabs {
margin: 0px;
padding: 0px;
list-style: none;
background: #000;
vertical-align: middle;
font-weight: 400;
color:#FFF;
text-align: right;
text-transform: uppercase;
font-size: 8px;
letter-spacing: 0.6px;
}
ul.tabs li {
background: #000;
vertical-align: middle;
font-weight: 400;
color:#FFF;
text-align: right;
text-transform: uppercase;
font-size: 8px;
letter-spacing: 0.6px;
display: inline-block;
padding: 55px 15px 55px 15px;
cursor: pointer;
}
ul.tabs li.current {
background: #000;
color: #FFF;
}
#welcome_selector {
float: left;
padding-left: 128px;
}
.tabcontentcontainer {
height: 400px;
width: 1000px;
background: url(http://placehold.it/1000x400) #000;
position: relative;
}
.tab-content {
display: none;
background: rgba(0, 0, 0, 0.0);
padding: 15px;
}
.tab-content.current {
display: inherit;
}
.bordertop_animate {
position: absolute;
height: 38px;
width: 966px;
border-top: 2px solid #FFF;
border-right: 2px solid #FFF;
border-bottom: 0px solid #FFF;
border-left: 2px solid #FFF;
}
.borderbottom_animate {
position: absolute;
bottom: 15px;
height: 38px;
width: 966px;
border-top: 0px solid #FFF;
border-right: 2px solid #FFF;
border-bottom: 2px solid #FFF;
border-left: 2px solid #FFF;
}
JS
$(document).ready(function(){
$('ul.tabs li').click(function(){
var tab_id = $(this).attr('data-tab');
$('ul.tabs li').removeClass('current');
$('.tab-content').removeClass('current');
$(this).addClass('current');
$("#"+tab_id).addClass('current');
})
})
I'd like for the first tab to keep current divs height which is 38px, however I'd like the other 3 tabs to have theirs at a height of 185px- but for the height to grow from 38px to 185px when the tab is selected. The animation would be similar to if the divs had a :hover css selector applied with a 0.5s transition, except it would happen when the tab is selected, not on mouseover.
Sorry if this isn't detailed or specific enough, this is my first time posting a question/and dealing with jquery.
Here is a jquery solution to your problem, just in case you need it.
JS fiddle: http://jsfiddle.net/nPAhw/
html
<ul>
<li id="tab1">Tab One</li>
<li id="tab2">Tab Two</li>
</ul>
<div id="tabone">Tab one</div>
<div id="tabtwo">Tab Two</div>
css
#tabone{
width:200px;
height:38px;
border:solid blue;
margin:10px;
}
#tabtwo{
width:200px;
height:38px;
border:solid black;
margin:10px;
}
#tab1:hover{
cursor:pointer;
}
#tab2:hover{
cursor:pointer;
}
jquery / javascript
$('#tab1').click(function(){
var h = $('#tabone').height();
if(h < 185){
$('#tabone').animate({height:'185px'});
$('#tabtwo').animate({height:'38px'});
}
else $('#tabone').animate({height:'38px'});
});
$('#tab2').click(function(){
var h = $('#tabtwo').height();
if(h < 185){
$('#tabtwo').animate({height:'185px'});
$('#tabone').animate({height:'38px'});
}
else $('#tabtwo').animate({height:'38px'});
});
You would want to use the Jquery Animate method.
This method can perform animation effects on any numeric CSS property, like for example, height, which is what you want to achieve.
$( ".element-class" ).animate({
height: "185px"
}, 500);

When setting padding for a div with display:table-cell, it changes padding of a neighbour div with the same display

I've created a container <div id="container"> for my content, which in return has a simple <div id="leftbar"> and <div id="content"> for the main text of the page.
I've made the <div id="container"> as a display:table in styles, and both <div id="leftbar"> and <div id="content"> as display:table-cell.
The problem I'm having now is, whenever I try to change padding on the <div id="content">, it affects padding in <div id="leftbar"> for some reason. And it applies only for the top padding.
How can I resolve this, and better yet, why is this happening? Is it because of the table structure?
Providing with code, and jsfiddle. In jsfiddle change the last padding line in CSS to see how it shifts everything in the left bar.
HTML:
<body>
<div id="wrapper">
<div id="header"><img src="http://i.imgur.com/krQBHIx.jpg" width="690" height="100"/></div>
<div id="container">
<div id="leftbar">
<ul>
<p class="heading">Navigation</p>
<li>Main</li>
<li>Articles</li>
<li>Lessons</li>
<li>About</li>
</ul>
<p class="heading" style="background: #bb0;">Subscribe</p>
<form action="subscribe.php" method="POST" name="form1">
Subscribe to our RSS feed and get all the fresh news and articles directly in your mail box!<br /><br />
<label><p>Enter your name:</p><input type="text"/></label>
<label><p>Enter your e-mail:</p><input type="text"/></label>
<input type="submit" name="submit" value="Send!"/>
</form>
</div>
<div id="content">
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
</div>
</div>
<div id="footer"><img src="http://i.imgur.com/2GzQuoo.jpg" width="690" height="18"/></div>
</div>
</body>
CSS:
/* Styles */
*
{
padding: 0;
margin: 0;
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
font: 14px Verdana, Tahoma, sans-serif;
}
*:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
a
{
color: #000;
text-decoration: none;
}
body
{
background: #606B79;
}
p
{
font: 14px Tahoma, Verdana, sans-serif;
}
#wrapper
{
width: 690px;
margin: 10px auto;
}
#header img
{
display: block;
height: 100%;
}
#footer img
{
border: 1px solid black;
border-top: none;
display: block;
}
#container
{
display: table;
width: 100%;
border-left: 1px solid black;
border-right: 1px solid black;
background: #fff;
}
#leftbar
{
display: table-cell;
width: 184px;
border-right: 2px solid black;
height: 100px;
padding: 5px;
}
#leftbar ul
{
list-style: none;
margin-bottom: 15px;
}
.heading
{
text-align: center;
background-color: #a22;
color: #fff;
padding: 3px;
margin-bottom: 7px;
}
#leftbar ul li
{
border: 1px solid gray;
border-bottom: none;
}
#leftbar ul li:last-child
{
border: 1px solid gray;
}
#leftbar a
{
display: block;
padding: 2px 4px;
}
#leftbar a:hover
{
background: #ccc;
}
#leftbar form
{
border: 1px solid gray;
padding: 10px;
text-align: justify;
}
#leftbar form input
{
width: 149px;
margin: 3px 0;
}
#leftbar form input[type="submit"]
{
height: 25px;
background: #ccc;
margin-top: 20px;
}
#content
{
display: table-cell;
width: 506px;
text-align: justify;
padding: 25px;
}
jsfiddle: http://jsfiddle.net/9Qtpj/
Help me, please?
The content in your #leftbar div is aligned to the baseline. To fix your current html/css change the following:
#leftbar
{
vertical-align: top;
display: table-cell;
width: 184px;
border-right: 2px solid black;
height: 100px;
padding: 5px;
}
BUT! You really should be using another method for this. Displaying non-table elements as tables can have its issues, and isn't needed anymore.
Start learning about flexbox [the latest and greatest in web layout] - http://css-tricks.com/snippets/css/a-guide-to-flexbox/ and use floats as a fallback [see #AlexPrinceton's answer].
Try to change your CSS styles. Don use display:table for aligning elements if you can use "float"
Here is your code
CSS
#container {
width:100%;
overflow:hidden
}
#content {
float:right;
width:506px;
padding:25px;
}
#leftbar {
width:184px;
float:left;
padding:5px;
}

Why won't my elements display horizontally?

I have two sections of my website that should be displaying in a similar manor. One displays correctly, while the other does not. The top one puts each element on its own line, while the bottom puts the above and the two images side by side how I want them.
My two questions are:
1: Why is the broken version broken?
2: What part of the working version is enabling it to display properly (or a better follow up question, what parts of the css are not aiding in it displaying properly and can be deleted?
Broken:
html:
<div id="maintitle">
<span id="chara1"><img src= "<?= $charused ?>" width="150" alt="char2"/></span>
<span id="maintitletext"><h1> Welcome to Born4battle's Wolfenstein 3D page</h1></span>
<span id="chara2"><img src= "<?= $charused ?>" width="150" alt="char2"/></span>
</div>
css:
#maintitle{
color: #ffff00;
text-align: center;
}
#maintitle ul{
margin:0;
padding: 0;
list-style-type: none;
}
#maintitle li{
display: inline;
}
#chara1, #chara2, #maintitletext{
margin-top: 0px;
margin-right: auto;
margin-left: auto;
display: inline;
padding: .5em;
width: 110px;
}
Working:
html:
<div id="share">
<p> Get the official shareware for Wolfenstein 3D and Spear of Destiny below </p>
<span id="getwolf"><img src="http://www.timsooley.com/wolfnow.gif" alt="getwolf"></span>
<span id="getspear"><img src="http://www.timsooley.com/getspear.gif" alt="getspear"></span>
</div>
css:
#share ul{
margin: 0;
padding: 0;
list-style-type: none;
}
#share li{
display:inline;
}
#getspear, #getwolf{
margin-top: 0px;
margin-right: auto;
margin-left: auto;
display: inline;
/*background: #bbbbbb;
border-top: solid 2px #333333;
border-left: solid 2px #333333;
border-right: solid 3px #999999;
border-bottom: solid 3px #999999;*/
padding: .5em;
width: 110px;
}
Please see the Fiddle .
After reading your question what i have understood is that you want your images should be side by side and text should be in middle. in you broken code.
please let me know if i am lagging some where. So i can make changes as per your needs.
see the css rules what i added:
#maintitle{ color: #ffff00; text-align: center; overflow:hidden; width:480px; border:1px solid red; }
#maintitle span { width:148px; display:block; font-size:12px; }
#chara1, #chara2, #maintitletext{ margin-top: 0px; margin-right: auto; margin-left: auto; display: inline; padding: .5em; width: 110px; float:left; // added to make all elements in horizontal manner }
To show the text and images in same line, make these changes in your code:
http://jsfiddle.net/S3CBj/2/
#maintitle{
color: #ffff00;
text-align: center;
}
#maintitle ul{
margin:0;
padding: 0;
}
#chara1, #chara2, #maintitletext{
margin-top: 0px;
margin-right: auto;
margin-left: auto;
display: inline;
float: left;
padding: .5em;
width: 150px;
}​