CSS overflow Property has different behaviour in Firefox only - html

I have a playlist as overlay for videos which should be scrollable.
.playlist{
height: 150px;
overflow-y: scroll;
border: 3px solid red;
}
.playlist li:before {
content: " ";
display: block;
height: 50px;
border: 1px solid #000;
}
.playlist li {
height: 50px;
}
.playlist li span {
display: block;
height: 50px;
position: relative;
top: -50px;
left: 10px;
}
A jsfiddle example of the situation here: http://jsfiddle.net/41unLxwk/4/
I use :before selector to display play- and pause buttons and the text is positioned relative. In this scenario there will be blank space in the end (only in firefox).
I know this does not happen if you do not use :before and relative positioning, but maybe there is another way to fix this.
edit: To clarify, the problem is that in firefox there is too much overflow-y in this example. I am not talking about the x-axis.

The problem is that the offset of relative positioned elements doesn't affect the other elements, so you see the space that where span would be if you didn't move them.
You can fix it adding
.playlist > ul {
overflow: hidden;
}
.playlist {
height: 150px;
overflow-y: scroll;
border: 3px solid red;
}
.playlist ul {
list-style: none;
padding: 0;
margin: 0;
overflow: hidden;
}
.playlist li:before {
content: " ";
display: block;
height: 50px;
border: 1px solid #000;
}
.playlist li:not(:first-child):before {
border-top: none;
}
.playlist li {
height: 50px;
}
.playlist li span {
display: block;
height: 50px;
position: relative;
top: -50px;
left: 10px;
}
<div class="playlist">
<ul>
<li>
<span>Song_1</span>
</li>
<li>
<span>Song_2</span>
</li>
<li>
<span>Song_3</span>
</li>
<li>
<span>Song_4</span>
</li>
<li>
<span>Song_5</span>
</li>
</ul>
</div>
However, consider something simpler like
.playlist > ul > li {
height: 50px;
border: 1px solid #000;
margin-top: -1px;
}
.playlist > ul > li:last-child {
border-bottom: none;
}
.playlist {
height: 150px;
overflow-y: scroll;
border: 3px solid red;
}
.playlist > ul {
list-style: none;
padding: 0;
margin: 0;
}
.playlist > ul > li {
height: 50px;
border: 1px solid #000;
margin-top: -1px;
}
.playlist > ul > li:last-child {
border-bottom: none;
}
<div class="playlist">
<ul>
<li>Song_1</li>
<li>Song_2</li>
<li>Song_3</li>
<li>Song_4</li>
<li>Song_5</li>
</ul>
</div>

Related

Enable :hover on margin

Is there any possibility to enable the :hover css effect also on the "margin area" of an object? I found a dirty solution working with an extra div inside, but is there something more elegant for this simple structure:
<ul>
<li><a>Hello</a></li>
<li><a>Hello</a></li>
</ul>
CSS
ul {
list-style: none;
margin: 0px;
padding: 0px;
}
li {
margin: 5px 100px;
background-color: #f1f1f1;
}
li:hover a {
color: red;
}
#dirty {
padding: 0px 100px;
margin: 0px -100px;
}
Hey is my working dirty example: https://jsfiddle.net/equalsound/wn4ctxvh/
If possible, a css only solution would be lovely.
As asked in the comments to your question, here is a working answer, using pseudo-elements to fill the 100px side margin:
ul {
list-style: none;
margin: 0px;
padding: 0px;
}
li {
position: relative;
margin: 5px 100px;
background-color: #f1f1f1;
}
li::before,
li::after {
content: '';
position: absolute;
top: 0;
bottom: 0;
width: 100px;
}
li::before {
right: 100%;
}
li::after {
left: 100%;
}
li:hover a {
color: red;
}
<ul>
<li><a>Hello</a></li>
<li><a>Hello</a></li>
</ul>
Just for fun, an alternative using transparent borders that's a little less practical due to the use of background-clip: padding:
ul {
list-style: none;
margin: 0px;
padding: 0px;
}
li {
margin: 5px 100px 5px 0;
border-left: 100px solid transparent;
background-clip: padding-box;
background-color: #f1f1f1;
}
li:hover a {
color: red;
}
<ul>
<li><a>Hello</a></li>
<li><a>Hello</a></li>
</ul>
Although, you can obviate the need for that if you can afford to make the a elements blocks and apply the background color to them instead:
ul {
list-style: none;
margin: 0px;
padding: 0px;
}
li {
margin: 5px 100px 5px 0;
border-left: 100px solid transparent;
}
li a {
display: block;
background-color: #f1f1f1;
}
li:hover a {
color: red;
}
<ul>
<li><a>Hello</a></li>
<li><a>Hello</a></li>
</ul>
Not sure if that is what you are aiming for, but maybe it could help:
https://jsfiddle.net/wn4ctxvh/2/
<ul>
<li>
<div>
<a>Hello</a>
</div>
</li>
<li>
<div>
<a>Hello</a>
</div>
</li>
</ul>
ul {
list-style: none;
margin: 0px;
padding: 0px;
}
li div {
margin: 5px 100px;
background-color: #f1f1f1;
}
li:hover a {
color: red;
}

CSS display block not working with anchor links

I am trying to make a dropdown-menu. So for this purpose, I've created a div and some anchor links inside, but the display: block; is not working. The cursor is default & the anchor does not seem to be a link.
Here is my HTML:
<div id="custom-wrapper">
<ul>
<li>View full profile</li>
<li>Logout</li>
</ul>
</div>
The CSS:
div#custom-wrapper
{
width: 200px;
height: auto;
position: fixed;
right: 15px;
top: 38px;
border-radius: 6px;
background: #fff;
border: 1px solid lightgrey;
}
div#custom-wrapper ul
{
list-style-type: none;
}
div#custom-wrapper ul li
{
width: 100%;
height: 50px;
line-height: 50px;
text-align: center;
}
div#custom-wrapper ul li a
{
text-decoration: none;
display: block;
color: grey;
font-family: sans-serif;
border-bottom: 1px solid lightgrey;
}
What's wrong with my code?
Display block element works perfect, Just you need to remove padding and margin for ul element.
/*** Default CSS Attributes ***/
#custom-wrapper ul {
margin: 0;
padding: 0;
}
/*** Overwrite CSS Attributes ***/
#custom-wrapper ul {
margin: 0 !important;
padding: 0 !important;
}
div#custom-wrapper {
width: 200px;
height: auto;
position: fixed;
right: 15px;
top: 38px;
border-radius: 6px;
background: #fff;
border: 1px solid lightgrey;
}
div#custom-wrapper ul {
list-style-type: none;
margin: 0;
padding: 0;
}
div#custom-wrapper ul li {
width: 100%;
height: 50px;
line-height: 50px;
text-align: center;
}
div#custom-wrapper ul li a {
text-decoration: none;
display: block;
color: grey;
font-family: sans-serif;
border-bottom: 1px solid lightgrey;
}
<div id="custom-wrapper">
<ul>
<li>View full profile</li>
<li>Logout</li>
</ul>
</div>
There is a padding for ul. Remove it:
div#custom-wrapper ul
{
list-style-type: none;
padding:0;
}
That is not the right way to build a dropdown. Check this (you would need to include Bootstrap library though, which by the way may make your life much easier).

Sizing the Mega Menu to page width and centering it

I am trying to make a mega menu that will be the width of the #header and also centered to the middle. The max-width of the header is 1024px. However the dropdown menu keeps starting at the edge of the parent li. I managed to hack it with margins, but that's not a permanent solution by any means. I've removed the margins for the sake of this question.
HTML
<header>
<div id="header">
<div class="row">
<div class="medium-3 columns">
<div id="logo">
<img alt="logo" src="http://dummyimage.com/174x114/828282/0011ff.png"/>
</div>
</div>
<div class="medium-7 columns">
<ul class="nav clearfix animated">
<li class="border-half">Home</li>
<li class="border-half">
Series
<div class="mega-container1">
<div style="width: 1000px; height: 290px;"></div>
</div>
</li>
<li class="border-half">Members
<div class="mega-container2">
<div style="width: 1000px; height: 290px;"></div>
</div>
</li>
<li class="border-half">
About
<div class="mega-container3">
<ul style="width: 1000px; height: 290px;">
<li>Who We Are</li>
<li>Why We Care</li>
<li>Some other page</li>
<li>How We Work</li>
</ul>
</div>
</li>
<li class="border-half">Contact Us</li>
</ul>
</div>
<div class="medium-2 columns">
</div>
</div>
</div>
</header>
CSS
body {font-size: 16px; background: #cacaca;}
#wrapper{width: 100%; height: 100%; padding: 0; margin: 0; background: #cacaca;}
header {width: 100%; max-height: 7.188em; background: #fff; border-bottom: 0.063em solid $header-border; z-index: 1;}
#header{max-width: 1024px; height: 7.125em; margin: 0 auto; padding: 0; background: #cdecde}
#logo {max-width: 10.875em; max-height: 7.125em; float: left; background: #eee;}
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;}
.nav {
background: #cdecde;
max-width: 500px;
height: 114px;
}
.nav li { list-style: none; }
.nav > li { padding: 0; float: left; position: relative; }
.nav > li > a {
float: left;
color: $body-font-color;
font-size: $paragraph-font-size;
text-decoration: none;
line-height: 114px;
padding: 0 20px;
height: 114px;
position: relative;
border-left: 1px solid #fff;
}
.nav > li:hover > a { background: #F7F7F7; border-left: 1px solid #f1f1f1;}
.nav > li:first-child > a { }
.nav > li:last-child > a { border-right: 0;}
.nav > li:hover > div { display: block; }
/* Mega Dropdown */
.nav > li > div {
position: absolute;
top: 114px;
display: none;
background: #F7F7F7;
padding: 10px 10px;
box-shadow: 0 2px 3px rgba(0,0,0,0.1);
overflow: hidden;
border-bottom: 4px solid $primary-color;
border-left: 1px solid $header-border;
border-right: 1px solid $header-border;
z-index: 2;
max-width: 1024px;
height: auto;
margin: 0 auto;
}
.mega-container1 {
left: ;
}
.mega-container2 {
left: ;
}
.mega-container3 {
left: ;
}
.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.border-half {
border-right: 1px solid #F0F0F0;
position: relative;
}
.border-half:before {
border-left: 1px solid #cdecde;
}
.border-half:after {
content: '';
display: block;
position: absolute;
height: 50px;
top: 0px;
right: -1px;
border: 1px solid #cdecde;
}
.border-half:hover::after {
right: -3px;
}
Here is a JSFiddle to get the idea: http://jsfiddle.net/7e3esmpx/
Update 1: The explanation was a little confusing.
Alright I think I have a solution to your problem. From my understanding, you want the hidden divs to appear when hovered, and take up the entire screen's width. Is that correct? To do that:
First add the position of fixed and a left margin of 0 to your nav li divs when they are hovered. i.e.:
.nav > li:hover > div { display: block;
position: fixed;
left: 0}
Change the max width on your nav li divs to contain the entire screen. i.e.:
.nav > li > div {
position: absolute;
top: 114px;
display: none;
background: #F7F7F7;
padding: 10px 10px;
box-shadow: 0 2px 3px rgba(0,0,0,0.1);
overflow: hidden;
border-bottom: 4px solid $primary-color;
border-left: 1px solid $header-border;
border-right: 1px solid $header-border;
z-index: 2;
max-width: 1800px;
height: auto;
margin: 0 auto;
}
The issue is that the UL had a certain width. And the dropdown was the same size of the UL meaning that if I resize the UL I should get the same width. So anyone having a similar issue, check your UL.

Why do menu bullets show up on my menus?

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;
}

Having trouble with making unusual shaped hover on first and last child

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?