The issue is quite simple really. Here is my CSS:
.fixed-body {
position: absolute;
}
And my HTML:
<div class="fixed-body">
<ul class="breadcrumb">
<li class="active">Name with spaces<span class="divider">/</span></li>
<li>Home<span class="divider">/</span></li>
<li>Library</li>
</ul>
</div>
Everything looks all right in all browsers apart from Internet Explorer 8. This is how it renders the Breadcrumb:
You can see it for yourself in this jsfiddle. This is just the resulting frame because jsfiddle doesn't render on IE8 properly. The whole fiddle is at this address (it's the same address without the "show" part in the URL).
There are two reasons why it doesn't render properly:
The CSS directive position: absolute in .fixed-body
Spaces in the first section of the breadcrum Name with spaces
If the first section doesn't contain spaces or the position of the parent node isn't set to absolute then Internet Explorer 8 renders the breadcrumb properly.
I tried to wrap the breadcrumb in another div and reset its position to static but it doesn't help. Is there any specific limitation of Internet Explorer 8 that shows in that way? And most interestingly, is there any way of fixing or working around this problem?
EDIT (copied from my response):
Just found by accident the proper fix. Overriding inline-block with inline for li in the breadcrumb gives the desired effect without any side issues (AFAIK):
.breadcrumb > li {
display: inline;
}
See also the new version of my fiddle, or open just the show frame in IE8.
This is because of "breadcrumb" width...
Check this in IE8: http://fiddle.jshell.net/azm53/12/show
I have changed breadcrumb width to 400px and it's ok.
<div class="fixed-body">
<ul class="breadcrumb">
<li class="active">Name with spaces<span class="divider">/</span>
</li>
<li>Home<span class="divider">/</span>
</li>
<li>Library
</li>
</ul>
</div>
And CSS
.fixed-body {
position: absolute;
}
.breadcrumb {
width: 400px;
}
Actually, setting the display to inline-block gives a similar result as the answer gave by ITChristian:
.breadcrumb {
display: inline-block;
}
However, both solutions have some problems. In case of setting width to a fixed value the site ceases to be responsive (the breadcrumb will not size with the window). When setting display to inline-block the gray background shrinks to only cover the links, leaving a white strip to the right. If after setting display to inline-block the width is set to 100% then it overflows the right border (since the width is to take 100% of the parent's element). Maybe the simplest solution would be to just get rid of the spaces?
EDIT:
Just found by accident the proper fix. Overriding inline-block with inline for li in the breadcrumb gives the desired effect without any side issues (AFAIK):
.breadcrumb > li {
display: inline;
}
See also the new version of my fiddle, or open just the show frame in IE8.
Related
I have a problem with very simple HTML markup, which is rendered different in Chrome and Firefox. I'm wondering whether it is a bug in one of them.
The code is as simple as:
<ul>
<li>
<img />
</li>
</ul>
The problem is that in Chrome the <li /> element has some padding at the top, but only if its content is an image. There is no problem with e.g. text.
Example fiddle: https://jsfiddle.net/8c4rujvu/1/
img {
display: block;
width: 500px;
}
li {
border: 1px solid #f00;
}
<ul>
<li>
<img src="http://www.w3schools.com/css/trolltunga.jpg">
</li>
<li>
<img src="http://www.w3schools.com/css/trolltunga.jpg">
</li>
<li>Some text</li>
</ul>
This is how it displays in Firefox (50.0.2):
And in Chrome (55.0.2883.75 m):
What seems to be a problem here?
This is due the default browser / user agent styling difference for display: list-item.
As a fix, you can use inline-block and vertical-align:top (or even just vertical-align: top) for the img to get common behaviour - see demo below:
img {
display: inline-block;
vertical-align: top;
width: 500px;
}
li {
border: 1px solid #f00;
}
<ul>
<li>
<img src="http://www.w3schools.com/css/trolltunga.jpg">
</li>
<li>
<img src="http://www.w3schools.com/css/trolltunga.jpg">
</li>
<li>
Some text
</li>
</ul>
A related question you may want to look at: Why alignment mark list is different on WebKit when using :before height?
Why this happens?
Given that other browsers do not agree with chrome on this, this clearly looks like a bug and it is. See this open bug documented in Chromium Bug Tracker:
Table inside list item rendered at wrong position(Example URL: http://jsfiddle.net/P8Ua7/)
See excerpts from one of the comments in the bug:
Not limited to tables. Putting a flexbox inside a list-item gives the
same result. It also happens if you have replaced content displayed as
block.
The OP has an image (which is an inline replaced element) displayed as block!
Here is another bug you may want to check out.
This issue can simply fix float:left property too , check this fiddle
https://jsfiddle.net/9wp619xz/
check with the bug details Fixing Google Chrome compatibility bugs in websites - FAQ
https://www.chromium.org/Home/chromecompatfaq
img {
float:left;
width: 500px;
}
li {
border: 1px solid #f00;
float:left;
width:100%;
}
<ul>
<li>
<img src="http://www.w3schools.com/css/trolltunga.jpg">
</li>
<li>
<img src="http://www.w3schools.com/css/trolltunga.jpg">
</li>
<li>Some text</li>
</ul>
It is usually due to browsers default styling. In order to fix this issue, i recommend using a normalize css stylesheet or by adding your own css for the element.
The solution is two-fold.
Setting the image to display: inline solves the empty line above the image. This empty line is a nasty bug in Chrome. This bug makes it effectively impossible to use/start with a non-inline element in a default list item. A very big deal if you ask me.
Adding vertical-align: top places the list marker on the top (which is where you probably want it to go). This also removes the unwanted space below the inline image. The list marker placement and the white space below the inline element are not bugs. This is expected behaviour.
This would result into the following (simple) work-around for the OP:
img {
width: 500px;
vertical-align: top;
/* display: inline; *//* This is default, thus can be omitted */
}
li {
border: 1px solid #f00;
}
https://jsfiddle.net/8c4rujvu/3/
This is caused by the two different approaches these two browsers take while rendering a UL / LI element. I think that is clear from the start :)
The issue here is not how inline elements behave!
The issue here is how list-style properties behave in these two browsers!
If you notice that, the size of gap is 18px, which is default line height in chrome! If you increase the font-size for the li then size of dot marker will also increase so as the distance of image from top edge of div.
If Firefox, that dot marker, or list-style-type component act as the absolute positioned element, thus any element after simply begin from the li top-left edge as expected.
But in Chrome, that dot marker, or list-style-type component act as the inline element, and like any other inline element will allow an inline/floating element to get in same line as itself. Thus text which is inline by nature began next to the dot! This applies also for image, button, link, span or any such elements!
Now what you feel as an issue is perfectly normal behaviour for those elements. Even If two elements are floating or inline, if they can not get in horizontal width of parent, the latter element fall down to next line! Similar is the case with display:block elements as they by default start on a new line!
In your example images have display:block, thus they will always begin on new line! But even if you remove that property, still image are quite big to fit in parent, thus it'll fall down & show a gap. (This is for smaller screens only, on larger screen this won't be an issue for inline-block image)
Again, weird part is that, div acts a inline element in this case, even if you give the width above 100%! From this I concluded that, if wrapping of content is possible then that element begin on new line but if content can not wrapped then it starts on a new line!
Note:
This is based on my observations & past experience! If anybody have links to official documentation for this case please paste if here. Also any suggestion to improve this answer are welcome.
I've updated your JSFiddle with more examples: https://jsfiddle.net/8c4rujvu/5/
Try this code for you HTML
ul li {
display:block;
}
img {
display: block;
width: 500px;
}
li {
border: 1px solid #f00;
display:block;
}
<ul>
<li><img src="http://www.w3schools.com/css/trolltunga.jpg"></li>
<li>
<img src="http://www.w3schools.com/css/trolltunga.jpg">
</li>
<li>
Some text
</li>
</ul>
The 1px vertical visual glitch
For an horizontal menu where I don't want to use floats, I have a small glitch which is a space of about 1px at the bottom of each LI container.
I tried to set the font size of the LI to 0, tried different values of vertical-align, overriding a potential border-bottom, but it still fails at least on chrome.
Note: check it with Chrome, it's not a "space related issue" between LIs (the horizontal space is not a problem for me, I just wanted to show you the simplified version of my issue), neither a text-decoration one.
Preview
<ul>
<li>
<a>
Something
</a>
</li>
<li>
<a>
Something else
</a>
</li>
<li>
<a>
Something else 2
</a>
</li>
</ul>
Fiddle source:
http://jsfiddle.net/darknessm0404/xjfd4p3z/
Notice that I do not want to use float because it creates some problem on complicated designs (with css clear properties for example).
Thank you for your help.
Add display to block to your links (li > a):
li > a {
display: block;
}
mention display:block in
li > a {
background-color:yellow;
display:block;
}
updated jsFiddle File
I think what you need is the text-decoration property set to none on your links to remove the line. Try this:
li > a {
background-color:yellow;
text-decoration: none;
}
So I have a navigation menu that is generated by my CMS:
The menu's HTML is straightforward (edited for clarity):
<ul>
<li>Journal</li>
<li>Art</li>
<li>Work</li>
</ul>
I want the items to show up as hand-written text, in keeping with the general theme of the site, using separate PNG files for each menu item.
To do that, I used the CSS content property like so:
#headerNav .nav li a[href="/_site/en/journal/"]
{ content: url(/path/to/image.png); }
And it worked great! The HTML text of each item was replaced by the correct image:
However, alas, then I learned not every browser supports the content property on selectors other than :before and :after! Chrome and Safari do it, but Firefox doesn. However when I use :before, the HTML node isn't replaced, but the image is added:
How do I work around this?
What didn't work:
Making the <a> element display: none removed the :before part as well.
Making the <a> element position: absolute and moving it elsewhere won't work either.
Making the <a> element width: 0px screws up the layout because the images added through content aren't in the document flow.
What I don't want to do:
Of course I can output the images by hand but I want to work with the HTML the CMS is giving me, which is <li>s with text in them.
Any solution involving background-image would require me to specify each item's width and height in the style sheet, which I would like to avoid for the purposes of this question.
Turning the handwriting into a font is not an option.
Using JavaScript to replace the items on the fly is not an option. This needs to work using pure HTML and CSS.
Since you are doing this into a navigation bar you should have a fixed height making the next method possible to work:
First insert the image as content on the :before element and make it display:block to push the actual text of the a tag below.
li a:before {
content:url(http://design.jchar.com/font/h_1.gif);
display:block;
}
Then hide that text with a fixed height on your a tag:
li a{
height:50px;
overflow:hidden;
}
The Working Demo
Answer was answered before OP added the line
Any solution involving background-image would require me to specify
each item's width and height in the style sheet, which I would like to
avoid for the purposes of this question.
So if anyone interested in background-image solution can refer this, else can simply skip.
Am not sure how optimum solution I am suggesting is, but surely you can use background-image for each a element, using nth- pseudo, and set the fonts color to transparent, or use text-indent property with overflow: hidden;
So it will be something like
nav ul li {
display: inline-block;
}
nav ul li:nth-of-type(1) a {
background-image: url(#);
display: block;
width: /* Whatever */ ;
color: transparent;
text-indent: -9999px; /* Optional */
overflow: hidden;
font-size: 0; /* Optional, some people are really sarcastic for this */
/* Below properties will be applicable if you are going for sprite methods */
background-position: /* Depends */ ;
background-size: /* If required */ ;
}
The reason why I would suggest you is :-
Advantages :
Cross browser compatible
Can you sprite methods to cut down http requests to request image for each tab
Also, you are not losing the text which is between the a tags, which is really good as far as screen readers are concerned.
Disadvantages :
Set custom width for each
Note: If you are going for a sprite solution, than background-position is anyways a must property to be used, so be sure you check out the support table first, before opting the sprite method.
Credits - For support table
I would put PNG images into img tag and then set alt attribute.
<ul>
<li><img src="journal.png" alt="Journal"/></li>
<li><img src="art.png" alt="Art"/></li>
<li><img src="work.png" alt="Work"/></li>
</ul>
I'm creating simple horizontal menu. When I hover item it changes background color, but lefts some strange 3px space on left side of the link, and I cannot identify why it shows up, and how to remove it.
Menu is here: http://pokerzysta.site44.com/ (Linki, Posty, Forum, Dodaj)
Any idea what's wrong with it?
Thats because you're displaying the list in a horizontal manner with display: inline-block;.
What is rendered there are white spaces from your HTML markup (most likely line-breaks after the li-tags).
If you put the li-tags in your html without white-space and line-breaks this won't happen:
<ul id="main-menu" class="horizontal-list fleft">
<li>Linki</li><li>Posty</li><li>Forum</li><li>Dodaj<li>
</ul>
#cimmanon pointed to a great article by Chris Coyier about displaying list navigations horizontally: http://css-tricks.com/fighting-the-space-between-inline-block-elements/
There're whitespaces between your LI-Elements. By removing them or using
float: left;
will solute also the problem (but after your UL you should use a clear: both)
your links are inline block, so the HTML whitespace actually uses space ;) A simple trick would be to set the font-size to 0 on the ul and reset the right font size in the li's
in your case:
.horizontal-list {
font-size: 0;
}
.horizontal-list li{
font-size: 17px;
}
http://testing.ipalaces.org/ looks different in IE9 where the 2nd LI in sub-navigation makes the top border. It seems the width it's at now works for every major browser but IE9. If I set it to exactly 3px less, it works good in IE9.
Is this a known bug? can I get around this without doing a conditional IE9 CSS call?
The problem is that without an explicit width, #sub-navigation li.selected renders a few pixels wider in IE 9 because of font rendering, interrupting the next floated element. Forcing a width will fix it.
Also, Verdana in bold renders relatively wide so you should consider dropping it from the font-stack.
#sub-navigation li { font:700 16px/1 geneva, sans-serif; }
#sub-navigation li.selected { width:105px; }
How about text-overflow?
+css:
#sub-navigation li span {
white-space: nowrap;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
Try this, anyway I don't have IE (Mac rulz) but in my workplace we usually optimize sites for IE too. I'll check it tomorrow if this is not going to work.
Can I ask, why do you have all the dropdowns featured as a nested list inside the last <li> in the navigation?
If it was me, I'd have each dropdown inside it's own list, as a sub-item fo the parent link.
This way, you can inherit the horizontal boundaries of the drop-down item for the parent-item, and it should be more straightforward to match widths.
Also, the code will read more logically, and expand more easily in future.
You should set a fixed width to all your li's for the submenu depending on the number you want. right now the first list element should be set to width: 107px.
to test it, just add style="width:107px" to <li class="selected">
Good luck :)