Why does the box not move freely despite using cdkDrag and cdkDragBoundary? - html

I am using "Drag and Drop" angular material.
https://material.angular.io/cdk/drag-drop/overview
When I create it with an external component as a child to the cdkDrag section it will only move up and down.
However, if I remove the boundary it will move freely.
Or, if I keep the boundary and have a generic div as a child to the cdkDrag section, then it will move freely within the boundary.
It seems the cdkDragBoundary does not like components inside. Does anyone know if this is just incompatible or am I doing something wrong?
Tabletop-creator-pagestructure
<main>
<div class="example-boundary">
<!--Creation field and actual placable objects-->
<div cdkDrag cdkDragBoundary=".example-boundary">
<!--This component being present along with the cdkDragBoundary causes problem-->
<app-tabletop-creator-placeable ></app-tabletop-creator-placeable>
</div>
</div>
</main>
.example-boundary {
position: absolute;
left: 300px;
top: 200px;
height: 600px;
width: 600px;
background: rgba(128, 128, 128, 0.351);
border: solid 3px rgb(255, 0, 0);
}
import { Component, OnInit} from '#angular/core';
import { navDataCard } from './nav-data-card';
import { CdkDragDrop} from '#angular/cdk/drag-drop';
#Component({
selector: 'app-tabletop-creator-pagestructure',
templateUrl: './tabletop-creator-pagestructure.component.html',
styleUrls: ['./tabletop-creator-pagestructure.component.scss']
})
export class TabletopCreatorPagestructureComponent implements OnInit {
data = navDataCard;
masterPlacableList = [];
topPlaceableList = ["test 1", "test 2", "test 3"];
constructor(){}
ngOnInit(){ }
}
tabletop-creator-placeable
<div class="example-placable" >
</div>
.example-placable {
width: 200px;
height: 200px;
border: solid 1px #ccc;
color: rgba(0, 0, 0, 0.87);
cursor: move;
display: inline-flex;
justify-content: center;
align-items: center;
text-align: center;
background: #fff;
border-radius: 4px;
margin-right: 25px;
position: absolute;
z-index: 1;
padding: 10px;
transition: box-shadow 200ms cubic-bezier(0, 0, 0.2, 1);
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2),
0 2px 2px 0 rgba(0, 0, 0, 0.14),
0 1px 5px 0 rgba(0, 0, 0, 0.12);
}
.example-box.free-dragging {
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12);
}
import { Component, OnInit} from '#angular/core';
#Component({
selector: 'app-tabletop-creator-placeable',
templateUrl: './tabletop-creator-placeable.component.html',
styleUrls: ['./tabletop-creator-placeable.component.css']
})
export class TabletopCreatorPlaceableComponent implements OnInit {
constructor(){
}
ngOnInit(): void {
}
}

The "cdkDrag" and "cdkDragBoundary" must be on the component selector.
<main>
<div class="example-boundary">
<!--Creation field and actual placable objects-->
<app-tabletop-creator-placeable cdkDrag cdkDragBoundary=".example-boundary">
</app-tabletop-creator-placeable>
</div>
</main>

Related

How to display a short message next to button when it's pressed?

I have the following html code:
<button onclick="copyText()">copy</button>
<script>
function copyText() {
navigator.clipboard.writeText
("Hello world");
}
</script>
How do I change the word "copy" to a checkmark and display a short message like "copied to clipboard" next to the button once it's pressed for 1 second and preferably that after 1 second the green checkmark is replaced by the text "copy" again?
Afaik, you cannot display native prompts using plain JavaScript. You would have to use something like an alert or a dialog or have a div hide and show the message.
What you need to do is structure your button in such a way that it sits next to an element with your message all aligned inline. You need CSS to accomplish this.
Then when you click on the button, the text gets copied (the code you've wrote so far) and then it should call a function which would then show the "copied" message.
You will again have to call another function to remove the message after a few seconds (or you could could leave it?) This can be done using setTimeout function.
See my example for a POC
HTH
function copyText() {
var secretKey = document.querySelector('samp.my-secret-key').innerText;
if (secretKey) {
navigator.clipboard.writeText(secretKey);
showNotification();
}
}
function showNotification() {
var notificationEl = document.querySelector('.copy-control p.notification-message');
notificationEl.classList.add('notify');
setTimeout(function() {
notificationEl.classList.remove('notify');
}, 1000);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: system-ui, -apple-system, system-ui, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.secret {
margin: 2rem auto;
display: flex;
justify-content: center;
}
.secret samp {
padding: .5rem 1rem;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: .25rem;
box-shadow: rgba(0, 0, 0, 0.02) 0 1px 3px 0;
background: #f0f0f0;
}
.copy-control {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
position: relative;
}
.notification-message {
margin: auto 1rem;
padding: .5rem 1rem;
background: black;
color: white;
border-radius: .25rem;
position: absolute;
right: 25%;
display: none;
}
.notification-message.notify {
display: block;
}
/* https://getcssscan.com/css-buttons-examples */
.copy-button {
align-items: center;
background-color: #FFFFFF;
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: .25rem;
box-shadow: rgba(0, 0, 0, 0.02) 0 1px 3px 0;
box-sizing: border-box;
color: rgba(0, 0, 0, 0.65);
cursor: pointer;
display: inline-flex;
font-size: 16px;
font-weight: 600;
justify-content: center;
line-height: 1.25;
margin: 0;
min-height: 3rem;
padding: calc(.875rem - 1px) calc(1.5rem - 1px);
position: relative;
text-decoration: none;
transition: all 250ms;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
vertical-align: baseline;
width: auto;
}
.copy-button:hover,
.copy-button:focus {
border-color: rgba(0, 0, 0, 0.15);
box-shadow: rgba(0, 0, 0, 0.1) 0 4px 12px;
color: rgba(0, 0, 0, 0.85);
}
.copy-button:hover {
transform: translateY(-1px);
}
.copy-button:active {
background-color: #F0F0F1;
border-color: rgba(0, 0, 0, 0.15);
box-shadow: rgba(0, 0, 0, 0.06) 0 2px 4px;
color: rgba(0, 0, 0, 0.85);
transform: translateY(0);
}
<div class="secret-text">
<div class="secret">
<samp class="my-secret-key">45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2</samp>
</div>
<div class="copy-control">
<button class="copy-button" onclick="copyText()">Copy Text</button>
<p class="notification-message">Copied!</p>
</div>
</div>
Not do it by functional approach...
Do it by id approach, like:-
<body>
<span id="cpnCode">Cupon_Code</span>
<button id="cpnBtn">Copy</button>
<script>
const btn = document.getElementById('cpnBtn');
const code = document.getElementById('cpnCode');
btn.addEventListener('click', () => {
// By clicking, just copy ==> this INNER HTML Content
navigator.clipboard.writeText(code.innerHTML);
btn.innerHTML = 'Copied To Clipboard';
// after clicking 3 second, reset it.
setTimeout(() => {
btn.innerHTML = 'Copy';
}, 3000);
});
</script>
</body>
Hope its will work in your case...

Space above and below HTML table varies largely from Google Chrome to Microsoft Edge

On the website https://neu.seidelpartner.ch/ I have the following HTML table which is inserted into a WordPress text box:
#kunden {
border-spacing: 30px;
}
#cell1,
#cell2,
#cell3,
#cell4,
#cell5,
#cell6,
#cell7,
#cell8 {
font-family: "Proxima Nova Bold";
font-size: 14px;
color: #857f7b;
letter-spacing: 2px;
text-align: left;
vertical-align: middle;
border: 1px solid black;
border-radius: 15px;
box-shadow: 1px 1px rgba(0, 0, 0, 0.5), 2px 2px rgba(0, 0, 0, 0.4), 3px 3px rgba(0, 0, 0, 0.3), 4px 4px rgba(0, 0, 0, 0.2), 5px 5px rgba(0, 0, 0, 0.1), 6px 6px rgba(0, 0, 0, 0.08), 7px 7px rgba(0, 0, 0, 0.06), 8px 8px rgba(0, 0, 0, 0.04);
padding-top: 60px;
padding-bottom: 60px;
padding-left: 10px;
padding-right: 10px;
width: 200px;
height: 160px;
}
<table id="kunden">
<tr id="row1">
<td id="cell1">BAHNUNTERNEHMEN</td>
<td id="cell2">BEHĂ–RDEN</td>
<td id="cell3">GENOSSENSCHAFTEN</td>
<td id="cell4">INVESTOREN</td>
</tr>
<tr id=row2>
<td id="cell5">PROJEKTENTWICKLER</td>
<td id="cell6">IMMOBILIEN-ANLAGESTIFTUNGEN</td>
<td id="cell7">KMU</td>
<td id="cell8">PLANER</td>
</tr>
</table>
Now what I observed is that the space above and below the table varies largely from Google Chrome (first image, large space) to Microsoft Edge (second image, small space). Intended from my side is how it looks in Edge.
I did some research and it seems that such spacing differences occured to many people on different elements but I was not able to solve the issue by myself.
This is also my first contact with HTML and CSS. I did not really learned these from beginning but instead just researched what I needed.
Thank you very much for any feedback.
Regards
Thanks #Pete for changing the code to a snippet, I was not aware this is possible (very cool feature). Your comment made me look deeper into the issue and I could solve it myself.
There was a pseudoelement ::before and ::after above and below the table.
It was possible to remove it with:
div.gdlr-core-pbf-column-content.clearfix.gdlr-core-js::before {
content: none;
}
div.gdlr-core-pbf-column-content.clearfix.gdlr-core-js::after {
content: none;
}
Regards

Make link open on card click

I'm a beginner and I'm making a website in HTML. It's mostly formed of cards, and some of the cards link to other pages (for example, a biography). I want some of my cards, upon click, to take me to another webpage. I have a card class:
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
border-radius: 10px;
width: 70%;
margin: auto;
}
And another class to make the card look nice:
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
So when the mouse hovers over certain cards, the card's shadow increases. These are the cards I want to have links (only two so far). Other non-link cards have a different class.
Is there a way to make the cards using the card class to link to another page when clicked? It should be if there's a click anywhere on the card, not just the text.
You do wrap the <a> tag around the card content but you need to add another class around the tag or else the areas to the sides can be clicked. This keeps it just to the card.
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
border-radius: 10px;
width: 100%;
}
.card:hover { box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); }
.control-width { width: 70%; margin: auto; }
.card2 {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
transition: 0.3s;
border-radius: 10px;
margin: auto;
width: 70%;
}
.card2:hover { box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); }
<div class="control-width">
<a href="your-link-bio">
<div class="card">
<h1>Card Header</h1>
<h3>Card Sub Header</h3>
<p>Card Description Card Description Card DescriptionCard DescriptionCard Description<p>
</div>
</a>
</div>
<a href="your-link-bio">
<div class="card2">
<h1>Card Header</h1>
<h3>Card Sub Header</h3>
<p>Card Description Card Description Card DescriptionCard DescriptionCard Description<p>
</div>
</a>

Polymer 2.0 - Trying to implement HTML5 drag and drop

I am trying to implement HTML5 drag and drop for polymer2.0 components similar to the drag and drop option as in http://jsfiddle.net/U55rc/
HTML:
<base href="https://raw-dot-custom-elements.appspot.com/PolymerElements/iron-flex-layout/v2.0.0/iron-flex-layout/">
<script src="../webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="iron-flex-layout-classes.html">
<dom-module id="demo-element">
<template>
<style include="shared-styles">
:host {
display: block;
padding: 10px;
}
.card {
margin: 24px;
padding: 16px;
color: #757575;
border-radius: 5px;
background-color: #fff;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
}
</style>
<div draggable="true" ondragstart="{{drag(event)}}" >
Input:
<input type="text"/>
</div>
<div class="card" id="div1" ondrop="{{drop(event)}}" ondragover="{{allowDrop(event)}}"></div>
</template>
<script>
Polymer({
is: 'demo-element',
allowDrop:function(ev){
ev.preventDefault();
},
drag: function(ev){
ev.dataTransfer.setData("text",ev.target.id);
},
drop:function(ev){
ev.preventDefault();
var data=ev.dataTransfer.getData("text");
console.log(ev)
ev.target.appendChild(document.getElementById(data));
}
});
</script>
<script>Polymer({is: "demo-element"});</script>
</dom-module>
<demo-element></demo-element>
JSFiddle for reference:
https://jsfiddle.net/Nagasai_Aytha/b62to481/
The key here is to use the on-<event> notation for the native HTML5 drag and drop events. Also, you don't need data binding notation for the events.
Here is your corrected markup.
HTML:
<base href="https://raw-dot-custom-elements.appspot.com/PolymerElements/iron-flex-layout/v2.0.0/iron-flex-layout/">
<script src="../webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="iron-flex-layout-classes.html">
<dom-module id="demo-element">
<template>
<style include="shared-styles">
:host {
display: block;
padding: 10px;
}
.card {
margin: 24px;
padding: 16px;
color: #757575;
border-radius: 5px;
background-color: #fff;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
}
</style>
<div id="draggedDiv" draggable="true" on-dragstart="drag" >
Input:
<input type="text"/>
</div>
<div class="card" id="div1" on-drop="drop" on-dragover="allowDrop"></div>
</template>
<script>
Polymer({
is: 'demo-element',
allowDrop:function(ev){
ev.preventDefault();
},
drag: function(ev){
ev.dataTransfer.setData("text",ev.target.id);
},
drop:function(ev){
ev.preventDefault();
var data=ev.dataTransfer.getData("text");
console.log(ev)
ev.target.appendChild(this.shadowRoot.querySelector('#' + data));
}
});
</script>
<script>Polymer({is: "demo-element"});</script>
</dom-module>
<demo-element></demo-element>
For Polymer 2.0 change this.$$ to this.shadowRoot.querySelector:
drop (ev){
ev.preventDefault();
var data=ev.dataTransfer.getData("text");
ev.target.appendChild(this.shadowRoot.querySelector('#' + data));
}

How to enable a css tag only during hover?

I'm creating a badge notification using css, but I want to show it only during hovering of the outer element. It that possible?
<img src..><span class="badge">5</span></img>
The badge is created as follows from css:
/*#see http://cssdeck.com/labs/menu-with-notification-badges*/
img .badge {
display: block;
position: absolute;
top: -12px;
right: 3px;
line-height: 16px;
height: 16px;
padding: 0 5px;
font-family: Arial, sans-serif;
color: white;
text-shadow: 0 1px rgba(0, 0, 0, 0.25);
border: 1px solid;
border-radius: 10px;
-webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.3), 0 1px 1px rgba(0, 0, 0, 0.08);
box-shadow: inset 0 1px rgba(255, 255, 255, 0.3), 0 1px 1px rgba(0, 0, 0, 0.08);
background: #67c1ef;
border-color: #30aae9;
background-image: -webkit-linear-gradient(top, #acddf6, #67c1ef);
background-image: -moz-linear-gradient(top, #acddf6, #67c1ef);
background-image: -o-linear-gradient(top, #acddf6, #67c1ef);
background-image: linear-gradient(to bottom, #acddf6, #67c1ef);
}
Question: how can I show the badge only when hovering the specific img where the badge class is applied at?
For starters the img element is a standalone self-closing element and doesn't doesn't allow children elements. With that markup most browsers will convert your code to:
<img src... />
<span class="badge">5</span>
Some may also treat that </img> tag as a second img element.
Separating the img element from the span as shown above is what we firstly want to do anyway, so adjust your HTML to reflect that. Then we can implement the adjacent sibling combinator (+) so select our span element when the img element is being overed over:
img:hover + .badge {
...
}
Remember to hide the .badge element by default.
.badge {
display: none;
}
img:hover + .badge {
display: block;
}
<img src="http://placehold.it/320x140&text=Hover%20Here" />
<span class="badge">Hello, world!</span>
jQuery .hover() function can also do this, remember $(".badge").hide() when load the page.