Is there a way, using CSS, to make it so that when clicking a tab (as shown in the diagram below), the tab "points" to an inactive tab?
I'm trying to make it so that the green Tab 1 (in the diagram below) points to Tabs 2 and 3, and then if you click Tab 2, it points to Tab 3. However, when you click Tab 3, it would remain rectangular (with no arrow).
I have been trying various Stack Overflow snippets which successfully place the arrow above or below the tab, but none seem to work in overlapping the inactive tab next to the active tab.
This is the basic structure of my HTML:
<ul>
<li class="active">
Tab 1
</li>
<li>
Tab 2
</li>
<li>
Tab 3
</li>
</ul>
As for the CSS, I've been using snippets like this one: https://codepen.io/mimoYmima/pen/MwzQym
The issue I've been running into seems to be that, because the tabs are floated left, I can't make the active tab's arrow overlap the other tabs.
Just add triangle using pseudoelement to active tab and other to simulate triangle border. Demo:
ul {
list-style-type: none;
display: flex;
margin: 0;
padding: 0;
}
ul > li {
padding: 10px 40px;
font-weight: bold;
font-size: 24px;
height: 40px;
border: 1px solid #000;
border-right: none;
background: linear-gradient(to bottom, #fdfdfd, #828282);
}
ul > li.active {
background: #66d835;
position: relative;
}
ul > li.active:before,
ul > li.active:after {
content: "";
position: absolute;
left: 100%;
top: 0;
}
/* triangle border for active tab */
ul > li.active:before {
transform: translateX(1px);
border: 30px solid transparent;
border-left-color: #000;
z-index: 1;
}
/* triangle for active tab */
ul > li.active:after {
/* border-width equal half of the height */
border: 30px solid transparent;
border-left-color: #66d835;
z-index: 2;
}
/* border-radius for first tab */
ul > li:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
/* border-radius for last tab but not active */
/* and right border */
ul > li:not(.active):last-child {
border-right: 1px solid #000;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
ul > li > a {
height: 100%;
/* styles for text centering */
display: flex;
align-items: center;
justify-content: center;
}
ul > li > a,
ul > li > a:hover,
ul > li > a:active,
ul > li > a:visited {
color: inherit;
text-decoration: none;
}
<ul>
<li class="active">
Tab 1
</li>
<li>
Tab 2
</li>
<li>
Tab 3
</li>
</ul>
You can leverage a pseudo element with absolute positioning as the arrow for the active tab. It will be hidden unless the list item is given the 'active' tab. Original HTML markup remains untouched.
html,
body {
height: 100%;
margin: 0;
}
html {
font-family: sans-serif;
}
body {
display: flex;
}
ul {
margin: auto;
padding: 0;
display: inline-block;
list-style-type: none;
overflow: hidden;
background-color: #eee;
background-image: linear-gradient( #fff, #ddd);
border-radius: 1rem;
border: 1px #888 solid;
font-weight: bold;
}
li {
float: left;
padding: 1.5rem 4rem;
border-right: 1px #aaa solid;
position: relative;
}
li:last-child {
border: none;
}
a {
text-decoration: none;
color: #000;
}
.active {
background-color: #0b0;
background-image: linear-gradient( #0b0, #090 );
}
li.active::after {
content:'';
width: 3rem;
height: 3rem;
background-color: #eee;
position: absolute;
border: none;
transform: scaleX( 0.75 ) rotate( 45deg ) translate( -50% );
top: 50%;
right: -2.45rem;
margin-top: -0.45rem;
border-top: 1px #888 solid;
border-right: 1px #888 solid;
background-color: #0b0;
background-image: linear-gradient( 130deg, #0b0, #090 );
border-top-right-radius: 0.5rem;
}
<ul>
<li class="active">
Tab 1
</li>
<li>
Tab 2
</li>
<li>
Tab 3
</li>
</ul>
You don't need to float the arrow divs.
I have forked the codepen you linked to and edited the CSS to create the effect in the graphic you've shared. Here's my edited version:
https://codepen.io/sigil/pen/YxWZGa
<!-- language: lang-css -->
/* Button-arrow CSS: */
.arrow {
cursor: pointer;
display: inline-block;
height: 40px;
position: relative;
line-height: 2.5em;
padding-left: 2em;
padding-right: 2em;
background: white;
color: black;
border: 1px solid #eee;
}
.arrow:after {
border-left: 20px solid white;
}
.arrow.active {
background-color: yellow;
}
.arrow.active,
.arrow.active:after {
z-index: 50;
border-left: 20px solid yellow;
}
.arrow.active:after {
content: "";
position: absolute;
border-bottom: 20px solid transparent;
border-top: 20px solid transparent;
height: 0px;
width: 0px;
margin-right: -20px;
right: 0;
}
.arrow:hover,
.arrow:active {
background: yellow;
color: black;
}
.arrow:hover:after,
.arrow:active:after {
border-left: 20px solid yellow;
}
/* General styles to set a baseline 'look' - not related to the button-arrow CSS above */
body, html {
font-family: helvetica;
background: #333;
color: #CCC;
}
.content {
text-align: center;
margin: 0 auto;
}
a:visited, a:link {
color: #F93;
}
<!-- language: lang-html -->
<html>
<body>
<div class="content">
<p>Button with an arrow on the right. Just uses an anchor tag and css, so you can use it with your existing buttons easily by just adding the class of "arrow"! Also includes a hover state.</p>
<a class="arrow active">Arrow</a><a class="arrow">Arrow</a><a class="arrow">Arrow</a>
</div>
</body>
</html>
<!-- end snippet -->
Related
I have created horizontal menu bar but on mouse hover it's not showing the submenu, it's working perfectly in Google Chrome but on Internet Explorer 11 it's not working.
Note
I am using Struts2 text property.
The Code:
#example {
width: 100%; /* Spans the width of the page */
height: 50px;
margin: 0; /* Ensures there is no space between sides of the screen and the menu */
z-index: 99; /* Makes sure that your menu remains on top of other page elements */
position: relative;
background-color: #366b82;
}
.navbar {
height: 50px;
padding: 0;
margin: 0;
position: absolute;
border-right: 1px solid #54879d;
}
.navbar li {
height: auto;
width: 150px;
float: left;
text-align: center;
list-style: none;
font: normal bold 12px/1.2em Arial, Verdana, Helvetica;
padding: 0;
margin: 0;
background-color: #366b82;
}
.navbar a {
padding: 18px 0;
border-left: 1px solid #54879d;
border-right: 1px solid #1f5065;
text-decoration: none;
color: white;
display: block;
}
.navbar li:hover, a:hover {
background-color: #54879d;
}
.navbar li ul {
display: none;
height: auto;
margin: 0;
padding: 0;
}
.navbar li:hover ul {
visibility: visible;
display: block;
}
.navbar li ul li {
background-color: #54879d;
}
.navbar li ul li a {
border-left: 1px solid #1f5065;
border-right: 1px solid #1f5065;
border-top: 1px solid #74a3b7;
border-bottom: 1px solid #1f5065;
}
.navbar li ul li a:hover {
background-color: red;
}
JSP Page
<div id="example">
<ul class="navbar">
<li><s:text name="Menu1"></s:text></li>
<li><s:text name="Menu2"></s:text>
<ul>
<li><s:text name="SubMenu1"></s:text></li>
<li><s:text name="SubMenu2"></s:text></li>
<li><s:text name="SubMenu3"></s:text></li>
</ul>
</li>
<li><s:text name="Menu3"></s:text></li>
</ul>
</div>
Is anything I left or I missed which is applicable on Internet Explorer 11?
I got the solution,issue is with IE compatability
I Have added
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
in HTML page and its start working!!
I'm trying to create menus for a webpage using HTML and CSS. When the menus are displayed those nasty bullets appear. I don't want them. How do I get rid of them?
Also, the submenus need to allow for variable length strings. I had to specify a width: 80px; property for the .dropdown li element. If I didn't, all the menus got squished together.
For the submenus, if I have a lengthy li like this:
<li>Most Popular Artists</li>
All that gets displayed is the word "Most".
So I need two things solved: Get rid of the bullets, and make the submenus handle variable length strings.
HTML:
<nav id="top_menu">
<img src="media/images/logo_large.jpg">
<ul class="dropdown">
<li class="dropdown_trigger">
NEWS
<ul>
<li>Subitem1</li>
<li>Subitem2</li>
<li>Subitem3</li>
<li>Subitem4</li>
</ul>
<li>
<li class="dropdown_trigger">
SOCIAL
<ul>
<li>Subitem1</li>
<li>Subitem2</li>
<li>Subitem3</li>
<li>Subitem4</li>
</ul>
</li>
</ul>
</nav>
CSS:
#top_menu{
position: relative;
top:35px;
left: 90px;
width:660px;
height:55px;
background-color: black;
border:1px solid black;
opacity:0.6;
filter:alpha(opacity=60); /* For IE8 and earlier */
}
.dropdown {
background: black;
border: 1px solid black;
float: right;
padding: 1px 0 0 1px;
margin: 0 0 20px;
line-height: 55px;
}
.dropdown a {
background: black repeat-x;
border: 1px solid black;
border-top-width: 0;
color: white;
display: block;
line-height: 25px;
overflow: hidden;
text-decoration: none;
height: 25px;
}
.dropdown a:hover {
color: #30B3FF;
background: #666;
}
.dropdown ul a {
background: black;
}
.dropdown > li {
list-style: none;
position: relative;
text-align: left;
font: bold 12px Tahoma;
*display: inline-block;
width: 80px;
/* IE7 hack to make inline-block work right */
*zoom: 1;
display: inline;
}
.dropdown li.dropdown_trigger {
display: inline;
float: left;
margin: 0 0 0 -1px;
}
.dropdown ul {
background: black;
border: 1px solid black;
border-top-width: 0;
position: absolute;
top: 26px;
left: -1px;
z-index: 9999;
}
.dropdown ul {
display: none;
}
.dropdown li.dropdown_trigger:hover ul {
display: block;
}
You should add list-style-type: none; to your main ul CSS like so:
.dropdown ul {
list-style-type: none;
background: black;
border: 1px solid black;
border-top-width: 0;
position: absolute;
top: 26px;
left: -1px;
z-index: 9999;
}
.dropdown ul {
display: none;
}
And looking at that you can consolidate those two items & format them for readability as well:
.dropdown ul {
display: none;
list-style-type: none;
background: black;
border: 1px solid black;
border-top-width: 0;
position: absolute;
top: 26px;
left: -1px;
z-index: 9999;
}
And past that you can even add the !important to force an override:
.dropdown ul {
display: none;
list-style-type: none !important;
background: black;
border: 1px solid black;
border-top-width: 0;
position: absolute;
top: 26px;
left: -1px;
z-index: 9999;
}
Add list-style:none; to your unordered (bulleted) list to hide the default bullets. Apply this role to ul in this way you will not have to apply it to each ul.class every time.
ul {
list-style:none;
padding:0;
margin:0;
}
Check out the JSfiddle showing what I am up to: http://jsfiddle.net/Amp3rsand/FPj3s/1/
HTML:
<ul id="navigation">
<li>BLAH</li>
<li>MORE <br /> BLAH</li>
<li>STILL <br /> MORE</li>
<li>YADDA <br /> YADDA</li>
<li>ETC ETC <br /> ETC ETC</li>
<li>FINISH</li>
</ul>
CSS:
body {
font-size: 12px;}
}
#navigation {
width: 600px;
height: 50px;
position: absolute;
left: 20px;
top: 25px;
}
#navigation li {
list-style-type:none;
width: 94px;
height: 40px;
display: block;
float: left;
margin: 0 5px 0 0;
text-align: center;
font-weight: bold;
background: lightgrey;
}
#navigation li:first-child {
border-top: 40px solid lightgrey;
border-left: 25px solid transparent;
height: 0;
width: 70px;
background: none;
}
#navigation li:first-child a {
position: relative;
top: -35px;
right: 0px
}
#navigation li:last-child {
border-top: 40px solid lightgrey;
border-right: 25px solid transparent;
height: 0;
width: 70px;
background: none;
}
#navigation li:last-child a {
position: relative;
top: -35px;
left: 5px;
}
#navigation li:last-child a:hover {
top: -35px;
left: 5px;
}
#navigation li a {
display: block;
height: 40px;
text-decoration: none;
color:#000;
}
#navigation li a:hover {
background: grey;
}
The lightgrey shapes are what I would like the hover to look like. Only the first and last children need to look different but I am unsure of how to go about messing with the borders on hover without ruining the layout. I have had to move the first and last 'a' elements because of the border shenanigans and now I'm stuck.
What would you suggest?
EDIT:
I just realised I could do this to change the shape of the hover bit but the link position is still causing trouble
#navigation li:last-child a:hover {
border-top: 40px solid grey;
border-right: 25px solid transparent;
height: 0;
width: 70px;
background: none;
}
See it live here on JS Fiddle
The properties you want to change are of the <li> elements so target the list items hover state and change the background and border color
#navigation li:hover {
background: grey;
}
#navigation li:first-child:hover,
#navigation li:last-child:hover{
background: none;
border-top-color: grey;
}
Updated fiddle
Essentially, you want to set the 'border-top' to grey for the first/ last child.
You could use in CSS:
#navigation li:first-child:hover {
border-top: 40px solid lightgrey;
}
But this didn't work in Google Chrome, for me, so perhaps just apply that as a hover effect using jQuery?
I need some advice and some help. I am not so much of a css guy, but I want to learn.
I am trying adjust some css for my drop down menu.
I have the following issues:
The dropdown button should be as big as the image, leaving only the area of the dropdown triangle.
The dropdown triangle should be aligned vertically in the middle and centered horizontally.
The dropdown options should be aligned with the right border and open inwards towards the left, instead of the opposite.
Can someone help me with adjusting this?
I want to learn the techniques, but trial on error is such a long way.
My code is as folowing:
<html>
<head>
<head>
<body>
<style>
body {
background-color: white;
font: normal 11px Tahoma,Verdana,Arial,Sans-Serif;
color: #222;
height: 380px;
}
.dropdown {
display: block;
display: inline-block;
margin: 0px 3px;
position: relative;
}
/* ===[ For demonstration ]=== */
.dropdown { margin-top: 25px }
/* ===[ End demonstration ]=== */
.dropdown .dropdown_button {
cursor: pointer;
width: auto;
display: inline-block;
padding: 0px 0px;
border: 1px solid silver;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 2px;
font-weight: bold;
color: #717780;
line-height: 16px;
text-decoration: none !important;
background: white;
}
.dropdown input[type="checkbox"]:checked + .dropdown_button {
border: 1px solid #3B5998;
color: white;
background: silver;
-moz-border-radius-topleft: 2px;
-moz-border-radius-topright: 2px;
-moz-border-radius-bottomright: 0px;
-moz-border-radius-bottomleft: 0px;
-webkit-border-radius: 2px 2px 0px 0px;
border-radius: 2px 2px 0px 0px;
border-bottom-color: silver;
}
.dropdown input[type="checkbox"] + .dropdown_button .arrow {
display: inline-block;
width: 1px;
height: 1px;
border-top: 5px solid silver;
border-right: 5px solid transparent;
border-left: 5px solid transparent;
}
.dropdown input[type="checkbox"]:checked + .dropdown_button .arrow { border-color: white transparent transparent transparent }
.dropdown .dropdown_content {
position: absolute;
border: 1px solid #777;
padding: 0px;
background: white;
margin: 0;
display: none;
}
.dropdown .dropdown_content li {
list-style: none;
margin-left: 0px;
line-height: 16px;
border-top: 1px solid #FFF;
border-bottom: 1px solid #FFF;
margin-top: 2px;
margin-bottom: 2px;
}
.dropdown .dropdown_content li:hover {
background: silver;
}
.dropdown .dropdown_content li a {
display: block;
padding: 2px 7px;
padding-right: 15px;
color: black;
text-decoration: none !important;
white-space: nowrap;
}
.dropdown .dropdown_content li:hover a {
color: white;
text-decoration: none !important;
}
.dropdown input[type="checkbox"]:checked ~ .dropdown_content { display: block }
.dropdown input[type="checkbox"] { display: none }
</style>
Here there will be a lot of text and a lot of other menu buttons. So hope the angle of the dropdown will open to the left instead of the right.
<div class="dropdown" id="dropdown">
<input type="checkbox" id="drop1" />
<label for="drop1" class="dropdown_button"><img src="http://ichef.bbci.co.uk/wwfeatures/43_43/images/live/p0/17/tx/p017txf6.jpg" height="43" width="43" /><span class="arrow"></span></label>
<ul class="dropdown_content">
<li>Privacy settings</li>
<li>Account settings</li>
<li>Logout</li>
</ul>
</div>
</body>
</html>
Now I managed to fix the border around the image by correcting the padding padding: 0px 0px; but then I feel like working in blind...can someone help pointing me where to fix my adjustments?
Give your span an id of 'arrowSpan' and apply this style in your css:
#arrowSpan{
display:block;
margin-left:17px;
margin-top:2px;
margin-bottom:5px;
}
Also add position:absolute; and right:0 to your .dropdown .dropdown_content styles.
Here's a fiddle: http://jsfiddle.net/zsp7t/1/
As for collapsing the dropdown when clicking outside, it is possible. There's a bunch of examples online using jQuery, here's a couple that can help you get started:
Use jQuery to hide a DIV when the user clicks outside of it
Hiding a div by selecting anywhere outside of it
You also mentioned that you wanted to learn more, so check these sites out to help you increase your skills:
http://www.codecademy.com/
http://www.codeschool.com/courses
Small question on how to achieve some styling on a HTML / CSS UL menu.
I have a standard UL menu, but having some issues getting my head around how to achieve a certain look to the styling. The UL menu as it currently stands is shown here:
http://jsfiddle.net/WMQqt/
(HTML)
<ul id="nav">
<li>CONTACT US
</li>
<li>HOME
</li>
</ul>
(CSS)
#nav {
list-style: none;
margin-bottom: 10px;
*/ margin-top: -6px;
position: relative;
right: 286px;
z-index: 9;
height: 26px;
padding: 4px 4px 4px 4px;
font-weight: bold;
}
#nav li {
float: right;
margin-right: 10px;
}
#nav a {
display: block;
padding: 5px;
color: #444444;
background: #fff;
text-decoration: none;
border: 1px solid grey;
}
#nav a:hover {
color: #fff;
background: #04B431;
}
I'd like the menu buttons to have a small 1px border, but then some white space padding of around 3px before the background color starts.
Similar to how this looks:
http://jsfiddle.net/6PY7z/
Can this be done using the UL menu method?
Thanks for any advice, I'm no expert with HTML / CSS.
Add margin to a tag and move border to li
#nav li
{
float: right;
margin-right: 10px;
border: 1px solid grey;
}
#nav a
{
display: block;
padding: 5px;
color: #444444;
background: #ccc;
text-decoration: none;
margin:3px;
}
DEMO
you can use the following styles to achieve what you want:
#nav li
{
float: right;
margin-right: 10px;
border: 1px solid grey; /*put original border here*/
}
#nav a
{
display: block;
padding: 5px;
color: #444444;
background: #d8d8d8; /*new background-color*/
text-decoration: none;
border: 3px solid white; /*add white padding here*/
}
http://jsfiddle.net/WMQqt/4/
ok
in html go
<dl><div><dt>F</dt><dd>T</dd></div>
<div><dt>F</dt><dd>T</dd></div>
<div><dt>F</dt><dd>T</dd></div>
<div><dt>F</dt><dd>T</dd></div>
</dl>
in css
dl { display: flex;
flex-direction: column;}
some hints...
dt float left AND
dd float right