Bootstrap drop down cutting off - css

I am trying to add a dropdown setting menu to my comments section in a project that I've been working on.
The dropdown menu seems to cut itself off and I am not sure why is that the case.
I tried overflow:visible and z-index:999. but none of them seem to work.
This is a basic comment block that I am trying to include a dropdown in
This is the basic code that I am trying to Implement
<div class="media">
<a class="pull-left" href="/user/{{shared_scribble.scribble.user.username}}/"><img class="media-object" src="/img.png/"></a>
<div class="dropdown pull-right">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#" style="font-size:10px;padding: 4px 8px;">
<b data-icon=""></b> <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><i class="icon-pencil"></i> Edit</li>
<li><i class="icon-trash"></i> Delete</li>
<li><i class="icon-ban-circle"></i> Ban</li>
<li class="divider"></li>
<li><i class="i"></i> Make admin</li>
</ul>
</div>
<div class="media-body">
<h4 class="media-heading"><a class="username" href="/user/hi/">Test User</h4>
<p>
Main body of the comment
</p>
</div>
</div>
And this is how my dropdown menu is turning out to be
media CSS
.media,
.media-body {
overflow: hidden;
*overflow: visible;
zoom: 1;
}
.media,
.media .media {
margin-top: 15px;
}
.media:first-child {
margin-top: 0;
}
.media-object {
display: block;
}
.media-heading {
margin: 0 0 5px;
}
.media .pull-left {
margin-right: 10px;
}
.media .pull-right {
margin-left: 10px;
}
.media-list {
margin-left: 0;
list-style: none;
}

This is not an ideal solution as the menu will not scroll with the target element, but I'm doing this for a scrolling data table as a last resort until I can find an alternative:
(function() {
var dropdownMenu;
$(window).on('show.bs.dropdown', function(e) {
dropdownMenu = $(e.target).find('.dropdown-menu');
$('body').append(dropdownMenu.detach());
dropdownMenu.css('display', 'block');
dropdownMenu.position({
'my': 'right top',
'at': 'right bottom',
'of': $(e.relatedTarget)
})
});
$(window).on('hide.bs.dropdown', function(e) {
$(e.target).append(dropdownMenu.detach());
dropdownMenu.hide();
});
})();
This will append the menu to the body and clean it up on hide. I'm using jquery UI for positioning but you can replace it with regular jquery positioning if you don't want to add the heavy dependency. You may also want to alter $(window).on if you only want to do this to a limited selection of dropdowns.

Check whether media class is has overflow:hidden. If so, replace it with overflow: auto or overflow: visible.

Write like this:
.media,
.media-body {
overflow: visible;
}
.media:after,
.media-body:after{
content:'';
clear:both;
display:block;
}
May be that's help you.

I had the same problem. After adding this lines, my dropdown worked just as I expected:
#media (max-width: 767px) {
.table-responsive .dropdown-menu {
position: static !important;
}
}
#media (min-width: 768px) {
.table-responsive {
overflow: visible;
}
}
I found the solution here

NEW METHOD:
Just bring drop down menu out of media class and use a negative margin:
<div class="dropdown pull-right" style="margin-left:-30px">
...
</div>
<div class="media">
...
</div>

Get this quite often on projects I inherit; tends to be a case of one of the parent elements having
overflow:hidden
Once I remove this it seems to work as expected (as long as your design doesn't rely on this property).

Based on #nick answer, this is what I do in Bootstrap 3 without Jquery UI.
let dropdown_toggles = $('.my-table .dropdown-toggle');
dropdown_toggles.each(function (index, elem) {
let dropdownMenu;
let dropdown_toggle = $(elem);
dropdown_toggle.dropdown();
dropdown_toggle.parent().on('show.bs.dropdown', function(e) {
let $target = $(e.target);
let $relatedTarget = $(e.relatedTarget).parent();
dropdownMenu = $target.find('.dropdown-menu');
dropdownMenu.css({
'position': 'absolute',
'z-index': 1,
'top': ($relatedTarget.offset().top + $relatedTarget.height()) + 'px',
/*'left': $relatedTarget.offset().left + 'px',*/ //from left
'left': ($relatedTarget.offset().left - dropdownMenu.width() + $relatedTarget.width()) + 'px', //from right
});
$('body').append(dropdownMenu.detach());
dropdownMenu.css('display', 'block');
});
dropdown_toggle.parent().on('hide.bs.dropdown', function(e) {
$(e.target).append(dropdownMenu.detach());
dropdownMenu.hide();
});
});
This will allow you to set from left or right with position absolute.

Related

Responsive Media Query for a Submenu

I'm learning Responsive Media Query, I would like to do two things:
Remove arrow icon
Adapt the submenu, I guess I just have to decrease the font size?
Here is an illustration below:
How to remove this icon, please?
HTML
<ul class="nav-links">
<li *ngFor="let menu of menus; let i = index" [class.active]="menu.active">
<ng-container>
<a class="item" (click)="selectMenu(menu)">
<i [class]="menu.iconClass"></i>
<span class="links_name">{{ menu.name }}</span>
<i class="fa fa-chevron-down"></i>
</a>
<ul
class="submenu"
#submenu
[ngStyle]="{ 'height': menu.active ? submenu.scrollHeight + 'px' : 0 + 'px' } "
>
<li *ngFor="let submenu of menu.submenu">
<a routerLink="{{ submenu.url }} "
><span class="links_subname">{{ submenu.name }}</span>
</a>
</li>
</ul>
</ng-container>
</li>
</ul>
CSS
/* Responsive Media Query */
#media (max-width: 400px) {
.sidebar {
width: 0;
}
.sidebar.active {
width: 60px;
}
.home-section {
width: 100%;
left: 0;
}
.sidebar.active~.home-section {
left: 60px;
width: calc(100% - 60px);
}
.home-section nav {
width: 100%;
left: 0;
}
.sidebar .logo-details .logo_name img {
height: 30px;
width: 65px;
margin: 0 auto;
}
.sidebar.active~.home-section nav {
left: 60px;
width: calc(100% - 60px);
}
.sidebar .nav-links .submenu .links_subname {
color: #fff;
font-size: 14px;
margin: 0 auto;
}
}
Here is a reproduction here.
Thank you for your help and comments.
#media (max-width: 400px) {
.fa-chevron-down{
display: none;
}
}
this code will remove your icon
but about the text
NO
Please do not make font-size smaller, this is a wrong approach to making websites responsive. In Responsive Web Design as your device size decreases you should generally increase your sizes(absolutely there are a few exceptions but generally that's true)
because the device size is Already Small Enough!
consider yourself trying to use this page with a device with below 400px width, is it easier to read smaller texts on that site? or larger ones? is it easier to TAP on smaller buttons? or larger ones (With enough distance)
so I suggest you increase the size of your side-bar instead of decreasing your font-size

CSS alignment - <h3> <span>

I have the following fiddle - here I am trying to align the 'click' and <h3> in the same line
I am facing 2 issues here -
when the h3 content is too long it is pushing 'click' -
and on click when it shows the content it is moving sideways. Any ideas on how to acheive this - new to CSS.
Tried giving display:inline to <h3> but that did not help in this scenario.
http://jsfiddle.net/92spd439/
$('#ttt a#iimarrow').css({
cursor: "pointer"
}).on('click', function() {
$(this).next('ul').toggle();
});
ul {
display: none;
}
#ttt {
float: right;
}
a#iimarrow {
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<h3><a> tdhfkjshdfhsdfsdflkshdlflskfjl</a><h3>
<span id="ttt">
<a id="iimarrow">click</a>
<ul>
<li>12</li>
<li>13</li>
</ul>
</span>
The problem here is actually the h3 element which defaults to a display: block;. So if you just remove a#iimarrow{display:inline-block;} (since a tags default to display: inline; as #mikelt21 pointed out) and add the CSS below, then your problem will be fixed.
h3 {
display: inline;
}
JSFiddle
I believe something like this might be what you are looking for.
What I did was add float:left to the first <a>.
As following:
<h3>
<a style="float:left"> tdhfkjshdfhsdfsdflkshdlflskfjl</a>
</h3>
You could achieve this by placing the right-floated <a> element ahead of the <h3> in the HTML:
$('#ttt a#iimarrow').css({
cursor: "pointer"
}).on('click', function() {
$(this).next('ul').toggle();
});
ul {
display: none;
}
#ttt {
float: right;
}
a#iimarrow {
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="ttt"><a id="iimarrow">click</a>
<ul>
<li>12</li>
<li>13</li>
</ul>
</div>
<h3><a>tdhfkjshdfhsdfsdflkshdlflskfjl</a><h3>
Note that a <span> cannot contain the block-level <ul> element, so I've used a <div> in place of that, otherwise the only change is rearranging so the <div> (#ttt) comes ahead of the <h3>.

Max-Height Firefox/Opera/IE

I'm trying to set a max-height to an image. It works well in Safari and Chrome, but not in Firefox/Opera/IE. Now I read that html and body heights should be put at 100%, and it did work when I used jsfiddle. However, it doesn't work in my page (memo-designs.com/portfolio.php).
The following is the source of the page:
<!DOCTYPE html>
<html>
<head>
<title>memodesigns</title>
<link rel='stylesheet' href='style/stylesheet.css'>
<script type = 'text/javascript'>
function displayImage(image, link) {
document.getElementById('img').src = image;
document.getElementById('mylink').href = link;
}
function displayNextImage() {
if (x < images.length-1){
x++;
} else {
x = 0;
}
displayImage(images[x], links[x]);
}
function displayPreviousImage() {
if (x > 0){
x--;
} else {
x = images.length-1;
}
displayImage(images[x]);
}
function startTimer() {
setInterval(displayNextImage, -1);
}
var images = [], links = [], x = 0;images[0] = "http://memo-designs.com/items/doublek-01.png"
links[0] = "http://memo-designs.com/items/doublek-01.png"
images[1] = "http://memo-designs.com/items/memodesigns.png"
links[1] = "http://memo-designs.com/items/memodesigns.png"
</script>
</head>
<body style = 'background-color: #000000'><div id = 'menucontainer'>
<div id = 'menu'>
<p>
<ul>
<li><a class = 'menu' href = '/'>HOME</a></li>
<li><a class = 'menu' href = 'about.php'>ABOUT</a></li>
<li><a class = 'menu' href = 'portfolio.php'>PORTFOLIO</a></li>
<li><a class = 'menu' href = 'rates.php'>RATES</a></li>
<li><a class = 'menu' href = 'contact.php'>CONTACT</a></li>
</ul>
</p>
</div>
</div>
<div id = 'contentcontainer' style = 'padding-top: 0%; max-height: 100%; overflow: hidden; background-color: #000000'>
<p>
<img id= 'img' src = 'http://memo-designs.com/items/doublek-01.png' style = 'max-height: 100%; max-width: 100%; display: block; margin-left: auto; margin-right: auto;'>
<img class = 'arrow' onclick = 'displayPreviousImage()' id= 'img' src = 'style/graphics/larrow.png' style = 'position: absolute; left: 0; top: 40%;'>
<img class = 'arrow' onclick = 'displayNextImage()' id= 'img' src = 'style/graphics/rarrow.png' style = 'position: absolute; right: 0; top: 40%;'> </p>
</div>
</body>
</html>
And the css stylesheet (only part of it is shown here):
*{
margin: 0;
padding: 0;
}
html{
margin: 0;
min-width: 100%;
height: 100%;
min-height: 100%;
}
body{
margin: 0px;
background-color: #f3f4f4;
min-width: 100%;
height: 100%;
min-height: 100%;
}
Would appreciate any help as to what I'm doing wrong :)
First of all I recommend you to start using a CSS-Reset like Normalize.css . It makes browsers render all elements more consistently and in line with modern standards.
Your HTML notation might also cause inconsistency across browsers. Turn things like <div id = 'menu'> into <div id="menu">. This makes it also more readable IMHO.
Inline style attributes make maintaining the pages a pain and may override things you didn't intent to. They also need to be applied to every single element thus also increasing download time. Using classes / id's is the way to go. Also pseudo-elements can't be used with inline styles. I advice to only use them for quick changes during development. I use the element inspector from Chrome / Firefox to change things quickly and instantly see how the changes look, copy/pasting the edits afterwards.
So, make sure to put all css into your stylesheet. It's also considered as a best practice for maintainability and better download speed (minify the files for production) of your pages.
You surely have heard about jQuery before. Try using it. jQuery makes developing things like image sliders a breeze (once you understand the syntax, but it's a low learning curve). Furthermore, there are LOTS of ready-to-use plugins for jQuery.
Another "good practice" is to put your javascripts at the very end of your document just before the </body> tag. Read more about this here and here.
Ok, enough tips. Let's get the hands dirty:
The HTML Part:
<!DOCTYPE html>
<html>
<head>
<title>memodesigns</title>
<link rel="stylesheet" href="/assets/css/normalize.css">
<link rel="stylesheet" href="/assets/css/style.css">
</head>
<body>
<div id="menuContainer">
<div id="menu">
<p>
<ul>
<!-- Instead of writing in CAPITALS use the text-transform:uppercase; css property -->
<li><a class="menu" href="/">Home</a></li>
<li><a class="menu" href="about.php">About</a></li>
<li><a class="menu" href="portfolio.php">Portfolio</a></li>
<li><a class="menu" href="rates.php">Rates</a></li>
<li><a class="menu" href="contact.php">Contact</a></li>
</ul>
</p>
</div>
</div>
<div id="contentContainer">
<p>
<!-- NOTE: Use IDs only once, else use classes to share css styles -->
<img id="img" src="http://memo-designs.com/items/doublek-01.png">
<img class="arrow left" src="style/graphics/larrow.png" onclick="displayPreviousImage()">
<img class="arrow right" src="style/graphics/rarrow.png" onclick="displayNextImage()">
</p>
</div>
<!-- Put the JavaScript at the end of the document just before the closing body tag -->
<script>
var images = [], links = [], x = 0,
baseUrl = "http://memo-designs.com/items/";
images[0] = baseUrl + "doublek-01.png";
links[0] = baseUrl + "doublek-01.png";
images[1] = baseUrl + "memodesigns.png";
links[1] = baseUrl + "memodesigns.png";
function displayImage(img, link)
{
document.getElementById('img').src = img;
document.getElementById('mylink').href = link;
}
function displayNextImage()
{
if (x < images.length-1) x++;
else x = 0;
displayImage(images[x], links[x]);
}
function displayPreviousImage()
{
if (x > 0) x--;
else x = images.length-1;
displayImage(images[x]);
}
function startTimer()
{
setInterval(displayNextImage, -1);
}
</script>
</body>
</html>
...and the CSS:
/* Assuming you'll use a CSS-Reset */
body {
background-color: #f3f4f4;
font:
...
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
#menuContainer { ... }
#menu { ... }
#menu ul { ... }
/* Making the menu labels all UPPERCASE */
#menu ul > li {
text-transform: uppercase;
}
#contentContainer {
background-color: #000;
padding-top: 0;
overflow: hidden;
/* IMPORTANT: Set a fixed pixel height here to make the images use up the given space */
height: 200px; /* change 200 to your needs */
}
#img {
display: block;
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
}
#contentContainer .arrow {
position: absolute;
top: 40%;
}
#contentContainer .arrow.left {
left: 0;
}
#contentContainer .arrow.right {
right: 0;
}
Ok, try out the suggestions and the code example. Tell us if and what helped.
Good luck and happy coding!

CSS onhover Popup

I have created CSS onHover popup as given here. but problem is, User should be able to click the Register link in the example. here, Popup disappears as I move the mouse aware form the link.
Can anyone tell how it could be achieved ?
HTML:
<div class="how f-left">
<h7>How does this work?</h7>
<div class="how-works bubble-outer">
<div class="navigation-up-arrow"></div>
<div class="body">
<h4>How It Works</h4>
<ol class="bubble-inner">
<li>Tell Us What's Wrong </li>
<li class=""> Register to Get Quotes from Local Shopshere </li>
<li class=" bold-txt ">Call Shop / Get Vehicle Serviced </li>
<li>Get Cash Back </li>
</ol>
</div>
</div>
</div>
Below CSS is used for onHover PopUp:
.how h7:hover + .how-works {
display: block;
}
You can make it display on hovering the parent (.how), not just its preceding sibling. Hovering the parent happens when you are hovering any of its descendants (the link, .how-works, any of the children of .how-works).
To do this, change:
.how h7:hover + .how-works {
display: block;
}
to:
.how:hover .how-works {
display: block;
}
DEMO
Also, if you want to make it work for touchscreens (no hover there), you could adjust a bit your HTML. Change
<h7>How does this work?</h7>
to
<a class="how-it-works" href="#" tabindex="1"><h7>How does this work?</h7></a>
and add this to the CSS as well:
.how-it-works:focus + .how-works {
display: block;
}
DEMO
Add this to your CSS:
.how-works:hover {
display: block;
}
Modified version of your demo: little link.
Here is a working example link.
Put
.how:hover .how-works {
display: block;
}
instead of
.how h7:hover + .how-works {
display: block;
}
and add position: relative; top: 0px; css properties to .how .how-works.bubble-outer{ ... }

How to make only one line list wider than screen?

I have a list, which length is variable,it could have 4 items or 30 items.
The issue is that this list is being rendered as a marquee, through a Javascript that is working, but items reach the screen width and then they pass to next line.
I want to have all the items on the same line, so then I could move the list to recreate the marquee effect.
<div class="submenu-container">
<div id="agrupador">
<ul style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px;" class="submenu" id="moverlo">
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>
<li> Item </li>
</ul>
</div>
</div>
.submenu-container {
background:#F0F7FF;
border-bottom:1px silver solid;
width: 100%;
overflow: hidden;
}
.submenu li {
display: inline-block;
margin-left:4px;
background:none;
*display: inline; /* IE */
float:left;
}
.submenu {
margin:0;
padding-top:8px;
padding-bottom:8px;
padding-left:0;
padding-right:0;
clear:none;
width:auto;
float:left;
}
And with javascript:
function ClonarAvisos(){
var width = alertSize(); // Usable window width
var xVarScreen = width - $('moverlo').getWidth();
alert($('moverlo').getWidth());
$('moverlo').setStyle({ width: $('moverlo').getWidth() + xVarScreen });
$('agrupador').setStyle({ width: $('moverlo').getWidth() * 2 });
var clon = Element.clone('moverlo', true);
clon.id = 'moverlo2';
$('agrupador').insert(clon);
}
function MoveNoticias(p) {
//Función que imita el comportamiento del Tag "marquee"
new Effect.Move('agrupador', {
x: -3,
y: 0,
mode: 'relative',
duration: 0.1,
afterFinish: function() {
var offSetDistance = $('agrupador').offsetLeft ;
offSetDistance = Math.abs(offSetDistance);
var gettingWidth = $('moverlo').getWidth() ;
if ( offSetDistance >= gettingWidth ) {
Element.setStyle('agrupador', {left: '0px' });
}
MoveNoticias();
}
});
}
I hope you understand what I am trying to do! Thanks!
Try removing the float: left from the li, and adding white-space: nowrap to the 'ul'.
I tried that here: http://jsfiddle.net/76d6p/

Resources