Im trying to override the styling when an element is selected.
This works on Safari and Firefox. It does not work on Chrome 38.
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../core-selector/core-selector.html">
<polymer-element name="my-selector" extends="core-selector">
<template>
<style>
:host::shadow .item.core-selected{
background: blue;
}
</style>
<shadow></shadow>
</template>
<script>
Polymer('my-selector');
</script>
</polymer-element>
Example:
<my-selector>
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</my-selector>
Try:
::content .item.core-selected {
...
}
:host::shadow try to picks elements out of the host's shadow dom. In this case, this is not where the elements are. The <div class="item"> elements are still going through an insertion point and are part of light dom. They need to be styled with ::content.
<script src="http://www.polymer-project.org/platform.js"></script>
<link rel="import" href="http://www.polymer-project.org/components/core-selector/core-selector.html">
<polymer-element name="my-selector" extends="core-selector">
<template>
<style>
::content .item.core-selected {
background: blue;
color: white;
}
</style>
<shadow></shadow>
</template>
<script>
Polymer('my-selector');
</script>
</polymer-element>
<my-selector selected="0">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
</my-selector>
Related
This is my markup:
<div class="comment">Comment author 1</div>
This is what I want:
<div class="comment">Comment author 1</div>
Is there a way to do this with jQuery? If so please help me, thank you everyone!
Simplest is use text(function) so you isolate specific instances.
This will loop over all elements with that class and overwrite any elements inside each one with just the text
$('.comment').text((_, txt) => txt);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="comment">Comment author 1</div>
<div class="comment">Another author </div>
Try this:
$(document).ready(function(){
var txt = $('.comment a').text();
$('.comment').html(txt);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="comment">Comment author 1</div>
Updated to loop through all .comment divs
$(document).ready(function(){
$('.comment').each(function(){
var txt = $(this).find('a').text();
$(this).html(txt);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="comment">Comment author 1</div>
<div class="comment">Comment author 2</div>
<div class="comment">Comment author 3</div>
This question already has answers here:
CSS selector for first element with class
(23 answers)
Closed 6 years ago.
It works perfectly if I remove the first div.
But if I have the first div without the class, it doesn't work correctly.
Test 1 should be blue and the next test should be red, and so on.
When I have another div, it doesn't work correctly. How do I solve this issue?
.el:nth-of-type(odd) {
background-color: blue;
}
.el:nth-of-type(even) {
background-color: red;
}
<div id="content">
<div>nothing</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
</div>
In your particular case, you could simply reverse the CSS rules for odd and even nth-of-type (see snippet). The nth-of-type refers to the tag, i.e. the divelement, not the class, therefore also counting the first div which doesn't have a class.
Since your CSS rule selectors combine the class with the nth-of-type, the first div isn't affected, since it doesn't have a class, yet the counting for odd or even starts at the first div.
.el:nth-of-type(odd) {
background-color: red;
}
.el:nth-of-type(even) {
background-color: blue;
}
<div id="content">
<div>nothing</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
</div>
How do I solve this issue?
Change the first div to another element, so it gets skipped by nth-of-type.
.el:nth-of-type(odd) {
background-color: blue;
}
.el:nth-of-type(even) {
background-color: red;
}
<div id="content">
<span>nothing</span>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
<div class="el">Test 1</div>
</div>
Most of my code is from the website: http://www.w3schools.com/html/html5_draganddrop.asp.
I've added the snippets of my .css and .html code. I'd like to be able to drag either of the two .gif images into the "first" box, though I'm not able to do this (in CoffeeCup Free HTML Editor). Perhaps I'm not using IDs correctly?
div.content {
height:70px;
width:350px;
border:1px solid #aaaaaa;
float:left;
margin:5px;
}
div#first:{
}
div#second:{
}
div#third{
}
div#fourth{
}
<!DOCTYPE HTML>
<html>
<head>
<link href="style1.css" rel="stylesheet" type="text/css"/>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>
<div class="content" id="first">Block 1</div>
<div class="content" id="second">Block 2</div>
<div class="content" id="third">Block 3</div>
<div class="content" id = "fourth">Block 4</div>
<div id="first" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br>
<img id="drag1" src="squig.gif" draggable="true" ondragstart="drag(event)" width="336" height="69">
<img id="drag2" src="squig2.gif" draggable="true" ondragstart="drag(event)" width="336" height="69">
</body>
</html>
I have two Solutions for you, choose which you need.
1. You need this in your HTML-Code:
<div class="content" id="first" ondrop="drop(event)" ondragover="allowDrop(event)">Block 1</div>
<div class="content" id="second">Block 2</div>
<div class="content" id="third">Block 3</div>
<div class="content" id = "fourth">Block 4</div>
You have to delete this line:
<div id="first" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
2.Another Solution without changing nothing in your HTML-Code.
Add this in your CSS-Code:
#first {
height:70px;
width:350px;
border:1px solid #aaaaaa;
float:left;
margin:5px;
}
I've seen both this and this question, but they're both Javascript-oriented.
I'm looking to select the only div which has no ID or Class.
Example:
<body>
<div class="X" ... />
<div class="Z" ... />
...
<div class="Y" ... />
<div>Select me</div>
<div id="footnote" ... /> <!-- Notice I have no class. -->
...
</body>
There will only ever be one div with no class and id.
The div may change places, or be not present.
No Javascript. However any language which can compile to CSS like SASS is fine.
The divs in question will only ever be directly under <body>.
I may not always know what classes or IDs there will be.
You can use the :not:
CSS:
div:not([class]):not([id]) {
height: 200px;
width: 200px;
background-color: red;
}
HTML:
<div></div>
<div class="shikaka"></div>
<div id="shikaka2"></div>
http://jsfiddle.net/qcq0qedj/
You can do:
body > div:not([class]):not([id]) { }
JSFiddle
Ah... the beauty of :not. (AKA - not:ugly)
div:not([class]):not([id]) {
color: #fff;
padding: 2px 4px;
background: red;
}
<body>
<div class="X">...</div>
<div>Select me</div>
<div class="Z">...</div>
<div class="Y">...</div>
<div>Select me, too!</div>
<div id="footnote">...</div>
</body>
http://jsfiddle.net/stevenventimiglia/53Lqekod/
I try to learn Polymer and until now, I think I am in a good way. However, I found a framework which has the same Google Material Design and I am trying to implement on of their tutorials to Polymer code.
The framework is: http://materializecss.com/ and the component I try to implement is the Card reveal
I have the code of how it should be on materializecss
<div class="col l4 m4 s1">
<div class="card">
<div class="card-image waves-effect waves-block waves-light">
<img class="responsive-img" src="/static/images/myimage.png">
</div>
<div class="card-content">
<span class="card-title activator grey-text text-darken-4">Training Estimation <i class="mdi-navigation-more-vert right"></i></span>
<p>This is a link</p>
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">Card Title <i class="mdi-navigation-close right"></i></span>
<p>Here is some more information about this product that is only revealed once clicked on.</p>
</div>
</div>
</div>
However, I don't know how to start and rewrite the same feature on Polymer directly.
Can be done using polymer core-animated-pages.
Demo and the code: https://github.com/DinethH/card-reveal
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-shadow/paper-shadow.html">
<link rel="import" href="../../bower_components/font-roboto/roboto.html">
<link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../bower_components/core-animated-pages/core-animated-pages.html">
<link rel="import" href="../../bower_components/core-animated-pages/transitions/slide-up.html">
<link rel="import" href="../../bower_components/core-animated-pages/transitions/slide-down.html">
<link rel="import" href="../../bower_components/core-animated-pages/transitions/cross-fade.html">
<polymer-element name="card-reveal" center layout>
<template>
<style>
paper-shadow,
core-animated-pages section {
height: 500px;
width: 500px;
}
core-animated-pages section {
overflow: hidden;
}
h3 {
font-weight: 300;
font-size: 26px;
margin: 0;
padding: 0;
padding-bottom: 10px;
}
.card-content,
.card-reveal {
padding: 20px;
background: white;
height: 500px;
}
a {
color: orange;
text-transform: uppercase;
}
</style>
<paper-shadow>
<core-animated-pages transitions="slide-up" selected="{{selected}}">
<section>
<div>
<img src="http://lorempixel.com/500/380/">
<div>
<div class="card-content">
<div layout horizontal>
<div flex>
<h3>{{item.title}}</h3>
</div>
<div>
<paper-icon-button on-tap="{{reveal}}" icon="more-vert"></paper-icon-button>
</div>
</div>
<a>This is a link</a>
</div>
</div>
</div>
</section>
<section>
<div class="card-reveal" slide-up cross-fade>
<div layout horizontal>
<div flex>
<h3>{{item.title}}</h3>
</div>
<div>
<paper-icon-button on-tap="{{reveal}}" icon="close"></paper-icon-button>
</div>
</div>
<div>
{{item.more}}
</div>
</div>
</section>
</core-animated-pages>
</paper-shadow>
</template>
<script>
Polymer({
created: function () {
this.item = {
title: "Card Title",
more: "Here is some more information about this product that is only revealed once clicked on."
};
},
reveal: function () {
if (this.selected == 0) {
this.selected = 1;
} else {
this.selected = 0;
}
}
});
</script>
</polymer-element>