I am working on a navigation with a bottom border. Active links are displayed with a second bottom border.
When I press refresh, sometimes there is a small gap between the two borders like on this screenshot. Why?
When I resize the window the gap is gone.
I have this issue in Chrome 97 on a mac. But I'm not sure if it doesn't occur in other browsers as well.
Does somebody can point me in the right direction?
* {
box-sizing: border-box;
}
a {
text-decoration: none;
}
li,
ul {
list-style-type: none;
padding: 0;
}
li,
ul {
margin: 0;
}
img{
width:100%;
height: auto;
}
.projektmenu-wrap {
border-bottom: 1px solid #000;
list-style: none;
overflow-x: auto;
padding-left: 2rem;
padding-right: 1rem;
padding-top: 0.75rem;
position: -webkit-sticky;
position: sticky;
top: 0;
white-space: nowrap;
z-index: 98;
}
.projektmenu {
align-items: flex-start;
display: flex;
flex-grow: 1;
flex-wrap: nowrap;
justify-content: flex-start;
white-space: nowrap;
width: 100%;
}
.projektmenu__item {
border-bottom: 3px solid transparent;
margin-right: 2em;
margin-top: 0;
}
.projektmenu__item--selected,
.projektmenu__item:hover {
border-bottom: 3px solid #000;
}
<img src="https://picsum.photos/200/300">
<nav class="projektmenu-wrap">
<div class="scrollable-menu">
<ul class="projektmenu">
<li class="projektmenu__item projektmenu__item--selected">
Lorem Ipsum
</li>
<li class="projektmenu__item ">
Dolor est
</li>
</ul>
</div>
</nav>
After some debugging i think the problem could be position: sticky.
Edit:
After some more debugging I realize that I forget something here, before the menu element there is an image with 100%width and auto height, maybe that could be the problem. I added it to the code above
After trying a lot of things, I have added some vw to the border, for the moment that is looking good. But it is hard to tell if it is the solution:
border-bottom: calc(3px + 0.1vw) solid #000
In general, having such a double border solution is always prone to rendering issues, because at different zoom levels the browser renders the borders a bit different.
See also: Google Chrome - Rendering differences when zooming in/out
A solution / workaround for your example would be to define the border width in relative units (e.g. rem), which isn't linked to pixels but based on font sizes (e.g. the root element).
Try this out:
.projektmenu__item--selected,
.projektmenu__item:hover {
border-bottom: 0.2rem solid #000; // alternative unit: em
// or: using a mixture of fixed and relative units
// border-bottom: calc(0.2rem + 3px) solid #000;
}
Also, although not required in this case, I would recommend you to use pseudo-elements like ::after for such markers in lists, it's basically what those are intended for.
Related
I'm trying to create a simple tabbed navigation menu in CSS. I am having a hard time getting the bottom border to go away on the active tab. Normally this would not be hard to do, but I also want a line height set.. so I'm using inline-block with various IE and FF fixes. This makes it display the way I want, with the exception of the bottom border.
I have tried numerous methods for getting this to work, including setting up some operators.. but I don't know enough about CSS to determine if I was using them correctly.
Here is my jsfiddle.
(Obviously my CSS skills need work and I could probably simplify the code greatly as well.)
Code:
#tab_menu {
width: 100%;
overflow: hidden;
color: #000000;
border-bottom: #dddddd solid 1px;
}
#tab_menu ul {
padding: 0px;
margin: 0px;
}
#tab_menu li {
list-style: none;
line-height: 42px;
padding-left: 15px;
padding-right: 15px;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
display: -moz-inline-stack;
/* Firefox Fix */
display: inline-block;
/* Normal Function */
zoom: 1;
/* IE Fix */
*display: inline;
/* IE Fix */
}
.tab_menu_active {
color: #000000;
border-bottom: none;
border-left: #dddddd solid 1px;
border-right: #dddddd solid 1px;
border-top: #dddddd solid 1px;
}
.tab_menu_active a {
color: #000000;
text-decoration: none;
}
.tab_menu_not_active {
}
.tab_menu_not_active a {
color:#52a4d4;
text-decoration: none;
}
.tab_menu_not_active:hover {
background: #eeeeee;
}
HTML:
<div id="tab_menu">
<ul>
<li class="tab_menu_not_active"> Link 1
</li>
<li class="tab_menu_active"> Link 2
</li>
<li class="tab_menu_not_active"> Link 3
</li>
<li class="tab_menu_not_active"> Link 4
</li>
<li class="tab_menu_not_active"> Link 5
</li>
</ul>
</div>
DEMO
for the #tab_menu I removed the overflow:hidden;
#tab_menu {
/*overflow: hidden;*/
}
to the .tab_menu_active I have added this styles, that will add border bottom white and with position manipulation will overidre the gray border color.
.tab_menu_active {
border-bottom:solid 1px #fff;
position:relative;
top:1px;
}
.tab_menu_active a {
position:relative;
top:-1px;
}
The problem you have is your entire #tab_menu has a bottom border. There are a couple ways you could solve this, but first I'll give you some details about how to simplify your css.
Give the li's the class tab, that means that every tab you have will all get the same css. On the active one, give it a second class, active. In your css definitions, define that all tab's should have the same css (instead of having duplicate css in tab_menu_active and tab_menu_not_active).
I would recommend giving them all a border on the bottom, and then removing that border in the active one.
Here's a forked jsfiddle.
I cannot figure this out. I HAVE DONE RESEARCH so please, no comments about me doing more research. Also, I am a noob, so be nice ;)
Here's my site: http://library.skybundle.com/
Hover your mouse over the two black rectangles in the main blue nav bar (header area). The a:hover should make the color change to a gray. The ISSUE is that in Chrome, this looks perfect. But, in Firefox, the padding-right isn't long enough or something, so there is always a small black rectangle at the far right side of the "Educational Courses" button (this will only be visible when hovering your cursor over the button). In other words, the gray box doesn't go all the way to the right-side end of the button area upon mouse hover. I just don't understand why this looks and works great in Chrome, but bugs out in Firefox...
Believe me when I say I have tried everything I can to fix it using Firebug in Firefox. If you play around with it using an editor in your browser, you will see that if you try to make the padding longer for Firefox, it pops the whole button down onto a new line. So to fix THAT problem, you must make the container wider, but then the original problem comes back. It's a circle of problems and I'm sure one of you geniuses out there will see a simple solution that I am missing.
Please help. Thanks!
EDIT :
Here's my JSFiddle and code. Notice how it looks great in Chrome but not in Firefox?
http://jsfiddle.net/S4st8/
HTML:
<div id="navigation">
<div id="navigation-inner">
<div id="page-nav">
<div id="primary-nav">
<ul id="top-menu">
<li id="li-left">Product Training Videos</li>
<li id="li-right">Educational Courses</li>
</ul>
</div>
</div>
</div>
</div>
CSS:
#navigation {
background: url(http://library.skybundle.com/wp-content/themes/business-services/library/styles/colour-images/mu-nav.jpg) repeat-x;
margin: 0px;
padding: 0px;
height: 40px;
width: 100%;
}
#navigation-inner {
margin: 0px auto;
padding: 0px;
height: 48px;
width: 960px;
}
#page-nav {
margin: 0px;
padding: 0px;
height: 40px;
width: 960px;
}
div#primary-nav {
position: relative;
display: block;
float: left;
margin: 0;
padding: 0;
}
ul#top-menu {
margin: -5px 0.325em 0 0.325em;
position: absolute;
padding: 0;
z-index: 100;
top: 0;
left: 3em;
width: 367px;
}
ul#top-menu li {
line-height: 3em;
list-style-type: none;
height: 49px;
background-color: #2C2C2C;
float: left;
}
li#li-right {
list-style-position: inside;
border-left: 2px solid #5E5E5E;
}
ul#top-menu li a {
font-weight: bold;
font-size: 11pt;
text-decoration: none;
padding: 15px 10px 16px 10px;
color: #ffffff;
}
ul#top-menu li a:hover {
text-decoration: none;
width: auto;
color: #ffffff;
background-color: #505354;
padding: 15px 10px 17px 10px;
}
its because a tags (anchor tags) have a default display property of inline
due to CSS Box Model you would need to adjust your padding and set the anchor tags display property to display:block;
the display block allows the anchor tag to fill the whole space of the LI tag
change ul#top-menu li a to this:
ul#top-menu li a{
color: #FFFFFF;
font-size: 11pt;
font-weight: bold;
display: block; /* add this */
padding: 0 10px; /* add this */
}
the CSS Box Model adds the content + padding + border + margin
https://developer.mozilla.org/en-US/docs/Web/CSS/box_model
Take a look at this CSS rule:
li#li-right {
border-left: 2px solid #5E5E5E;
list-style-position: inside;
}
Dropping list-style-position: inside seems to fix your issue in Firefox (and still works in Chrome), but I haven't tested the implications in other browsers. The CSS rule is documented here.
The reason why : browsers apply their own css if you don't specify it. Firefox added the space for your bullet (somehow)
FF :
list-style-image none
list-style-position outside
list-style-type disc
GooChrome :
list-style-image: none;
list-style-position: inside;
list-style-type: none;
User JasonSperske gave you a fixing solution,
i invite you to RESET your css.
PS. in the meantime, you are invited to see : https://stackoverflow.com/help AND http://sscce.org/
Reading and understanding those pages will give you few reputations points
I am strugling to make a simple function work in IE9. It works perfectly in Chrome and FF.
The purpose is to have 2 "ul" lists and move "li" elements between them, on click.
I would like to have li elements with blue background in the first container (MultiListAvailableElements), changing to green on mouse over. And opposite in the second container (MultiListSelectedElements) - green background, changing to blue on mouse over.
The problem is that in IE9 element's behave like they never loose hover state after I append them to opposite list. I have to move mouse over them (and out) to make them look like they should. So, for example, I click blue element from first container, it moves to second container and is still blue (blue in the second container is only for hover state, it should be green by default as the mouse is no longer over the element because the element has moved to different place). Then I have to move mouse over and out the elements in second container to make them come back to normal (green color).
HTML:
<div style="height: 210px; width: 600px;">
<div class="MultiListAvailableElements">
<ul id="OptionsUL">
<li id="id1" onclick="MLAdd(this)">1</li>
<li id="id2" onclick="MLAdd(this)">2</li>
<li id="id3" onclick="MLAdd(this)">3</li>
<li id="id4" onclick="MLAdd(this)">4</li>
<li id="id5" onclick="MLAdd(this)">5</li>
</ul>
</div>
<div class="MultiListSelectedElements">
<ul id="SelectedUL">
</ul>
</div>
</div>
CSS:
/* ------------------------------------ Available Elements --- */
.MultiListAvailableElements {
overflow-y: scroll;
width: 250px;
height: 200px;
border: 1px solid black;
}
.MultiListAvailableElements ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
.MultiListAvailableElements ul li {
background-color: #e5ecff;
border: 1px solid #c3caff;
width: 180px;
text-align: center;
margin-bottom: 2px;
padding: 2px;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: small;
}
.MultiListAvailableElements ul li:hover {
background-color: #e5ffec;
border: 1px solid #a3ffaa;
}
/* ------------------------------------ Selected Elements --- */
.MultiListSelectedElements {
overflow-y: scroll;
width: 250px;
height: 200px;
border: 1px solid black;
}
.MultiListSelectedElements ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
.MultiListSelectedElements ul li {
background-color: #e5ffec;
border: 1px solid #a3ffaa;
width: 180px;
text-align: center;
margin-bottom: 2px;
padding: 2px;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: small;
}
.MultiListSelectedElements ul li:hover {
background-color: #e5ecff;
border: 1px solid #c3caff;
}
JavaScript:
function MLAdd(Obj) {
document.getElementById("SelectedUL").appendChild(document.getElementById(Obj.id));
document.getElementById(Obj.id).onclick = function () { MLDel(Obj); }
}
function MLDel(Obj) {
document.getElementById("OptionsUL").appendChild(document.getElementById(Obj.id));
document.getElementById(Obj.id).onclick = function () { MLAdd(Obj);
}
You don't actually have to clone. Just remove it and append it elsewhere. Also, you don't have to request the element from the DOM because you are already passing it as an argument to the function (it's coming from the this in the original function call).
function MLAdd(Obj) {
Obj.parentNode.removeChild(Obj);
document.getElementById("SelectedUL").appendChild(Obj);
Obj.onclick = function () { MLDel(Obj); }
}
I'd also cache the results of document.getElementById("SelectedUL") as well by setting it in a variable from within a closure, but I'll leave that for you to figure out.
Whenever I have two elements side by side horizontally with right and/or left padding and/or margin specified, there is often space between the elements over and above what I've specified. I'm hoping someone can tell me how to eliminate that space (without something crufty like a negative margin).
Please note: I am not looking for alternative multi-column CSS layout techniques. I know there are loads of them out there and this issue is bigger than just a column layout issue.
Below is the markup and styles for a working example page. Here's a partial screenshot of that page that shows left elements selected with Firebug. The mysterious space in question is to the right and is marked with a red asterisk. There are no reset styles included but I've plugged in Eric Meyers' reset and it didn't solve the problem.
<div id="side-a">
<p>
Lorem ipsum ....
</p>
</div>
<div id="side-b">
<p>
Nunc dapibus....
</p>
</div>
<div id="website-footer">
<ul id="legal-information">
<li>Copyright 2011</li>
<li>Privacy Policy</li>
</ul>
</div>
div#side-a,
div#side-b {
display: inline-block;
width: 200px;
padding: 17px 17px 0;
}
div#side-a {
vertical-align: top;
}
div#side-b {
background: #999;
}
ul {
padding-bottom: 17px;
list-style: none outside none;
}
ul li {
line-height: 17px;
margin-left: 17px;
}
div#website-footer ul#legal-information {
float: left;
}
div#website-footer ul#legal-information li {
border-left: 1px solid #29443C;
display: inline;
margin: 17px 0;
padding-left: 8px;
}
div#website-footer ul#legal-information li:first-child {
border-left: medium none;
padding: 0 8px 0 0;
}
It's natural because of inline-block. Simple solution is to kill whitespace.
http://work.arounds.org/issue/6/unwanted-white-space-between-inline-block-elements/
There are other css based workarounds such as setting a font size of 0 on the body, but AFAIK they aren't as consistent/reliable. I could be wrong though.
I changed this Css:
div#side-a,
div#side-b {
float: left
width: 200px;
padding: 17px 17px 0;
}
And added in Css for the footer:
#website-footer {
clear: both;
}
And this fixed the issue.
I usually float the elements when I want them next to each other.
I have what I think is some pretty basic css, and it behaves differently in FF4 and IE8.
The CSS in question is like this:
div.showme {
border: 1px dotted blue;
position: absolute;
top :10px;
bottom :10px;
left: 1%;
right: 33%;
overflow: auto;
padding: 0.8em 1em 0.8em 1em;
line-height:1.75em;
}
div.showme a {
padding: 0em 5px 0em 5px;
margin: 0;
white-space: nowrap;
color: #FF00FF;
background-color:#E6E6FA;
border: 1px solid grey;
padding: 0em 4px 0em 4px; }
div.showme a:link { color: blue; }
div.showme a:visited { color: #1E90FF; }
div.showme a:active { color: red; }
The relevant HTML looks like this:
<div class='showme'>
<a href='one'>one</a>
<a href='two'>two</a>
...
</div>
The problem is, the padding is not consistently displayed, in IE8.
In Firefox, it works as I would expect.
working example:
http://jsbin.com/ogosa4
Using the above working demonstration, if you resize the window you will see the padding on the "leading" element on each line within the div, change from zero to non-zero.
How can I fix this?
If you add display: inline-block; to your div.showme a {} the padding will be applied in IE also, but it has some impact with the line height and you may need to specify additional margin's
I have seen this behaviour in Opera too. The padding goes to the upper line. Try display: inline-block and white-space:nowrap if you have more than one word in the link...
You can safely use inline-block in IE7 with inline tags.