Remove last bar between links in nav - html

I have a jsfiddle here - https://jsfiddle.net/w4k70at5/
It's a realy simple problem but I'm a bit stumped.
I have a border between each link to separate them.
I don't want a border on the last link in the line.
I can remove the last border but can I remove the border after 'Link Six' and then when the page is resized remove the border on the last link on that line.
*{
margin: 0;
padding: 0;
}
nav{
margin: 50px;
max-width: 600px;
margin: 50px auto 0 auto;
}
ul{
list-style: none;
text-align: center;
}
li{
display: inline;
margin: 0 0 10px 0;
}
a{
display: inline-block;
border-right: 1px solid red;
font-size: 1.5em;
padding: 5px;
text-decoration: none;
}
li:last-of-type a{
border-right: none;
}

You can perform that using Jquery :
1st possibility:
Add a JQuery function which will add a class to your ul if it's the last one on the line:
$(function() {
var lastElement = false;
$("ul > li").each(function() {
if (lastElement && lastElement.offset().top != $(this).offset().top) {
lastElement.addClass("noborder");
}
lastElement = $(this);
}).last().addClass("noborder");
});
And a CSS class to remove the border:
.noborder a {
border: 0;
}
If you want, you can remove your CSS rule with the previous solution:
li:last-of-type a {
border-right: none;
}
JSFiddle 1: https://jsfiddle.net/ghorg12110/w4k70at5/4/
2nd possibility:
Same JQuery function but will not target the last ul > li a (because you already target it with your CSS):
$(function() {
var lastElement = false;
$("ul > li").each(function() {
if (lastElement && lastElement.offset().top != $(this).offset().top) {
lastElement.addClass("noborder");
}
lastElement = $(this);
});
});
And a CSS class to remove the border:
.noborder a {
border: 0;
}
JsFiddle 2: http://jsfiddle.net/ghorg12110/x93456gr/

FULL CSS SOLUTION
https://jsfiddle.net/w4k70at5/
I added a class to the <li> that cause a problem, and this one is set up like following :
When the screen size is under 590, I tell the class to show a right red border
When screen size is above, border is transparent
I used media queries CSS function to perform this. This allows to set different class behiaviour for different variables (like the screen size in this case).

Related

css/html dropdown menu on hover does not work for me

I'm trying to make a dropdown menu with html and css. I followed a ton of tutorials but they don't seem to work for me and I can not figure out why. I have an for a menubar that's always showing on the top of the screen and I want another to show when you hover the burgermenu on the left. This is my current code:
<body>
<div class='menudiv'>
<ul>
<li><a><img class='dropdown' src='burgermenu.png' alt='OpenMenu' height='90px' width="90px" onmouseover="this.src='burgermenuwit.png'" onmouseout="this.src='burgermenu.png'"></a></li>
<li style="float:right"><img src='pp.png' alt='LogIn' height='90px' width="95px" onmouseover="this.src='ppwit.png'" onmouseout="this.src='pp.png'"></li>
</ul>
</div>
<div class='logo'>
<a href="#home"><img src='flowy_logo.png' alt='Logo' height='95px', widht='95px' onmouseover="this.src='flowy_logowit.png'" onmouseout="this.src='flowy_logo.png'">
</div>
<div class='menu2'>
<ul>
<li><a>Meten</a></li>
<li><a>Huidige waardes</a></li>
<li><a>Geschiedenis</a></li>
<li><a>Contact</a></li>
</ul>
</div>
</body>
</html>
and css:
.menudiv ul {
font-family: "Georgia", "Times New Roman", "Serif";
font-size: 25px;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(102, 75, 255);
}
.menudiv ul li {
float: left;
cursor: pointer;
}
.menudiv ul li a {
display: block;
padding: 8px;
}
.logo img {
position: relative;
top: -105px;
margin-left: auto;
margin-right: auto;
display: block;
}
.menu2 ul {
position: relative;
list-style-type: none;
margin: 0;
padding: 0;
font-size: 30px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
top: -100px;
}
.menu2 ul li a {
display: block;
width: 200px;
background-color: rgb(102, 75, 255);
padding-top: 10px;
padding-bottom: 10px;
padding-left: 10px;
padding-right: 10px;
}
.menu2 ul li a:hover {
color: white;
cursor: pointer;
}
.menu2 {
display: none;
}
.dropdown:hover .menu2 {
display: block;
}
Can anybody tell me why it's not working?
You can achieve this by listening for the 'mouseover' event and changing the display style for menu2 to 'inline-block' (the ordinary 'block' takes the full width which is bad for 'mouseout'). You have to listen on both, the trigger ('Open Menu' link) and the menu itself.
To close the menu on 'mouseout' there is more code necessary then with a small inline onmouseout handler is possible:
First you have to check if the menu is hovered. Therefor you need a litle timeout before closing the menu from 'mouseout' on the trigger, so that the cursor has a chance to reach the menu.
Secondly you need to know that the 'mouseout' event is fired when changing to the next a or li tag in the menu. Since the 'mouseout' event is faster then the eventbubbling of the next 'mouseover' event from the a or li tag to the containing menu2, you need a second timeout for 'mouseout' on menu2 for checking if it is still hovered.
And third you have to check if the cursor is hovering again over the trigger when he has left the menu, otherwise the menu would remain closed and the 'mouseover' event on the trigger would not fire again. This can be checked in the second timeout check.
And fourth you need to wrap all that in an event handler that executes it not until the DOM is loaded. Otherwise the hover event listeners would have no effect because there would be no element to bind the listener to when the script is executed.
For the check if hovered use two variables that get true on 'mouseover' and false on 'mouseout'.
Here is a working example:
document.addEventListener('DOMContentLoaded', function() {
const menu_trigger = document.querySelector('#menu-trigger');
const menu2 = document.querySelector('.menu2');
var trigger_hovered = false;
var menu2_hovered = false;
menu_trigger.addEventListener('mouseover', function() {
trigger_hovered = true;
menu2.style.display = 'inline-block';
});
menu_trigger.addEventListener('mouseout', function() {
trigger_hovered = false;
setTimeout(function() {
if (menu2_hovered == false) {
menu2.style.display = 'none';
}
}, 10);
});
menu2.addEventListener('mouseover', function() {
menu2_hovered = true;
});
menu2.addEventListener('mouseout', function() {
menu2_hovered = false;
setTimeout(function() {
if (menu2_hovered == false && trigger_hovered == false) {
menu2.style.display = 'none';
}
}, 10);
});
});
* {
margin: 0;
padding: 0;
}
.menudiv ul {
display: flex;
justify-content: space-between;
overflow: hidden;
width: 100vw;
font-size: 25px;
font-family: "Georgia", "Times New Roman", "Serif";
list-style-type: none;
background-color: rgb(102, 75, 255);
}
.menudiv ul li a {
display: block;
padding: 8px;
cursor: pointer;
}
.menu2 {
display: none;
}
.menu2 ul {
list-style-type: none;
font-size: 30px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
.menu2 ul li a {
display: block;
width: 200px;
padding: 10px;
background-color: rgb(102, 75, 255);
}
.menu2 ul li a:hover {
color: white;
cursor: pointer;
}
<div class='menudiv'>
<ul>
<li id="menu-trigger">
<a>Open Menu</a>
</li>
<li>Login</li>
</ul>
</div>
<div class='menu2'>
<ul>
<li><a>Meten</a></li>
<li><a>Huidige waardes</a></li>
<li><a>Geschiedenis</a></li>
<li><a>Contact</a></li>
</ul>
</div>
Here is a JSFiddle with everything fixed: https://jsfiddle.net/dwauq9mL/
I had to change some things for my own convenience since I didn't have the images.
The problem: Since, menu2 is NOT a child of the the element on whose hover event you want it to display on, it will not work.
The solution: You need to put menu2 inside the li of the burger menu. You need to remove the .dropdown class from the burger image and add it to its parent li.
When you do this it is bound to mess the layout up. I wrote a JSFiddle for you (should be mentioned up) with everything fixed.
I recommend you not to use floats since they are deprecated. I removed the floats and used flexbox instead which is much better and recommended. I suggest you go learn Flexbox. I will link a few resources at the end of this answer.
CSS Tricks article on Flexbox:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Fun little game to learn Flexbox: https://flexboxfroggy.com/
bellow code will work only if there is no space between burgermenu button and menu2, I would suggest to add background color to menu2 div, so that you can see the div size
<script>
var menu2 = document.querySelector('.menu2');
document.querySelector('.dropdown')
.addEventListener('mouseover', function() {
menu2.style.display = 'block';
});
document.querySelector('.dropdown')
.addEventListener('mouseout', function() {
menu2.style.display = 'none';
});
menu2.addEventListener('mouseover', function() {
menu2.style.display = 'block';
});
menu2.addEventListener('mouseout', function() {
menu2.style.display = 'none';
});
</script>
if there is some space in between menu button and menu, you can manage this by adding some time delay for display:none, I don't know this will be the good way or not, but it will work.

How does Bootstrap add "/" to breadcrumb components?

Bootstrap breadcrumb components in both v3 and v4 add a "/" to list items:
http://getbootstrap.com/components/#breadcrumbs
https://v4-alpha.getbootstrap.com/components/breadcrumb/
The docs say:
Separators are automatically added in CSS through ::before and
content.
So, I looked at the source code, the relevant section showing:
.breadcrumb-item + .breadcrumb-item::before {
display: inline-block;
padding-right: 0.5rem;
padding-left: 0.5rem;
color: #636c72;
content: "/";
}
However, the content: "/"; only exists on the breadcrumb-item rule. Yet, it seems to work when I follow the v3 docs, which don't require a breadcrumb-item class for items inside a list:
<ol class="breadcrumb">
<li class=''>Home</li>
<li class=''>Library</li>
<li class="active">Data</li>
</ol>
JSFiddle
Why does the above HTML with the above CSS result in / separators being added to items in a .breadcrumb list even though they don't have the .breadcrumb-item class and thus can't benefit from the content: "/" rule? Inspecting the output HTML in JSFiddle shows that no bootstrap javascript magic has added a .breadcrumb-item class to my html list items.
link to this style at github (bootstrap v3.3.7):
https://github.com/twbs/bootstrap/blob/v3.3.7/less/breadcrumbs.less
for (bootstrap v4.0.0):
https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.6/scss/_breadcrumb.scss
(bootstrap v3.3.7 --> breadcrumbs.less)
//
// Breadcrumbs
// --------------------------------------------------
.breadcrumb {
padding: #breadcrumb-padding-vertical #breadcrumb-padding-horizontal;
margin-bottom: #line-height-computed;
list-style: none;
background-color: #breadcrumb-bg;
border-radius: #border-radius-base;
> li {
display: inline-block;
+ li:before {
content: "#{breadcrumb-separator}\00a0"; // Unicode space added since inline-block means non-collapsing white-space
padding: 0 5px;
color: #breadcrumb-color;
}
}
> .active {
color: #breadcrumb-active-color;
}
}
(bootstrap v4.0.0 --> _breadcrumb.scss)
.breadcrumb {
padding: $breadcrumb-padding-y $breadcrumb-padding-x;
margin-bottom: $spacer-y;
list-style: none;
background-color: $breadcrumb-bg;
#include border-radius($border-radius);
#include clearfix;
}
.breadcrumb-item {
float: left;
// The separator between breadcrumbs (by default, a forward-slash: "/")
+ .breadcrumb-item::before {
display: inline-block; // Suppress underlining of the separator in modern browsers
padding-right: $breadcrumb-item-padding;
padding-left: $breadcrumb-item-padding;
color: $breadcrumb-divider-color;
content: "#{$breadcrumb-divider}";
}
// IE9-11 hack to properly handle hyperlink underlines for breadcrumbs built
// without `<ul>`s. The `::before` pseudo-element generates an element
// *within* the .breadcrumb-item and thereby inherits the `text-decoration`.
//
// To trick IE into suppressing the underline, we give the pseudo-element an
// underline and then immediately remove it.
+ .breadcrumb-item:hover::before {
text-decoration: underline;
}
+ .breadcrumb-item:hover::before {
text-decoration: none;
}
&.active {
color: $breadcrumb-active-color;
}
}
In version 3 of Bootstrap, the separators are coming from:
.breadcrumb>li+li:before {
padding: 0 5px;
color: #ccc;
content: "/\00a0";
}
on line 6 of the included file breadcrumbs.less.
Hope this helps! :)
When you inspect the element, you get the style to be:
.breadcrumb > li + li:before {
padding: 0 5px;
color: #ccc;
content: "/\00a0";
}
So the above code targets all the descending <li> elements inside the .breadcrumb element.
The logic is pretty simple. The next element has a breadcrumb before.
There is a CSS rule like this:
.breadcrumb>li+li:before {
padding: 0 5px;
color: #ccc;
content: "/\00a0";
}

Unwanted Boostrap gutter spacing/margin/padding between rows

Problem:
Do you see the gutter spacing between them? I'd like to get rid of that and add custom ones to match the margin at the bottom.
Here's the page's code:
#posts
.row
- #posts.each do |post|
.col-xs-12.col-sm-6.col-md-4.col-lg-3
.post
.post_content
.title
%h2
= link_to truncate((post.title), length: 25), post
%p
$
= post.price
.post_image
= link_to image_tag(post.image.url), post
.data.clearfix
%p.username
Listing by
= post.user.name
%p.buttons
%span
%i.fa.fa-comments-o
= post.inquiries.count
%span
%i.fa.fa-thumbs-o-up
= post.get_likes.size
And of course, the CSS:
#posts {
.post {
margin: .5rem;
border: 1px solid #9B9B9B;
&:hover {
border: 1px solid white;
};
.post_image {
height: 20rem;
overflow: hidden;
img {
width: 100%;
border-radius: .3rem .3rem 0 0;
}
}
.post_content {
margin: 1rem;
h2 {
margin: 0;
font-weight: 100;
padding: 1rem;
border-bottom: 1px solid #E4E4E4;
font-size: 1.5rem;
a {
text-decoration: none;
/*color: #333233;*/
&:hover {
color: #6E58E0;
}
}
}
.data {
/*padding: .75rem 5%;*/
color: #969696;
.username, .buttons {
margin: 0;
font-size: 1rem;
}
.username {
float: left;
}
.buttons {
float: right;
span {
margin-left: .5rem;
}
}
}
}
}
}
Ideally, you should show me how to style it so that the individual posts are squares with even margin between them.
Simply add this (the other answer had the same idea but you don't need the commas since you're using HAML):
.col-xs-12.col-sm-6.col-md-4.col-lg-3 {
padding-right: 0;
padding-left: 0;
}
The reason is that Boostrap's row comes preloaded with paddings (not margins) of 35px and 15px. Therefore you need to reset it or set your own.
In the Sass version of Bootstrap, find the _variables.scss file. Search for "$grid-gutter-width". You can adjust this value to whatever you want to affect the gutter width.
The default gutter width is this:
$grid-gutter-width: 30px !default;
Change that to something smaller to see if that works.
If you're working in the already compiled version of Bootstrap, you'll have to adjust this crazy set of code:
.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9 {
position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px
}
Adjust the padding-left and padding-right here, or override them in your own css.
You shouldn't override default css, like in most answers.
To keep the default bootstrap css you could use this:
<div class="customdiv">
<div class="col-xs-12.col-sm-6.col-md-4.col-lg-3">
content here
</div>
</div>
You can than add the styling to customdiv.
.customdiv{
boder:2px red;//or something
}
When you override the bootstrap css you dont have the padding anymore at spots where you do want the padding.

Why is my drop down CSS disappearing, and how can I fix it?

This is a really strange problem which only affects Google Chrome.
If I have 299 rows in a drop down list, it keeps my custom CSS. However, the second I reach 300 rows all my styling is removed and seems to be set to a default by Google Chrome.
In the JSFiddle page, it has 300 rows, if you view the result, it will have default styling. But if you remove one row, my custom styling will be applied. Why is this?
JSFiddle: https://jsfiddle.net/s7opd7dm/
Simple drop down element:
#Html.DropDownListFor(m => m.SupplierID, new SelectList(Model.Suppliers, "SupplierID", "DisplayName"), "Select Supplier Name", new { #id = "SuppNameDD", #class = "GRDropDown", disabled = true })
I had the same problem. I found out that they disabled it at 300 options or more.
We intentionally disabled styling for 300+ options because of a
performance issue (crbug.com/500401).
Read about it here
Chrome Intentionally did disabled styling for 300+ options, so we can't reach the answer that way.
In short i would like to say that you should use any custom drop down.
As you are requesting for a solution to achieve, here's the fix
In that case i would prefer you to create a customized drop-down using other html elements like divs and list and take the selected list value. Here i am going to show a demonstration of how to create a customized div. The code has been tested in ASP.NET MVC5 C# and works fine. Post this demonstration here to promote this idea, as this might help anyone like you searching for what to do on cases like this.
in your some_view.cshtml add the following to include jquery and styles
<script src="#Url.Content("~/Scripts/jquery-1.10.2.min.js")"></script>
<!--<script src="#Url.Content("~/Scripts/myjquery.js")"></script> in case want this jquery to be external-->
<script>
function my_dd(el) {
this.dd = el;
this.initEvents();
}
my_dd.prototype = {
initEvents : function() {
var obj = this;
obj.dd.on('click', function(event){
$(this).toggleClass('active');
event.stopPropagation();
});
}
}
$(function() {
var dd = new my_dd( $('#dd') );
$(document).click(function() {
$('.wrapping').removeClass('active');
});
});
/** on select take the value to hidden text field**/
$(document).ready(function()
{
$('ul.my_dd li').click(function(e)
{
var selected=$(this).text();
/**change label to selected**/
$('.label').text(selected);
$('#selected-value').val(selected);
});
});
</script>
<!--<link href="#Url.Content("~/Content/my.css")" rel="stylesheet" type="text/css" />
in case want the css to be external-->
</script>
<style>
*,*:after,*:before {
box-sizing: border-box;
}
.wrapping {
position: relative;
width: 200px;
margin: 0 auto;
padding: 10px 15px;
cursor: pointer;
outline: none;
}
.wrapping:after {
width: 0;
height: 0;
position: absolute;
right: 16px;
top: 50%;
margin-top: -3px;
border-width: 1px solid red;
border-style: solid;
border-color: #366;
}
.wrapping .my_dd {
position: absolute;
top: 60%;
left: -45px;
right: 0px;
background: white;
transition: all 0.1s ease-out;
list-style: none;
opacity: 0;
pointer-events: none;
}
.wrapping .my_dd li a {
display: block;
text-decoration: none;
border: 1px solid;
padding: 10px;
transition: all 0.1s ease-out;
}
.wrapping .my_dd li i {
margin-right: 5px;
color: inherit;
vertical-align: middle;
}
.wrapping .my_dd li:hover a {
color: grey;
background-color: darkgrey;
max-height:300px;
}
.wrapping.active:after {
border-width: 0 6px 6px 6px;
}
.wrapping.active .my_dd {
opacity: 1;
pointer-events: auto;
height:300px;
overflow-y:scroll;
}
</style>
</style>
<div id="dd" class="wrapping">Test Drop Down
<ul class="my_dd">
<!-- use list or a foreach or for loop to push content to list
example
#foreach(var productId in Model.FailedProductIdsList)
{
<li>#Convert.ToString(productId);</li>
}-->
<li><i></i>Select 0</li>
...............
<li><i></i>Select 300+</li>
</ul>
</div>
<!-- #Html.TextBoxFor(c => c.Propertyname, new { #Value = "selected" })-->

How can I achive equal responsive padding for navigation elements?

I'm trying to create horizontal navigation bar, that fills out the screen, or parent container and will have equal horizontal padding for elements, that will equally reduce on smaller window width. Using display:table-cell I have got to the point that it nicely reduces but is not equal. Longer titles have more padding. I'm open to any working solutions, ideally css but if that is not possible, than anything that will work without glitches. What i have so far can be seen here
ul {
list-style:none;
padding:0;
width:100%;
display:table;
border-top:1px solid;
border-bottom:1px solid;
border-left:1px solid
}
li {
border-right: 1px solid;
margin:0;
display:table-cell;
position:relative;
text-align:center
}
<ul>
<li>some title</li>
<li>some longer title</li>
<li>some title</li>
</ul>
http://jsfiddle.net/xZ6q3/16/
Solved it (and learned a lot). The basic idea is to run through all list items and calculate the average padding. Then run through them again and set their width to their text width + average padding.
Heres the updated jsfiddle: http://jsfiddle.net/xZ6q3/21/
// calculate the average padding
var totalPadding = 0;
var count = 0;
$('li').each(function(){
var t = $(this);
var outer = t.outerWidth(true);
var inner = t.textWidth();
var padding = outer - inner;
totalPadding += outer - inner;
count++;
});
totalPadding /= count;
// set each width to text width + average padding
$('li').each(function(){
var t = $(this);
var inner = t.textWidth();
var newWidth = inner + totalPadding;
t.css('width', newWidth);
});
To make it work, I had to use Phil's textWidth() and listen to window resize events. See the jsFiddle.
Try this
ul {
border-bottom: 1px solid;
border-left: 1px solid;
border-top: 1px solid;
display: inline-block;
list-style: none outside none;
padding: 0;
}
li {
border-right: 1px solid;
display: inline-block;
margin: 0;
padding: 0 17px;
position: relative;
text-align: center;
}
First, I would go for float:left property and then change values for different screen resolutions.
ul li {
float:left;
padding-left: 15px;
padding-right: 15px;
}
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
ul li {
padding-left: 5px;
padding-right: 5px;
}
}