tab menu that drops/toggles (pure css/html) - css

I have a tab that sits at the bottom of a global nav.
I want that tab to expand and contract on click preferably not using jquery.
When the tab expands it will contain a list with links vertically and the tab should stick to the bottom of the expanded list.
I've looked many places online to find something similar but have not been able to locate what I'm looking to achieve.
Mobile friendly would be nice and needs to toggle when clicked outside the region.
Here is the css for the tab.
.findprod {
position: absolute;
top: 11.5vw;
background-color:rgba(0, 0, 0, 0.5);
text-decoration: none;
text-align:center;
right:7vw;
top-padding:-.7vw;
margin:-.7vw;
width:10.75vw;
font-family: Lato;
color: white;
font-size: .88vw;
font-weight: 400;
line-height: 3.1vw;
border: none;
-webkit-border-radius: 0 1px 22px 22px;
border-radius: 0 1px 22px 22px;
white-space: nowrap;
overflow: hidden;
z-index:1;
}
html: <div class="findprod"> Find a Product </div>

Here is a simple example of how to do this with jQuery.
See: https://jsfiddle.net/552xrcf3/
$('.findprod').click(showHide);
function showHide(){
$('#list').slideToggle();
}
.findprod {
background-color:rgba(0, 0, 0, 0.5);
text-align:center;
color: white;
font-family: sans-serif;
display: inline-block;
padding: 20px 30px;
border-radius: 0 0 40px 40px;
cursor: pointer;
}
#list{
display: none;
list-style-type: none;
font-family: sans-serif;
margin: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="list">
<li>Rocks</li>
<li>Pipes</li>
<li>Cookies</li>
<li>Office Supplies</li>
<li>Fireworks</li>
</ul>
<div class="findprod"> Find a Product</div>

Related

Remove padding/margin between elements in shrink-to-fit container

I want the yellow div to just be tall enough and only reach the very bottom part of the letter g.
After adding a list it seems to not work despite having 0 padding or margin and displaying as an inline-block.
Also there shouldn’t be a gap between the green list and ‘get a quote’ orange section.
To summarise, I want to get rid of the yellow (well still be there but behind the other colours), and shift the green up to be just under the orange.
#footer-right {
float: left;
width: 360px;
height: 200px;
background: #96F;
}
.footer-text-section-wrap {
background: #ff0;
width: auto;
height: auto;
display: inline-block;
}
f1 {
color: #333;
font-weight: 100;
font-family: verdana, arial, "Times New Roman", Times, serif, georgia, serif, helvetica;
font-size: 20px;
border-bottom: 1px solid #ccc;
padding: 0 0 10px 0px;
background: #FCC;
}
ul.footer {
list-style-type: none;
padding: 0px;
color: #666;
font-weight: 100;
font-family: verdana, arial, "Times New Roman", Times, serif, georgia, serif, helvetica;
font-size: 20px;
background: #0CC;
}
<div id="footer-right">
<div class="footer-text-section-wrap">
<f1>Get a Quote</f1>
<ul class="footer">
<li>About</li>
<li>Contact</li>
<li>Outsourcing</li>
</ul>
</div>
</div>
Add a margin reset to remove unwanted gaps between elements. Something like this: * {margin:0}. This rule resets the margins applied by the browser to all properties. Or you could simply target the ul with ul.footer {margin:0}.
Then add padding-top: 10px to the ul to compensate for the padding-bottom: 10px on the f1 above. OR, add display: block to the f1.
The reason the padding-bottom on the f1 doesn't simply push down the ul is because the f1 is a custom element. As such, it has no basic styles applied by the browser and CSS properties fallback to initial values. The initial value of the display property is inline.
An inline box cannot grow in height. Hence, the padding-bottom:10px simply overlaps the line box, intruding into the element below. By changing the display to block, the f1 will act like a normal block element and push away the ul.
* { margin: 0; }
f1 { display: block; }
#footer-right {
float: left;
width: 360px;
height: 200px;
background: #96F;
}
.footer-text-section-wrap {
background: #ff0;
width: auto;
height: auto;
display: inline-block;
}
f1 {
color: #333;
font-weight: 100;
font-family: verdana, arial, "Times New Roman", Times;
font-size: 20px;
border-bottom: 1px solid #ccc;
padding: 0 0 10px 0px;
background: #FCC;
}
ul.footer {
padding: 0;
list-style-type: none;
color: #666;
font-weight: 100;
font-family: verdana, arial, "Times New Roman", Times;
font-size: 20px;
background: #0CC;
}
<div id="footer-right">
<div class="footer-text-section-wrap">
<f1>Get a Quote</f1>
<ul class="footer">
<li>About</li>
<li>Contact</li>
<li>Outsourcing</li>
</ul>
</div>
</div>
More information: Proper way to apply CSS to HTML5 custom elements
This is a quick resolution using margin changes to remove the yellow space like you asked. Remember you can inspect elements and see where space is being created by highlighting the element's markup then viewing the diagram shown normally on the bottom left of the window.
#footer-right{
float:left;
width:360px;
height:200px;
background:#96F;
}
.footer-text-section-wrap{
background:#ff0;
width:auto;
height:auto;
display: inline-block;
}
f1{
color:#333;
font-weight:100;
font-family:verdana,arial,"Times New Roman", Times, serif,georgia,serif,helvetica;
font-size:20px;
border-bottom:1px solid #ccc;
padding:0 0 10px 0px;
margin: 0 0 10px 0px;
background:#FCC;
}
ul.footer {
list-style-type:none;
padding: 0px;
margin: 10px 0 0 0; /*This is all that I added or changed*/
color:#666;
font-weight:100;
font-family:verdana,arial,"Times New Roman", Times, serif,georgia,serif,helvetica;
font-size:20px;
background:#0CC;
}
<div id="footer-right">
<div class="footer-text-section-wrap">
<f1>Get a Quote</f1>
<ul class="footer">
<li>About</li>
<li>Contact</li>
<li>Outsourcing</li>
</ul>
</div>
</div>
<ul> have default margins (20px on top and bottom), you should add margin: 0; to your ul.footer styles to remove the extra yellow created by the margins.
You have no margin in your ul.footer..
First Option.. You can just do margin:0px; in your ul.footer.
Second Option.. You can take out the yellow background, and do margin-top:-10px; in your ul.footer.
(Not the actual negative number.. That is just guesstimating.)
Either one works, but the first option is easiest and less painful.

CSS button not clickable on left

I have been 75% successful by looking at this post: How Do I Make a CSS Button Clickable
But still if the cursor comes in on the left the button is not clickable.
HTML
<span class="buy">Buy Tickets Now</span>
CSS
.buy {
float: left;
position: relative;
display: block;
width: 200px;
height: 27px;
text-align: center;
margin-left: -70px;
margin-top: 30px;
font-family: Calibri,Helvetica, sans serif;
font-size: 22px;
font-weight: 700;
color: #ffffff;
background-color: #39b54a;
-moz-border-radius: 15px;
border-radius: 15px;
padding: 15px;
}
.buy:hover {
background-color: #8dc63f;
}
Could someone help with what I got wrong?
http://christianfordlive.com
The problem is generated by the div mainImage and the left margin. The div mainPage is in front of your button, that's why you can't click on it.
You have two easy options to fix the bug:
1 - Remove the margin-left of your button
margin-left: 0px;
If you do it, the div mainImage will stop overlapping your span.
You can also modify the z-index of your button to force it to go to the front of the mainImage div. For example, just add it to your .buy class:
z-index: 1000;
Both options should fix your problem
First of all, your code is kind of a mess, and you are overruling properties inside the same rule. All you need is:
html:
<a class="buy" href="http://www.christianfordlive.com/buy-tickets/">Buy Tickets Now</a>
css:
.buy {
float: left;
position: relative;
font-family: Calibri,Helvetica, sans serif;
font-size: 22px;
font-weight: 700;
color: #fff;
text-align: center;
text-decoration: none;
border-radius: 15px;
background-color: #39b54a;
padding: 15px 40px;
margin-top: 30px;
z-index: 100;
}

Hover effect is not applying to the border of my navigation buttons for text color

I have a navigation that I have styled as I like, but there is a small flash as you go over the border, where the background hover effect still applies but the text color change does not. I have tried various ways of resizing the "a" element (which triggers the text change), and it always stays within the border area no matter how I resize it. I have also tried adding the color change to the li:hover section with no effect.
Here is the nav bar:
<div id="leftmenu">
<ul id="sidenav">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</div>
And this is the CSS (probably overly complex - I have tried lots of different things that didn't seem to make a difference and didn't remove them all):
#leftmenu{
float: left;
width: 300px;
margin: 10px 0 0 10px;
}
ul#sidenav{
list-style-type: none;
padding: 0;
margin: 0;
}
ul#sidenav li{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border: solid medium #898E95;
border-radius: 5px;
text-align: center;
margin: 5px 0 5px 0;
background: #898E95;
font-size: 11pt;
}
ul#sidenav li a{
width: 295px;
text-align: center;
line-height: 25px;
text-shadow: 1px 1px 0px #283744;
text-decoration: none;
font-size: medium;
font-weight: bold;
color: #FFF;
display: block;
}
ul#sidenav li:hover{
background-color: #E5ECF9;
}
ul#sidenav li a:hover{
color: #5C5E64;
text-shadow: none;
}
#contentright{
margin-left: 320px;
padding: 0 20px 0 20px;
}
Thanks for any help you can provide - this is my first question, hopefully I asked it correctly!
http://jsfiddle.net/b8M6e/
The problem is created by this line
border: solid medium #898E95;
I just removed that line and it fixes the issue.
Also, by removing that line you'll notice it makes the menu items a little smaller than what you had. To fix that add the following line to the a- like so:
ul#sidenav li a {
padding: 4px;
}
updated fiddle http://jsfiddle.net/b8M6e/1/

Titles in css menu change width while hovering

I am implementing a very simple css menu. However, if I select a menu title in the menu bar (and thus open the menu associated with it) the width of the title extends to the width of the menu, which is not desired (i.e. the width of the title should not change). Check out the JSFiddle, or have a look at the markup:
<div id="menu">
<ul>
<li>you
<ul>
<li>register...</li>
<li>login...</li>
<li>forgot password...</li>
</ul>
</li>
<li>.</li>
<li>qan</li>
<li>.</li>
<li style="width: 20px"><a class="site">be</a>
<ul>
<li>be</li>
<li>do</li>
</ul>
</li>
</ul>
</div>
and the css definitions:
#menu {
font-family: Arial, Helvetica, sans-serif;
padding: 0px 5px;
font-size: 12px;
line-height: 18px;
color: darkgrey;
position: absolute;
top: 0px;
left: 0px;
height: 20px;
background-color: black;
z-index: 3;
/*opacity: 0;*/
white-space: nowrap;
}
#menu ul {
margin: 0px;
padding: 0px;
list-style-type: none;
list-style-image: none;
}
#menu>ul>li {
font-weight: bold;
display: inline-block;
float: left;
padding: 2px 1px 0px 1px;
width: auto;
/*width: 10px;*/
}
#menu a { color: inherit; text-decoration: none;}
#menu>ul>li>a:hover { background-color: grey;}
#menu>ul ul {
display: none;
background-color: lightgrey;
padding: 2px 5px;
line-height: 14px;
min-width: 100px;
}
#menu>ul ul>li {
color: black;
padding: 2px 8px 2px 5px;
margin: 0px -3px;
}
#menu>ul ul>li:hover { color: lightgrey; background-color: grey;}
#menu>ul>li:hover ul { display: block;}
Since the menus are generated dynamically and contents meant to change on the fly and the font used is proportional, I cannot just set the widths of a title to a constant value which suppresses the resize. The width of the title should be determinded solely by the width of the text.
It used to work when I had implemented yuimenus, but that did all kinds of stuff to my CSS, the ramifications of which I found hard to control, so now I cooked up the menu by myself and am quite happy with it, save for the width change, and I haven't figured out which part of yui suppressed that. Any suggestions?
I don't agree with max-width.. this will make the link's width content-independent
use position:absolute; for the submenu: jsFiddle
Set width in li
Your updated example :- http://jsfiddle.net/8U5An/8/
Css:-
#menu ul li {
width: 25px;
}
See some useful example as well , how they handle same case by using width only :-
http://www.diy.com/diy/jsp/index.jsp?noCookies=false
http://www.puregrips.com/

how do I float a div over a background image in a different div

In my CSS, I've created a menubar <div> and a header <div>. My intention is to have the menu line flush with the BOTTOM of the header's background image, so I've nested the menu inside the header. Alas, it's not working, and I can't figure out why.
I've created a fiddle, but I can't figure out how to upload the associated image file, so I've attached the header placeholder image. I've also uploaded a Wireframe demonstrating what I'm trying to make happen.
If you're not able to view the fiddle, here's my HTML and CSS:
HTML:
<!DOCTYPE html PUBLIC "-//W3c/DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- ------------------------------------------------------------------------>
<head>
<title>Test</title>
<LINK rel="stylesheet" href="t2.css" type="text/css">
</head>
<!-- ------------------------------------------------------------------------>
<body>
<div id="header" >
<div id="menubar">
home | about | contact
</div>
</div>
</body>
</html>
CSS:
body {
background-color: #FFFFFF;
color: #000064;
font-family: "Calibri", sans-serif;
font-size: 12px;
}
h1 {
background-color: #FFFFFF;
color: #000064;
font-family: "Calibri", sans-serif;
font-size: 2em;
}
h2 {
background-color: #FFFFFF;
color: #000064;
font-family: "Calibri", sans-serif;
font-size: 1.5em;
margin-left: 5%;
}
h3 {
background-color: #FFFFFF;
color: #000064;
font-family: "Calibri", sans-serif;
font-size: 1em;
margin-left: 20%;
}
p {
background-color: #FFFFFF;
color: #000064;
font-family: "Calibri", sans-serif
font-size: 12px;
padding: 0px 0px 0px 600px;
margin: 0px:
float: bottom;
}
a {
color: #000064;
text-decoration: none;
font-family: "Calibri", sans-serif;
font-size: 14px;
}
a.visited {
color: #640064;
weight: bold;
text-decoration: none;
}
#header {
height: 120px;
background-color: #ffffff;
background-image: url(headerblock.jpg);
background-repeat: no-repeat;
background-position: top left;
float: bottom;
}
#menubar {
border-width: 1px 0px 1px 0px;
border-color: #000064;
border-style: solid;
font-family: "Calibri", sans-serif;
font-size: 14px;
line-height: 16px;
float: bottom;
padding: 0px 0px 0px 600px;
margin: 0px 0px 0px 0px;
}
#menubar a {
text-decoration: none;
color: #000064;
float: bottom;
}
#menubar a.visited {
text-decoration: bold;
color: #000000;
float: bottom;
}
Anyone have any ideas?
Put the image in a separate div, all inside the header, like so:
<div id="header">
<div id="banner"></div><!--
--><div id="menubar"></div>
</div>
Then use display: inline-block; on #banner and #menubar.
Note the HTML comment after #banner and before #menubar. It's to remove the white space between those elements, you can remove it if you don't care about the blank space. Look at this for more info: Fighting the Space Between Inline Block Elements.
Check this fiddle.
By the way, you should use <ul> and <li> for your navigation.
And use borders on your separators, instead of |. That's for presentation, and presentation should be handled with css, not html.
Your #menubar has a padding 600px left that pushes the div out. Also Float can not be Bottom, It is either Left or Right.
To make it perfect place a position:relative to the header div and position:absolute; bottom:0px; left:0px; to the child div place it exactly
The float parameter accepts left or right. There is no such thing as float: bottom.
But if you add position: relative to the header div. You can position the menu with position: absolute; left: 0; bottom: 0;
Update
You might have to specify a width for the menu bar, te prevent the text from wrapping downwards.

Resources