CSS responsive multiline list with dashed lines (name - - - price) - html

I'm trying to figure out how to make a multi-line dot leader when the background is textured or you don't know the background. The W3C site provides a good example when you know the background color, but that doesn't work for my needs. Here is a SO example of a textured background that works really well, but the leaders disappear when the line breaks to a 2nd line. Unfortunately the two use a different method to achieve this effect, so I'm not sure the best way to combine the best of both worlds here...
Here's sorta what I'm thinking. Is it possible?

Something from the top of my mind:
(Honestly I don't know for any other better and responsive solution):
jsBin demo (so you can resize and play with)
Place 2 span (as table-cell) inside a LI set as table
Trick the last span to width: 1%;
Add the desired dashes or dots or even a background-image to the first span's :after pseudo element
body{background:orange;} /* No other backgrounds are used */
ul.leaders {
padding: 0;
}
ul.leaders li {
display: table;
}
ul.leaders li span {
display: table-cell;
}
ul.leaders li span:first-child { /* TITLE */
position: relative;
overflow: hidden; /* Don't go underneath the price */
}
ul.leaders li span:first-child:after { /* DASHES */
content: "";
position: absolute;
bottom: 0.5em; /* Set as you want */
margin-left: 0.5em; /* Keep same for the next span's left padding */
width: 100%;
border-bottom: 1px dashed #000;
}
ul.leaders li span + span { /* PRICE */
text-align: right;
width: 1%; /* Trick it */
vertical-align: bottom; /* Keep Price text bottom-aligned */
padding-left: 0.5em;
/* white-space: nowrap; /* Uncomment if needed */
}
<ul class=leaders>
<li>
<span>Salmon Ravioli</span>
<span>7.95</span>
</li>
<li>
<span>Pan seared Ahi with avocado, soy, ginger and lime</span>
<span>8.95</span>
</li>
<li>
<span>Almond Prawn Cocktail</span>
<span>7.95</span>
</li>
<li>
<span>Bruschetta</span>
<span>45.25</span>
</li>
<li>
<span>Margherita Pizza</span>
<span>108.95</span>
</li>
</ul>

Related

Changing the color of the <ul> in CSS

I am asking this question because I am currently struggling to understand the difference between <ul> and <li>. Till now what I have read, practiced and understood, the <ul> (unordered list) seems to act like a parent <div> in which we can place <li> items.
So if that's the case, then if define the color of the <ul> then all its children <li> should also have the same color.
But unfortunately, it is not working out this way. Please see it below yourself. It's only when I define the background color of <li> the color finally changes.
However, much surprisingly I am able to define the text color (red) in <ul>.
But I am not sure why the background color (black) doesn't comes by defining in through <ul>?
The alternative, I know, is simple: Just define the background color black in the <li> element. However, I am trying to understand the reason behind this which would help me understand the definition of <ul> and <li> better.
ul {
background-color: rgba(0, 0, 0, 1);
color: rgba(255, 0, 0, 1);
}
ul li {
display: inline-block;
float: left;
border: 1px solid #000;
list-style-type: none;
}
<body>
<ul>
<li>First</li>
</ul>
</body>
Its because ul height not taken properly due to clear fix causing by child li tag float, you can fix this with clear fix hack.
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}
ul {
background-color: rgba(0,0,0,1);
color: rgba(255,0,0,1);
}
ul li {
display: inline-block;
float: left;
border: 1px solid #000;
list-style-type: none;
}
Just add .cf class to UL tag
<ul class="cf">
<li> First </li>
</ul>
CHECK JS BIN
put clearfix class on ul..it will work fine..:)
.clearfix {
zoom: 1;
}
.clearfix:before, .clearfix:after {
content: "";
display: table;
line-height: 0;
}
.clearfix:after {
clear: both;
}
You are using float on list items and you haven't set layout on parent.
Read about hasLayout css. And using inline-block with flaot is excess. Use only one. overflow hidden sets layout of parent. Always set layouts of parents when you use float.
ul {
background-color: rgba(0,0,0,1);
color: rgba(255,0,0,1);
overflow: hidden;
}
ul li {
float: left;
border: 1px solid #000;
list-style-type: none;
}
<body>
<ul>
<li> First </li>
</ul>
</body>
Because you are using float that's why.
Use overflow hidden in Ul just like:
overflow: hidden;
Here is Fiddle
https://jsfiddle.net/zt3auduv/1/

I am having alingment issue in navigation bar css

In first image was taken from IE, its having full width for every content, but if u see in second image last menu content, not taking full width. how to solve this in both browser
HTML:
<div class="menu-section clearfix">
<div class="menu-element clearfix">
<ul>
<li class="active">Home</li>
<li>about us</li>
<li>administration</li>
<li>academics</li>
<li>research</li>
<li>activities</li>
<li>examination</li>
<li>facilites</li>
<li>contact us</li>
</ul>
</div>
</div>
CSS:
.menu-section {
background-color:#900000;
height: 56px;
}
.menu-element {
background-color: #400;
height: 50px;
}
.menu-element li {
float:left;
}
.menu-element li:hover {
background-color:#900000;
}
.menu-element li.active {
background-color:#900000;
}
.menu-element li a {
color:#fff;
text-transform:uppercase;
display: block;
padding: 18px 21px;
text-decoration:none;
font-weight: bold;
}
You need to add style to the ul as well:
.menu-element > ul {
list-style: none;
margin: 0; padding: 0;
}
Maintaining consistency across browsers is bit difficult, but you could ensure same rendering by two methods.
Specify a valid doctype on your html to ensure standards mode, and
Specify a box-sizing typically border-box in your stylesheet.
-
* {
box-sizing: border-box;
}
If you want to justify the menu options across the width, then you will have to make a few adjustments and a hack.
Apply a fixed width to the wrapping div, text-align:justify on the ul and display:inline-block on li are required.
Note 1: The display: inline-block is required, however it generates html white-spaces. In order to get rid of those white-spaces, html comments can be used in the markup of list items.
Note 2: The :after pseudo element in the hack is what seems to do the trick. However, that will create an unintended space below the ul. This space seems to be there because the elements are flushed across. If not justified, then this space does not appear.
.menu-element {
width: 100%; /* fixed width required on wrapping container */
}
.menu-element > ul {
list-style-type: none; /* getting rid of bullets */
margin: 0px; padding: 0px; /* getting rid of default indents */
text-align: justify; /* important to justify contents */
}
.menu-element li {
display: inline-block; /* required. float won't work. */
text-align: left; /* to properly align list items */
white-space: no-wrap; /* to prevent wrapping of list items if required */
}
.menu-element > ul:after {
/* this is the hack without which the list items won't get justified */
content:''; display: inline-block; width: 100%; height: 0;
}
Demo: http://jsfiddle.net/abhitalks/mv7qnfLe/4/
Full Screen Demo: http://jsfiddle.net/abhitalks/mv7qnfLe/4/embedded/result/
.
Try this:-
.menu-element ul {
padding: 0;
}
Try This
Give some width to ul element and add this style rule in your css:
.menu-element ul {
clear: both;
list-style:none;
margin: 0 auto;
text-align: center;
width: 92%;
}
I hope it works for you.

How can align css colums vertcally to the bottom?

Having the following code: http://codepen.io/anon/pen/wCcfA
HTML:
<ul id="menu-main-menu">
<li><a>Home</a></li>
<li><a>About</a></li>
<li><a>Portfolio</a></li>
<li><a>Blog</a></li>
<li><a>Contact</a></li>
</ul>
CSS:
#menu-main-menu {
padding: 0;
height: 77px;
-webkit-column-count: 2;
-webkit-column-gap: 42px;
border: 1px solid blue;
width:250px;
}
#menu-main-menu li{
display: block;
list-style: none;
height: 24px;
border: 1px solid red;
}
How can I vertically align all the "li" elements at the very bottom of "menu-main-menu" rather than at the top?
How can I vertically align all the "li" elements at the very bottom of "menu-main-menu" rather than at the top?
I don’t think vertical-align can be applied here.
But there is an approach that should work: Using transform to first flip the whole menu around on the Y axis – and then again on the list items to flip them “back” to readable:
#menu-main-menu {
/* … */
-webkit-transform:scaleY(-1);
transform:scaleY(-1);
}
#menu-main-menu li{
/* … */
-webkit-transform:scaleY(-1);
transform:scaleY(-1);
}
http://codepen.io/anon/pen/Abrxl
Of course flipping the menu around changes the order of items – to correct that, their order in the HTML would have to be changed too: http://codepen.io/anon/pen/yxDsi Whether that’s a compromise your’re willing to make, is for you to decide.
I added the -webkit- prefixed version and the unprefixed one here, and also the -moz- versions of the column properties, yet in Firefox there seem to be some extra margins or something like that going on. That seems to come from applying the columns properties already though, and doesn’t seem to be a result of applying the transformation. Maybe you’ll find a solution to make that look smoother by yourself.
One solution is to use margin-top every 4n li elements like:
#menu-main-menu {
padding: 0;
height: 77px;
-webkit-column-count: 2;
-webkit-column-gap: 42px;
border: 1px solid blue;
width: 250px;
}
#menu-main-menu li {
display: block;
list-style: none;
height: 24px;
border: 1px solid red;
position: relative;
}
#menu-main-menu li:nth-child(4n) {
margin-top: 24px; /*add margin top*/
}
<ul id="menu-main-menu">
<li><a>Home</a>
</li>
<li><a>About</a>
</li>
<li><a>Portfolio</a>
</li>
<li><a>Blog</a>
</li>
<li><a>Contact</a>
</li>
</ul>

Vertially align image and link on a single line

How do I align the following so that the image and the link are vertically aligned? Also how do I increase the spacing between consecutive lines?
<li><img src="c.png" alt="Centern | Karta"/> Centern </li>
<li><img src="fi.png" alt="Feministiskt initiativ | Karta"/>Feministiskt initiativ </li>
You can put the images as background.
HTML
<li><a class='centern' href="centern.php" title="Centern | Karta">Centern</a> </li>
CSS
a.centern {
background: url('c.png') no-repeat;
height:20px; //height of the link
width:100px; //width of the link
padding-left:40px //give some space for the background image
}
Not entirly sure what you mean by alignment. I set up a fiddle here: http://jsfiddle.net/GX5k6/
/* this takes care of the alignment of the text and images */
li a {
display: block;
line-height: 32px;
float: left;
padding-left: 5px; /* spacing between image and text */
}
li img {
display: block;
float: left;
}
li {
clear: both;
overflow: hidden;
}
/* spacing between lines */
li {
margin-bottom: 5px;
}
Depending on wether you consider the images styling or content and if you want them to show up when the page is printed, you should indeed consider making them background images as suggested by #petar

Safari 5.1 breaks CSS table cell spacing

My site was working fine across all major browsers right up until the update to Safari 5.1. Now, the primary navigation is busted up. I was using display:table-cell on the anchor element within the list element and was also using the font-size:0 hack to remove the spacing in between menu elements. Has anyone else encountered this issue and have a solution they could offer up?
Before:
After:
CSS:
#navigation {
padding-top: 7px;
}
#navigation ul.links, /* Main menu and secondary menu links */
#navigation .content ul /* Menu block links */ {
margin: 0;
padding: 0;
display: block;
font-size: 0; /* this is a hack so that the spacing between the menu buttons disappear
since they are inline-block elements, this should be unneccessary when
CSS3 is approved */
}
#navigation ul.links li, /* A simple method to get navigation links to appear in one line. */
#navigation .content li {
display: inline-block;
padding-right: 0;
padding-left: 0;
margin: 0;
/* below is a fix for IE7 to get the main navigation items lined up correctly
* in one row
*/
zoom: 1;
*display: inline;
}
#main-menu ul {
width: 100%;
}
#main-menu li {
width: 108px;
text-align: center;
padding-bottom: 7px;
font-size: 11pt;
}
#main-menu a {
display: table-cell;
width: inherit;
text-decoration: none;
font-size: 0.9em;
color: #035B9A;
background-color: white;
height: 30px;
vertical-align: middle;
}
HTML:
<div id="navigation">
<div class="section">
<h2 class="element-invisible">Main menu</h2>
<ul id="main-menu" class="links inline clearfix">
<li class="menu-379 first">About Us</li>
<li class="menu-401">Research</li>
<li class="menu-385">Education</li>
<li class="menu-402">Outreach</li>
<li class="menu-403 active-trail active">News & Events</li>
<li class="menu-439">People</li>
<li class="menu-405">Resources</li>
<li class="menu-406">Publications</li>
<li class="menu-415 last">Partners</li>
</ul>
</div>
</div>
Thanks.
Just a note, this is a Drupal 7 site.
Also I freely and humbly admit I am not the very best at CSS markup. I'm learning a lot right now and am just trying to scrape through.
For those having trouble with Safari and dimensions for elements set to display:table; I was able to fix my problems by removing the padding and adding padding to a child element set to display:table-cell;
Apparently Safari does not like it when you try to add padding to an element set to display:table; In retrospect, this makes sense.
Solved by making the list elements display as block and float them to the left.
#navigation ul.links li, /* A simple method to get navigation links to appear in one line. */
#navigation .content li {
display: block;
float: left;
padding-right: 0;
padding-left: 0;
margin: 0;
/* below is a fix for IE7 to get the main navigation items lined up correctly
* in one row
*/
zoom: 1;
*display: inline;
}
You want border-collapse:collapse on the display:table element to remove cell spacing.
I took your css and html, and added to the css
body {
background-color: gray;
}
and I got the following, which looks correct.
This was run under lion, which has Safari 5.1