Create a dropdown menu with arrow pointer in SASS - html

I want to know how can I implement dropdown menu with arrow pointer in CSS (SASS).
The idea is simple:
1) menu dropdown on press on left or right button
2) dropdown always centred and takes 85% of screen width (please refer screenshot http://joxi.ru/12MpgxpI4y8olm).
3) only the arrow should point 1 or 2 when clicking the respective button.
Here is where problems came:
1) I use absolutely positioned dropdown window (and the arrow too therefore) and all his parents up to the action button itself have position: static (this is required to have a dropdown window always aligned to the left side of a screen and take a % of screen's width)
2) Arrow starts to be positioned against screen size - instead of being positioned against her grandparent - action button. Arrow starts posing against button only if I remove position: static from button, but in this case I've lost dropdown taking full-screen with and aligned to left corder of a screen (it starts to show up against button).
I've tried to do some implementation with flexbox / clearfix, but it seems doesn't work with static elements. Or I misunderstood the idea.
So, my questions are:
1) How I can build a dropdown with arrow pointer properly as I described above and showed on a screenshot? (http://joxi.ru/12MpgxpI4y8olm)
Any ideas?
2) How in CSS (SASS/SCSS) I can get grandparent's position (left, margin-left, padding-left - something like that)? Grandparent == parent of parent :)
I need to support only modern browsers, so e.g. IE before version 9 doesn't really matters to me.
Current styles look like this:
.listing-action-button
position: static
display: flex
flex-direction: row
justify-content: flex-start
.dropdown-menu
left: 5% !important
margin-top: 1.5%
width: 80% !important
float: left !important
position: absolute !important
&:before
flex-grow: 1
align-self: flex-start
position: absolute
top: -7px
left: 9px
display: inline-block
border-right: 7px solid transparent
border-bottom: 7px solid #ccc
border-left: 7px solid transparent
border-bottom-color: rgba(0, 0, 0, 0.2)
content: ''
&:after
position: absolute
top: -6px
left: 10px
display: inline-block
border-right: 6px solid transparent
border-bottom: 6px solid #ffffff
border-left: 6px solid transparent
content: ''
It's based on standard bootstrap's dropdown-menu.
flex-* stuff isn't working, you can omit it.
HAML code for buttons group and dropdown:
<...>
.col-sm-6.col-xs-12.col-sm-pull-3
.user-listing__main{ style: "margin-top: -12px;" }
.user-listing__buttons.user-listing__buttons-tablet.btn-group.btn-group-justified
.btn-group.listing-action-button.left-button{:role => "group"}
%button.btn.btn-lg.btn-default.dropdown-toggle{ type: "button", :style => "width: 100%;", data: { toggle: "dropdown" } }
Preview
%span.caret
%ul.dropdown-menu.dropdown-menu-no-border{ role: "menu" }
.menu-arrow
%li{ class: ("disabled" if disable_edit) }
%a#user-listings__make-featured{ href: edit_listing_path(token: listing.token), role: "group", type: "button", style: "width: 100%;" }
%span.glyphicon.glyphicon-pencil
= t 'user.listings.edit'
%li
%a#user-listings__launch-facebook-campaign{ href: listing_preview_path(token: listing.token), role: 'button', target: '_blank', type: 'button', style: "width: 100%;" }
%span.glyphicon.glyphicon-eye-open
= t 'user.listings.preview'
.btn-group.listing-action-button.right-button{:role => "group"}
%button.btn.btn-lg.btn-primary.btn-inverted.dropdown-toggle{ type: "button", :style => "width: 100%;", data: { toggle: "dropdown" } }
Promote
%span.caret
%ul.dropdown-menu.dropdown-menu-no-border{ role: "menu" }
.menu-arrow
%li.mark-featured{ data: {"listing-id" => listing.id} }
%a#user-listings__make-featured{ href: "#" }
%span.glyphicon.glyphicon-star{ class: ("active" if is_featured?(listing)) }
= t 'user.listings.make_featured'
%li.disabled
%a#user-listings__launch-facebook-campaign{ href: "#" }
%span.glyphicon.glyphicon-thumbs-up
Launch Facebook Campaign
<...>

Related

How to fix fixed link taking up full width of page?

I have a fixed anchor tag linked to a heading on my website. This anchor tag has an arrow icon that is meant to be a quick way to get to the top of the page. I wanted to position it at the bottom right, but the link is taking up full width at the bottom of the page unless I use "width: fit-content;'. I tried all the display options and float only works on the icon and not the link. It makes the arrow icon float to the position I want but the link width is still taking up all the pages width. Does anyone know how I can fix the width of the link and position it to the bottom right side of the page? Thank you in advance.
NOTE-
I am using bootstrap 5
#quick-anchor-top {
font-size: 25px;
padding: 15px 25px 15px 25px;
border-radius: 50px;
color: rgb(0, 0, 0);
background-color: rgba(182, 20, 20, 0.800);
transition: all 0.4s ease;
margin: 20px;
}
#quick-anchor-top:hover {
transition-duration: 0.4s;
color: white;
background-color: rgba(0, 0, 0, 0.800);
}
<a id="quick-anchor-top" href="#header-title-1" class="fixed-bottom float-end"> <i class="fa-solid fa-arrow-up"></i></a>
You can use predefined bootstrap 5 classes to position elements on the site. Use position-fixed and bottom-0, end-0 to set your element to the bottom right corner.
Just change your classes in the anchor element like this:
<a id="quick-anchor-top" href="#header-title-1" class="position-fixed bottom-0 end-0"><i class="fa-solid fa-arrow-up"></i></a>
Here is an example: https://jsfiddle.net/5j7do14t/
More: https://getbootstrap.com/docs/5.0/utilities/position/
Always try to share your full code so others can understand better and help you in a faster way. As I can see your code is missing an important point which is the position.
Since you didn't share the full code I will try to explain to you how to do a Scroll back to top button in a very easy way.
First of all, you need the button itself, and secondly, do your style, and finally, the JavaScript code that will handle the scroll.
So let's start.
1. Create the button that will take you to the top of the page when clicked on.
<button id="quickAnchorTop" title="Go to top"><i class="fa-solid fa-arrow-up"></i></button>
For the naming, it's better to use the camelCase since you will use its ID in the CSS and in the JS code, so we can call your button (quickAnchorTop instead of quick-anchor-top).
2. Now the most important part, is the CSS to style your button.
#quickAnchorTop {
display: none; /* It should be hidden by default */
position: fixed; /* Fixed/sticky position */
bottom: 20px; /* Place the button at the bottom of the page */
right: 20px; /* Place the button 20px from the right */
z-index: 99; /* Make sure it does not overlap */
border: none; /* Remove borders */
outline: none; /* Remove outline */
background-color: blue; /* Set a background color */
color: white; /* Text color */
cursor: pointer; /* Add a mouse pointer on hover */
padding: 16px; /* Some padding */
border-radius: 10px; /* Rounded corners */
font-size: 18px; /* Font size */
}
#quickAnchorTop:hover {
background-color: #555; /* Add a dark-grey background on hover */
}
3. Finally, use JavaScript to handle the scroll and show your button.
// Get the button from the current page:
let myBackToTopButton = document.getElementById("quickAnchorTop");
// When you scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
myBackToTopButton .style.display = "block"; // To show your button
} else {
myBackToTopButton .style.display = "none"; // To hidd your button
}
}
// When you click on the button, scroll to the top of the document
function topPageFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
In the above JS code, first, you will get your button by the ID you used which is (quickAnchorTop), then you will have a function to handle the scroll and to show or hide your button.
Now make sure to update your button code and use this final form as you added the onclick event to your button:
<button onclick="topPageFunction()" id="quickAnchorTop" title="Go to top"><i class="fa-solid fa-arrow-up"></i></button>
Hopefully this will help you.

Is there a way to align the first node at the top instead of at the middle?

I am using BalkanGraph plugin and I'm trying to align the first parent node of the orgchart to the top of the svg instead of the center of it.
I tried to set a negative "margin-top" and increases the height of the whole svg, but then the click goes with it, and it doesn't work well.
My only css is this:
#tree {
width: 100%;
height: 630px;
border: 1px solid lightgray;
background-color: #fff;
}
and the things I am using in Orgchart are these:
var chart = new OrgChart(document.getElementById("tree"), {
mouseScroolBehaviour: BALKANGraph.action.zoom,
nodeMouseClickBehaviour: BALKANGraph.action.none,
scaleInitial: BALKANGraph.match.boundary,
collapse: {
level: 2,
allChildren: true
},
});
Set align option to BALKANGraph.ORIENTATION
var chart = new OrgChart(document.getElementById("tree"), {
align: BALKANGraph.ORIENTATION,
...
});

Top Nav moves up when clicking on md-menu, mdDialog buttons

I'm creating an angularjs and asp.net site that uses angular material, and when you scroll on the page and click an mdDialog or an md-menu the top nav will go up the body or "disappear". Here's the css for the top nav
.sidebar-header {
position: fixed;
width: 100%;
height: 50px;
background: #ffffff;
padding: 0 10px;
box-shadow: 0px 0px 6px 4px rgba(0, 0, 0, 0.05);
z-index: 998;}
and here's the html code when the top nav disappears
any suggestions would help, I have no idea how to fix this bug at the moment.
EDIT
The js fiddle: here
Okay so for anyone who has the same bug as me this is my fix:
in jquery:
$(document).ready(function () {
$(window).scroll(function () {
console.log($(window).scrollTop());
var topPixel = $(window).scrollTop();
var sideNavHeaderPixelCount = topPixel - topPixel;
$("<enter top nav identifier here>").css("top", sideNavHeaderPixelCount);
});
});
in css:
#menu_container_0{
top: 52px !important;
}
so I just played around with it until I Found a pattern. if the top offset of the body after clicking on an md-menu is -137.5px then you just need to get the decimal and use that as the top for your top nav (top: .5px). also the #menu_container_0 is the Id of the md-menu I used in my top nav, I didn't want it to overlap.

Absolute div overlay iframe borders?

I'm wondering if there is a way to have a div, absolutely positioned, hover over the border of the iframe that div is in. Can this be done?
My case:
I have an iframe with a list of files in it, on the right end of each file there is a button. I want to have a div-popup with some functions like a contextmenu. But because this button is at the edge of the iframe the absolutely positioned div is put behind/outside the iframe viewport. I want it to overlay in the rest of my document, outside the iframe.
​<iframe width="100" height="100">
div would be in here, say 300 x 100 px.
</iframe>
overlayed div should be visible here as well, basically the div should overlay the iframe.​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
Well, technically you can't do that. However, if you hijack the events in the iframe, you can recreate the context menu in the main window and use the relative position of the div within the iframe + the absolute position of the iframe itself.
So, to sum up, the context menu can be outside the iframe, and manipulated by the events from within the iframe.
Let me show you how it can be done. I don't have your code, so I'm just making a very crude proof of concept. :)
Example | Code
HTML
<iframe id='my_frame'></iframe>
<div id='copy_to_frame'>
<ul id='files_list'>
<li>data.dat</li>
<li>manual.html</li>
<li>readme.txt</li>
<li>model1.obj</li>
<li>human_model.obj</li>
</ul>
</div>
<div class='context_menu'>
<ul>
<li>Delete</li><li>Open</li><li>Move</li><li>Copy</li>
</ul>
</div>
Javascript
//Declare the necessary variables, good practice
var frame = $("#my_frame"),
frame_contents = frame.contents(),
frame_body = frame_contents .find("body"),
copy_list = $("#copy_to_frame"),
context_menu = $(".context_menu");
var bInside = false;
//Fill the iframe with a list
frame_body.html(copy_list.html());
copy_list.hide();
paint();
//Attach event handler for context menu popup etc.
$("#files_list li", frame_body).click(function(e){
var $this = $(this);
var rel_x = $this.position().left + $this.outerWidth() + 5,
rel_y = $this.position().top + $this.outerHeight()/2 - context_menu.outerHeight()/2 - frame_body.scrollTop(),
abs_x = frame.offset().left,
abs_y = frame.offset().top;
e.stopPropagation();
context_menu.css({
top: rel_y + abs_y,
left: rel_x + abs_x
});
//Show the context menu in this window
context_menu.show();
paint($this);
});
//Hide when clicking outside the context menu
$(document).add(frame_body).click(function(){
if(!bInside){
context_menu.hide();
paint();
}
});
//Determine if mouse is inside context menu
context_menu.mouseenter(function(){
bInside = true;
}).mouseleave(function(){
bInside = false;
});
function paint(el){
$("#files_list li", frame_body).css({
"background-color": "white",
"border": "1px solid transparent"
});
if(el){
el.css({
"background-color": "#ddecfd",
"border": "1px solid #7da2ce"
});
}
}
CSS
#my_frame{
position: absolute;
border: 1px solid gray;
width: 200px;
height: 100px;
top: 50%; left: 50%;
margin-top: -62.5px;
margin-left: -100px;
z-index: 1;
}
.context_menu{
display: none;
position: absolute;
top: 0;
left: 0;
background-color: white;
z-index: 2;
}
.context_menu ul{
border: 1px solid black;
border-right: 0;
display: inline-block;
}
.context_menu li{
display: inline-block;
border-right: 1px solid black;
padding: 2px;
text-align: center;
margin: 0px;
cursor: default;
}
.context_menu li:hover{
background-color: lightgray;
}
This is a bit of a guess based on the minimal information that was provided, but...
You can manipulate the contents of an <iframe> from within the parent document using jQuery, like so:
$('#myFrame').contents().find('a').click(function() { /*...*/ });
This allows you to detect when the user has clicked inside the <iframe>. Then you can work out where to position your overlay <div>.
Your overlay <div> will need to have position: fixed set. You can use jQuery's .offset() method to get the coordinates of the <iframe> and the link that was clicked inside the <iframe>. You can use these two values to calculate where to position the overlay <div> in the parent document. For example, to position the overlay to the left of the <iframe> and on the same vertical level as the link that was clicked you can do this:
$('#overlayDiv')
.offset({
left: $('#myFrame').offset().left - $('#overlayDiv').width(),
top: $('#myFrame').offset().top + $(this).offset().top
})
See this fiddle for a basic example of how it could work: http://jsfiddle.net/Gxd3M/2/
(Note that this assumes that the contents of the parent document and the iframe both come from the same server, i.e. they have the same origin.)

Make visible/unvisible div on click on other div

Can anybody help me, I need something like http://web-kreation.com/demos/login_form_mootools_1.2/, just mush simpler, when I click on one div ( login in this case) just to show other and if I click again to make unvisible. How to do that with Mootools if I have two divs ( div id=login and div id=vis_unvis) ?
Please refer to the following thread to learn more how toggle element’s visibility via the javascript:
Toggle Visibility - Show/Hide Anything
to replicate the effect in the example to it's most basic, look at this fiddle:
http://jsfiddle.net/dimitar/9Syj3/
(function() {
var loginOpen = false, loginForm = document.id("login").set("morph", {
link: "chain"
}).setOpacity(0);
document.id("toggler").addEvents({
click: function() {
loginForm.morph((loginOpen) ? {
marginTop: -90,
opacity: 0
} : {
marginTop: 0,
opacity: 1
});
loginOpen = !loginOpen;
this.set("text", loginOpen ? "Hide form" : "Show form");
}
});
})();
with html of:
<div id="login">
This be the login form
</div>
<div id="toggler">Show form</div>
and css of:
#login {
width: 300px;
background: #ccc;
height: 50px;
padding: 10px;
position: absolute;
margin-top: -90px;
margin-left: 300px;
z-index: 1000;
-moz-box-shadow: 0 0px 3px 3px #000;
}
resources for mootools: Fx.Morph or the element prototype .morph() allows you to animate properties of an element, in this case modifying marginTop and opacity.
mootools also supports Fx.Slide, Fx.Reveal and more as part of the mootools-more official collection of plugins.
of course to hide/show, you could just toggleClass a css class which has display: none on the element or use .show() / .hide() or .fade("in") / .fade("out") to hide via opacity.
NO end to ways to handle this. Check Fx.Move too :)