Is this possible without introducing Javascript or adding to the HTML? - html

My client wants every link list, that is, every list of the form
<ul>
<li>
Here's a link
</li>
<li>
Here's a link
</li>
<li>
Here's a link
</li>
</ul>
to have the bullets of the list be the same color as the linked text, but every non-link list, that is, every list of the form
<ul>
<li>Here's a regular list item</li>
<li>Here's a regular list item</li>
<li>Here's a regular list item</li>
</ul>
should have its bullets and corresponding text inherit as usual.
Fiddle: http://jsfiddle.net/0kkc2rz4/
I am constrained by not being able to add classes into the HTML, so something like
<ul class='link-list'>
<li>
Here's a link
</li>
<li>
Here's a link
</li>
<li>
Here's a link
</li>
</ul>
ul.link-list li { color: #004E98; }
is out of the question, although I realize that's the obviously best way to do it if I was coding the site from scratch. I can add JS, but would prefer not to.

Here's a solution using a pseudo element and the unicode character for bullet points. The basic idea is to 'overlap' the a bullet over the li bullet, giving the effect that they are different.
ul{
margin:0em;
padding:0em;
list-style:none;
padding:20px 20px 0px 20px;
font-family:sans-serif;
}
li{
margin:0em;
padding:0em;
padding-bottom:10px;
}
a{
color:red;
text-decoration:none;
}
a:hover{
color:green;
}
a, li{
position:relative;
}
a:before, li:before{
content:'\2022';
position:absolute;
left:-0.5em;
color:inherit;
}
<ul>
<li>
Here's a link
</li>
<li>
Here's a link
</li>
<li>
Here's a regular list item
</li>
</ul>

Playing a bit with pseudolements: http://jsfiddle.net/2acw2hae/1/
ul { list-style: none; }
ul a { position: relative; }
ul a:before {
content : "\25CF"; /* unicode for black circle */
font-size: 0.75em;
margin-right: .5em;
}
/* this overlaps the text-decoration under the bullet */
ul a:after {
content : "";
position: absolute;
bottom: 0; left: 0;
height:4px;
width: .5em;
background: #fff;
}
Result

Related

Moving css only menu items 1 by 1 when resizing window

I have the below shown css only menu, but am wondering how I can, when the browser window gets smaller and the menu items doesnt fit, how I can move them one by one! onto the last, right most item "more..." so they create a sub menu there instead. Please see the following pictures of how first item "seventh" and "eighth" are moved onto "more..." and the second picture shows what should happen when you hover over "seventh", it should reveal its original sub menu items.
My current code: (pen with same for easier resizing: https://codepen.io/anon/pen/oZoMbK)
* {box-sizing:border-box;}
.nav{
background-color:#d6336c;
font-size:20px;
}
.nav ul{
list-style: none;
}
.nav ul li{
padding:2px 20px;
float: left;
position:relative;
background: #1bc2a2;
white-space: nowrap;
}
.nav ul li ul {
display:none;
position: absolute;
background-color:orange;
left: 0;
}
.nav ul li ul, .nav li li {
min-width: 100%;
}
.nav ul li:hover > ul{
display: block;
}
.nav ul ul ul{
left:100%;
top:0;
}
.nav a{
color:#ffffff;
}
ul,li{
margin:0;
padding:0;
}
<div class="nav">
<ul>
<li>first</li>
<li>second
<ul>
<li>sub1 first</li>
<li>sub1 second
<ul>
<li>sub2 first</li>
<li>sub2 second
<ul>
<li>sub3 first</li>
<li>sub3 second</li>
<li>sub3 third</li>
</ul>
</li>
</ul>
</li>
<li>sub2 third</li>
</ul>
</li>
<li>third
<ul>
<li>.
<li>.
<li>.
</ul>
</li>
<li>fourth</li>
<li>fifth</li>
<li>sixth</li>
<li>seventh
<ul>
<li>cats</li>
<li>dogs
<ul>
<li>beagle</li>
<li>boxer</li>
</ul>
</li>
<li>birds</li>
</ul>
</li>
<li>eighth</li>
<li>more...</li>
</ul>
</div>
First image when hovering "more...":
Second image, when hovering "seventh" under "more...":
I cant figure out how its done, only with media queries but I dont want set specific values as the menu items width might change/be dynamic. The following two pens somehow moves the items one by one as they dont fit when resizing the screen:
https://codepen.io/VPenkov/pen/wMZBOg & https://codepen.io/tejasukmana/pen/bZKNrJ
I really want to keep this css only, no javascript.
thanks in advance for any help!
Frank

Horizontal CSS dropdown menu

I am trying to make a horizontal drop down menu in CSS. However, it appears vertically:
I want the two topmost menu items to be horizontal. What can I do, besides making a table with one row?
ul ul {
display: none;
}
ul li:hover > ul {
display: block;
}
<ul>
<li>
abc
<ul>
<li>abc</li>
<li>abc</li>
</ul>
</li>
<li>
abc
<ul>
<li>abc</li>
<li>abc</li>
</ul>
</li>
</ul>
You can try floating the list items:
.root {
overflow: hidden; /* clear float */
}
.root > li {
float: left;
}
<ul class="root">
<li>
abc
<ul>
<li>abc</li>
<li>abc</li>
</ul>
</li>
<li>
abc
<ul>
<li>abc</li>
<li>abc</li>
</ul>
</li>
</ul>
You can add submenu a class/id with
.inline-menu{
display: inline;
}
http://jsfiddle.net/dyaskur/fby9fan6/
The gist of your question is actually this: what is the difference between inline and block elements? This is a fundamental question that is important to understanding the basics of layout in CSS/HTML. There is a good write-up on this topic and some of the trade-offs of the various approaches at:
http://designshack.net/articles/css/whats-the-deal-with-display-inline-block/
Basically, <li> is block-level tag, meaning that it displays as its own "block" element: receives a layout (settable dimensions), by default takes the entire width of the parent element, and has a forced break after the rendered element (is on a line to itself).
So, that leaves us with a number of approaches for having your menu items sit side-by-side:
Use inline-level elements for your menu items
Use block-level elements and float them
Use block-level elements and style them as inline-block
All of these approaches are detailed in the above link. Personally, I prefer to use floated block elements. I have a fiddle with some rough css to give you an idea. Note that there are some considerations in how to display your submenus as well. You'll note that I've implemented these as having display: block, with no float, because we want them to stack vertically.
HTML
<ul class="menu">
<li>
foo
<ul class="submenu">
<li>subfoo1</li>
<li>subfoo2</li>
</ul>
</li>
<li>
bar
<ul class="submenu">
<li>subbar1</li>
<li>subbar2</li>
</ul>
</li>
</ul>
CSS
ul.menu {
list-style: none;
}
ul.menu > li{
float: left;
position: relative;
}
ul.menu li {
background-color: #cccccc;
padding: 5px 20px;
}
ul.menu > li + li {
border-left: solid black 2px;
}
ul.menu li:hover > ul {
display: block;
}
ul.menu li a,ul.menu li a:link, ul.menu li a:hover, ul.menu li a:visited {
color: black;
text-decoration: none;
}
ul.submenu{
display: none;
list-style: none;
position:absolute;
left: 0;
padding: 0;
}
ul.submenu li {
float:none;
display: block;
}
ul.submenu > li + li {
border-top: solid black 1px;
}
You can just remove some <li> tags:
<ul>
<li>
abc
<ul>
abc
abc
</ul>
</li>
<li>
abc
<ul>
abc
abc
</ul>
</li>
</ul>

Is there an inline element that adds text, so there is not line break?

The reason i am asking this is because i have links on my site that are bolded when hovered over, they are "Our Work | Contact us", but the problem is that the "|" is a part of one of the links therefore it is also bolded, is there anyway around this?
You can do this with css and a border (which is the proper way, not a pipe-sign)
<a> text </a>
<a> text </a>
<a> text </a>
<a> text </a>
a{
margin: 0 5px;
padding: 0 5px;
line-height: 20px; /* this is to center it with the text */
}
a+a{
border-left: 1px solid #000;
padding-left: 10px;
}
jsFiddle demo
Use style="white-space:nowrap;" for the container having text to avoid line break.
I assume you are looking for this kind of structure
HTML
<ul>
<li> Our work </li>
<li> | </li>
<li> contact us </li>
</ul>
CSS
ul{
list-style:none;
}
ul > li{
float:left;
padding: 5px;
}
DEMO
EDIT
without hard coded pipe
<ul>
<li> Our work </li>
<li> Contact us </li>
<li> About us </li>
</ul>
ul{
list-style:none;
}
ul > li{
float:left;
}
ul > li a{
padding:5px;
}
li + li::before {
content: "|";
}
DEMO

HTML Submenu disappearing when trying to hover over it

i created an HTML menu that has a submenu, however when i hover over the main menu and it shows the submenu, i cant get access to it. It disappears before i can move my mouse down to navigate to it. I dont know what i am doing wrong, maybe with my code someone can help out. thanks
#header ul { position: absolute; top: 88px; left: 0; }
#header ul li { display: inline;}
#header ul li a { font-size: 11px; text-decoration: none; text-transform: uppercase; margin-right: 20px; color: #fff; line-height: 2em;}
#header ul li ul{ position: static;display: none; z-index: 999;top:150%;}
#header ul li:hover a { font-weight:bold; color: #000000}
#header ul li:hover ul { display: block; position:absolute;}
Edited to show HTML
<ul>
<li>Home
</li>
<li>
HRMS
<ul>
<li>
Position
</li>
<li>
COA
</li>
<li>
Employee
</li>
<li>
Estate
</li>
</ul>
</li>
<li>
Employee Maintenance
</li>
<li>
Payroll
</li>
<li>
Data Transfer
</li>
<li>
Reports
</li>
<li>
Administration
</li>
<li>
Help
</li>
</ul>
The problem is a disconnect between the main and the children <ul>.
In your style ul li ul { position: static;display: none; z-index: 999;top:150%;}
The top:150%; creates the disconnect (so you hover over nothing instead of hitting the submenu's :hover logic when you hover from ul li to ul li ul). You can try using padding-top instead:
ul li ul{ position: static;display: none; z-index: 999; padding-top:10px;}
Edit: Here is a working nav menu example you can look at.
Edit 2: Looks like it works in Firefox and Chrome, but not IE.
You will need a direct child selector, somewhere along the line of:
li:hover > ul { display: block; (...) }
This means that the child <ul> in the list will be displayed when it's direct parent <li> has been hovered upon.
I wrote one article about Dropdown menu in Portuguese, but I guess it will help you with google translate or something like that.
Check it out: http://www.linhadecodigo.com.br/artigo/3474/menu-em-css-menu-dropdown-horizontal-com-html5-e-css3.aspx

Vertical Menu with submenus flying out when mouse is hovered

I am trying to create a vertical menu with fly outs .That is a vertical menu with sub-menus.What is wrong with the following code?
<html>
<head>
<title>Untitled Document</title>
<style type="text/css">
#navmenu ul ul li a {
border:1px solid #888888; border-bottom: none; font-size:12pt; line-height: 1.6em; color:#303030; background-color:#a5a5a5; background-image:none;
}
#navmenu {
width: 150px; /* set width of menu */
}
#navmenu ul {
list-style-type:none; margin:0px; padding:0px;
}
#navmenu a {
text-decoration:none; border: 1px solid #303030; width:170px; display:block; text-align:center; font-size:14pt; line-height:2em; background:url(Button_top.gif) repeat-x left; font-family:Arial, Helvetica, sans-serif; color:white;
}
#navmenu a:hover {
color: #a00;
/* red text color on hover */
background: #fff;
/* white bgcolor on hover */
}
#navmenu li {
/* make the list elements a containing block for the nested lists */
position: relative;
}
#navmenu ul ul {
position: absolute; top: 0; left: 100%;
/* to position them to the right of their containing block */
width: 100%;
/* width is based on the containing block */
}
#navmenu li {
/* make the list elements a containing block for the nested lists */
position: relative;
}
#navmenu ul ul {
display: none;
}
#navmenu ul li:hover ul {
display:block;
}
</style>
</head>
<body>
<div id="navmenu">
<ul>
<li>
Home
</li>
<li>
Blog
</li>
<ul>
<li>
Blog 1
</li>
<li>
Blog 2
</li>
</ul>
<li>
Websites
</li>
<ul>
<li>
Websites 1
</li>
<li>
Websites 2
</li>
</ul>
<li>
Photos
</li>
</ul>
</div>
</body>
</html>
http://jsfiddle.net/9bHkj/1/
You might have to revisit how you are constructing the menu. For instance:
<li>
Blog
</li>
<ul>
<li>
Blog 1
</li>
<li>
Blog 2
</li>
</ul>
is supposed to be a Blog menu with two sub menus Blog 1 and Blog 2. But then <ul> for the sub menu is supposed to be within the <li> of the menu and not separately:
<li>
Blog
<!-- The <li> does not end here -->
<ul>
<li>
Blog 1
</li>
<li>
Blog 2
</li>
</ul>
</li> <!-- end tag for the blog <li>, now enclosing the submenu also -->
Once you do this, for the other submenus as well, you have the flying sub menus. You can now work out the location, colors etc.
you wrote this twice:
#navmenu li {
/* make the list elements a containing block for the nested lists */
position: relative;
}
Your nested lists ul are not contained by li elements. So this will not work either:
#navmenu ul li:hover ul {
display:block;
}
nesting your ul in li elements may solve your problem.