Is it possible to make a squiggly line? - javascript

If I wanted to make a horizontal line, I would do this:
<style>
#line{
width:100px;
height:1px;
background-color:#000;
}
</style>
<body>
<div id="line"></div>
If I wanted to make a vertical line, I would do this:
#line{
width:1px;
height:100px;
background-color:#000;
}
</style>
<body>
<div id="line"></div>
A curved line is trickier, but possible using border-radius and wrapping the element:
<style>
.curve{
width:100px;
height:500px;
border:1px #000 solid;
border-radius:100%;
}
#wrapper{
overflow:hidden;
width:40px;
height:200px;
}
</style>
<body>
<div id="wrapper">
<div class="curve"></div>
</div>
</body>
But I cannot even fathom how I could generate squiggly lines! Is this even remotely possible using only css (and javascript since it does seem that it will be necessary to be able to more easily generate them).
note:
As expected, given your answers there is no way to do this in sole css...javascript and jquery are 100 percent okay for your answer...NO IMAGES CAN BE USED

This question is fairly old, but I found a way to do with without Javascript, repetitive CSS or images.
With background-size you can repeat a pattern, which can be created with pure CSS using linear-gradient or radial-gradient.
I put a bunch of examples here: http://jsbin.com/hotugu/edit?html,css,output
The basic gist is:
.holder {
/* Clip edges, as some of the lines don't terminate nicely. */
overflow: hidden;
position: relative;
width: 200px;
height: 50px;
}
.ellipse {
position: absolute;
background: radial-gradient(ellipse, transparent, transparent 7px, black 7px, black 10px, transparent 11px);
background-size: 36px 40px;
width: 200px;
height: 20px;
}
.ellipse2 {
top: 20px;
left: 18px;
background-position: 0px -20px;
}
<div class="holder">
<div class="ellipse"></div>
<div class="ellipse ellipse2"></div>
</div>
You can produce some convincing squiggly lines with some modifications:
.holder {
position: relative;
width: 200px;
height: 50px;
top: 25px;
}
.tinyLine {
position: absolute;
/* Cuts off the bottom half of the pattern */
height: 20px;
/* For better cross browser consistency, make it larger with width. */
width: 1000%;
/* And then scale it back down with scale, recentering with translateX. */
transform: translateX(-45%) scale(0.1);
}
.tinyLine1 {
background: linear-gradient(45deg, transparent, transparent 49%, red 49%, transparent 51%);
}
.tinyLine2 {
background: linear-gradient(-45deg, transparent, transparent 49%, red 49%, transparent 51%);
}
.tinyLine {
/* Must be after background definition. */
background-size: 40px 40px;
}
<div class="holder">
<div class="tinyLine tinyLine1"></div>
<div class="tinyLine tinyLine2"></div>
</div>
The browser support is okay (http://caniuse.com/#feat=css-gradients), IE 10 will probably work, however things break down at small scales in different browsers. If you want it to work on really small scales consistently you may want to make the line on a larger scale and then scale it down with transform: scale(x);.
It should also be very fast, linear-gradients are rendered on the GPU in chrome.

EDIT: Given the requirement of no images/data uri.
You can also cram a bunch of border-radius elements together, alternating with top/bottom or left/right edges disabled. I've generalized this into a function that appends them to an element.
Javascript, where squigglecount is the number of "squiggles". You could generalize that to an actual width if you so desired.
http://jsfiddle.net/V7QEJ/1/
function makeLine(id, squiggleCount) {
var curve;
var lineEl = $(id);
for (var i = 0; i < squiggleCount; i++) {
curve = document.createElement('div');
curve.className = 'curve-1';
lineEl.append(curve);
curve = document.createElement('div');
curve.className = 'curve-2';
lineEl.append(curve);
}
}
$(document).ready(function(){
makeLine('#line', 16);
});
.curve-1,
.curve-2 {
display: inline-block;
border: solid 1px #f00;
border-radius: 50px;
height: 20px;
width: 20px;
}
.curve-1 {
border-bottom: none;
border-left: none;
border-right: none;
}
.curve-2 {
border-top: none;
border-left: none;
border-right: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="line">
</div>
Old (with images):
There's already a bunch of answers, but here's an easy way to do a vertical squiggly line, similar to Lawson's answer.
Basically, you use background-image and a data-uri of a squiggly line to do it. I probably wouldn't use this for anything but it's an interesting thought exercise. There are a bunch of data uri generators that you can use online to change your own images.
http://jsfiddle.net/zadP7/
.aux{
display: inline-block;
vertical-align: top;
}
.line{
display: inline-block;
height: 400px;
width: 10px;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAoCAYAAADHVmuAAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QYYFSs0NbBHxgAAAB1pVFh0Q29tbWVudAAAAAA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AAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACelxA/rjIgrgAAAABJRU5ErkJggg==);
}
<div class="aux">Stuff</div>
<div class="line"></div>
<div class="aux">More Stuff</div>

Pure CSS solution:
We can use the sin wave character '∿' character and then
Set a negative value for letter-spacing
FIDDLE
Just for fun we can use different characters to get other squiggles:
FIDDLE #2
div {
font-size: 50px;
font-family: verdana;
}
.tilde {
letter-spacing: -19px;
}
.ohm {
letter-spacing: -6px;
}
.ac {
letter-spacing: -25px;
}
.acd {
letter-spacing: -11px;
}
.curlyv {
letter-spacing: -12px;
}
.frown {
letter-spacing: -13px;
}
<div class="acd">∿∿∿∿∿∿∿∿∿∿∿∿∿∿∿</div>
<div class="tilde">˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜˜</div>
<div class="curlyv">⋎⋎⋎⋎⋎⋎⋎⋎⋎⋎⋎⋎⋎⋎⋎⋎</div>
<div class="frown">⌢⌢⌢⌢⌢⌢⌢⌢⌢⌢⌢⌢⌢⌢⌢⌢⌢</div>
<div class="ac">∾∾∾∾∾∾∾∾∾∾∾∾∾∾∾∾∾∾∾∾∾</div>
<div class="ohm">ΩΩΩΩΩΩΩΩΩΩ</div>

If you want the underline of some text to be a squiggly line, you can use the following css:
span {
text-decoration-line: underline;
text-decoration-style: wavy;
text-decoration-color: red;
}
<span>Example text here</span>
Source: https://developer.mozilla.org/en/docs/Web/CSS/text-decoration-line#example

if you are not looking for something really neat, but just for the fun of it, play with multiple box-shadow:
http://codepen.io/gcyrillus/pen/mfGdp or http://codepen.io/gcyrillus/pen/xhqFu
.curve{
margin:3em 0;
width:100px;
height:150px;
border-radius:50%;
box-shadow:
0px 2px 1px -1px,
400px 0px 0px 0px white,
400px 2px 1px -1px ,
300px 0px 0px 0px white,
300px -2px 1px -1px,
600px 0px 0px 0px white,
600px 2px 1px -1px ,
500px 0px 0px 0px white,
500px -2px 1px -1px,
800px 0px 0px 0px white,
800px 2px 1px -1px ,
700px 0px 0px 0px white,
700px -2px 1px -1px,
1000px 0px 0px 0px white,
1000px 2px 1px -1px ,
900px 0px 0px 0px white,
900px -2px 1px -1px,
1200px 0px 0px 0px white,
1200px 2px 1px -1px ,
1100px 0px 0px 0px white,
1100px -2px 1px -1px,
1400px 0px 0px 0px white,
1400px 2px 1px -1px ,
1300px 0px 0px 0px white,
1300px -2px 1px -1px,
1600px 0px 0px 0px white,
1600px 2px 1px -1px ,
1500px 0px 0px 0px white,
1500px -2px 1px -1px;
position:relative;
}
.curve:before,.curve:after {
content:'';
position:absolute;
height:100%;
width:100%;
border-radius:100%;
box-shadow:inherit;
}
.curve:before {
left:100%;
transform:rotate(180deg);
}
.curve:after {
left:200%;
}

﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏﹏
& #65103 ; (wavy low line)
I hope this is not too much off topic - here is how to use those squiggly lines to underline some text (should be a common use case.)
method 1 (snatched from Wulf answering a related question)
<span style="border-bottom: 1px dotted #ff0000;padding:1px">
<span style="border-bottom: 1px dotted #ff0000;">
foobar
</span>
</span>
(not really a squiggly line but a collection of dots, but looks OK and is beautifully simple.)
method 2 (inspired by DanieldD)
using & #65103 ; (wavy low line) unicode character and absolute / relative positioning to put that character underneath some text. Here is a fiddle
here is "the meat" of the code for the positioning
function performUnderWavyLowLineazation(contentElt){
var wavyFontSize = 40;
var width = contentElt.width();
contentElt.addClass("underWavyLowLined");
replaceSpaceByNonBreakingSpace(contentElt);
var sp = "<span/>";
var wrapper = contentElt.wrap(sp).parent();
wrapper.addClass("wavyParent");
var underlining = jQuery(sp, {"class" : "wavyLowLine"}).prependTo(wrapper);
var ghost;
var invisibleGhostThatTakesUpTheSpaceThatUnderWavyLowLinedElementShouldTakeButDoesntDueToBeingAbsolute
= ghost = jQuery(sp, {"class": "invisibleUnderWavyLowLined"}).appendTo(wrapper);
ghost.html(contentElt.html());
ghost.find("*").removeAttr("id");
replaceSpaceByNonBreakingSpace(ghost);
var numWavyChars = Math.floor(0.1 + width/wavyFontSize);
innerUnderLine = jQuery(sp, {"class": "innerWaveLine"}).appendTo(underlining);
innerUnderLine.html("﹏".repeat(numWavyChars));
var lineLength = wavyFontSize * numWavyChars;
var defect = width - lineLength;
innerUnderLine.css("left", defect/2);
var wavyGroup = jQuery(sp, {"class" : "wavyGroup"}).prependTo(wrapper);
underlining.appendTo(wavyGroup);
contentElt.appendTo(wavyGroup);
}

Thank #yeerk for such a wonderful solution!
But I would like to suggest some improvements to his first variants — to those of waves what seem to be more triangular. I would suggest to use :before and :after pseudo-elements instead of hard-coded enclosed divs.
It may look like this (html):
<div class="triangly-line"></div>
— where triangly-line is a target decorated element (not "waved" but "triangled").
Corresponding styles (using LESS notation) will look like this:
#line-width: 300px;
#triangled-size: 6px;
#triangly-color: red;
#double-triangled-size: (#triangled-size * 2 - 1px);
.linear-gradient (#gradient) {
background: -webkit-linear-gradient(#gradient);
background: -o-linear-gradient(#gradient);
background: linear-gradient(#gradient);
}
.triangly-gradient (#sign, #color) {
.linear-gradient(~"#{sign}45deg, transparent, transparent 49%, #{color} 49%, transparent 51%");
}
.triangly-line {
overflow: hidden;
position: relative;
height: #triangled-size;
&:before {
.triangly-gradient("", #triangly-color);
}
&:after {
.triangly-gradient("-", #triangly-color);
}
&:before,
&:after {
content: "";
display: block;
position: absolute;
width: #line-width;
height: #triangled-size;
background-size: #double-triangled-size #double-triangled-size !important;
}
}
Resulted CSS (using specified above parameters):
.triangly-line {
overflow: hidden;
position: relative;
height: 6px;
}
.triangly-line:before {
background: -webkit-linear-gradient(45deg, transparent, transparent 49%, red 49%, transparent 51%);
background: -o-linear-gradient(45deg, transparent, transparent 49%, red 49%, transparent 51%);
background: linear-gradient(45deg, transparent, transparent 49%, red 49%, transparent 51%);
}
.triangly-line:after {
background: -webkit-linear-gradient(-45deg, transparent, transparent 49%, red 49%, transparent 51%);
background: -o-linear-gradient(-45deg, transparent, transparent 49%, red 49%, transparent 51%);
background: linear-gradient(-45deg, transparent, transparent 49%, red 49%, transparent 51%);
}
.triangly-line:before,
.triangly-line:after {
content: "";
display: block;
position: absolute;
width: 300px;
height: 6px;
background-size: 11px 11px !important;
}

Before there was HTML5 and Canvas, there was JavaScript VectorGraphics. You may want to give it a try if you want to draw Circles, Ellipses etc. etc. in pure HTML.

Instead of using the border, use a tiled background image.
I do not think there is a solution that get's away without using a graphics file and that also works in all browsers.
If you are brave you can try this:http://www.html5canvastutorials.com/tutorials/html5-canvas-arcs/
It allows to draw on the canvas in HTML5, but it would not work on older browsers.
if you can add a lot of html you can use this:
http://jsfiddle.net/QsM4J/
HTML:
<body>
<p>
before
</p>
<div id="sqig">
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
<div class="topsqig"><div></div></div>
<div class="bottomsqig"><div></div></div>
</div>
<p>
after
</p>
</body>
CSS:
#sqig{
position:relative;
width:400px;
height:6px;
}
#sqig div{
position:relative;
width:6px;
height:6px;
display: inline-block;
margin:0 0 0 -4px;
padding:0;
}
#sqig .topsqig div{
border-radius: 3px;
top:1px;
border-top: 1px solid #000;
}
#sqig .bottomsqig div{
border-radius: 3px;
top:-1px;
border-bottom: 1px solid #000;
}

Here is a SASS wave line generator based on the answer from #yeerk. If you want triangles, use the generator above by #lilliputten.
$waveHeight: 40px;
$waveLength: 70px;
$waveRadius: 13px; // adjust depending on length
$waveThickness: 8px;
#mixin waveSide() {
position: absolute;
background: radial-gradient(ellipse, transparent, transparent $waveRadius, black $waveRadius, black #{$waveRadius + $waveThickness}, transparent #{$waveRadius + $waveThickness});
background-size: #{$waveLength} #{$waveHeight * 2};
height: $waveHeight;
}
.wavy {
width: 400px; // give the wave element a length here
#include waveSide;
&::before {
$waveOffset: $waveLength / 2;
#include waveSide;
content: '';
width: calc(100% - #{$waveOffset});
top: $waveHeight;
left: $waveOffset;
background-position: 0px -#{$waveHeight};
}
}

I found a slighty nicer way to achieve trangle squiggly lines in CSS without halving heights or applying tricks that don't work well across browsers.
I tried #yeerk's solution but it only works well in Chrome. The lines had artifacts on Safari and Firefox.
Firefox
Safari
This solution is a variation of #liliputen's solution, however it improves on ease of flexibility.
You can change the line's size easily from the background-size property.
.squiggly {
position: relative;
height: 10px;
width: 100%;
}
.squiggly::after,
.squiggly::before {
height: inherit;
width: inherit;
background-size: 12px 100%; /* Change this to adjust the size of the squiggly line. */
content: "";
position: absolute;
}
.squiggly::before {
top: -2px;
background-image: linear-gradient(45deg, red 35%, transparent 0),
linear-gradient(-45deg, red 35%, transparent 0);
}
.squiggly::after {
top: 0px;
background-image: linear-gradient(45deg, white 35%, transparent 0),
linear-gradient(-45deg, white 35%, transparent 0);
}
<div class="squiggly"></div>
You can also find it here on JS Fiddle.

If you are using Javascript, this can be easily achieved using a sine wave - this is how programming languages have achieved controllable squiggly lines for decades! You should be able to find plenty of examples out there, but essentially you just do loop with an incrementing x value and apply the sine function sin(). This used to be cool for doing screen-savers in the 90s and animating them, etc.

Related

How to animate containers using JS

I have a container that holds images of work. How do I use JS to bring up a button and some extra info on the image when I hover over it.
I tried using CSS and the hover tag but it would apply the effect I needed below the image, Not on top of it. The page is HTML, with CSS and the only JS code will be for this effect. The site is for my portfolio so each image is different but the class is all the same. The code below is what the original code is without the effect. If you could show me how to correctly do this I would really appreciate it, thanks.
I don't have the code I tried using before as I tried that many it felt pointless. I'll edit the question when I attempt another solution and post either the failed attempt or the successful attempt.
Here is a JSFiddle link
Welcome to StackOverflow!
So it seems like you only wanted to use the JavaScript as a fallback since you couldn't get the CSS to work. I would recommend against this as you may run into various compatibility issues between browsers and browser versions if you're not using a Polyfill.
To do this in CSS, I would recommend creating a container for each work item. In my example, I created a .item class and used that to contain the image and text. Once that was created, we can now look for a :hover on each .item and use that to modify the elements inside of our .item.
Let me know if you need me to clarify any part of my explanation or if I misunderstood any parts of your question.
.item {
width: 50%;
margin: 0 auto;
}
.wrapper {
text-align: center;
}
.work_container {
display: inline-block;
position: relative;
/* width: 1200px; Removed for testing */
height: 100%;
text-align: center;
}
.work_title {
display: inline-block;
width: 100%; /* Changed for testing */
height: 30px;
position: relative;
top: 30px;
font-family: 'Montserrat', sans-serif;
font-size: 28px;
font-weight: 500;
color: black; /* Changed for testing */
/* Used for the animation */
opacity: 0;
transition: 0.3s;
}
.work-hub {
width: 100%; /* Added for testing */
position: relative;
text-align: center;
margin-top: 50px;
margin-bottom: 50px;
-webkit-box-shadow: 0px 20px 36px -3px rgba(0, 0, 0, 0.34);
-moz-box-shadow: 0px 20px 36px -3px rgba(0, 0, 0, 0.34);
box-shadow: 0px 20px 36px -3px rgba(0, 0, 0, 0.34);
}
/* Run the hover on the container */
.item:hover .work_title {
opacity: 1;
}
<main>
<div class="wrapper">
<div class="work_container">
<div class="item">
<h1 class="work_title">Logo Visualisation</h1>
<img class="work-hub" src="https://images-na.ssl-images-amazon.com/images/I/51IwmuOPQyL._SL1052_.jpg" alt="Work Image">
</div>
<div class="item">
<h1 class="work_title">Rock Banner</h1>
<img class="work-hub" src="https://images-na.ssl-images-amazon.com/images/I/51IwmuOPQyL._SL1052_.jpg" alt="Work Image">
</div>
<div class="item">
<h1 class="work_title">Forest Fire</h1>
<img class="work-hub" src="https://images-na.ssl-images-amazon.com/images/I/51IwmuOPQyL._SL1052_.jpg" alt="Work Image">
</div>
<div class="item">
<h1 class="work_title">Beach Body</h1>
<img class="work-hub" src="https://images-na.ssl-images-amazon.com/images/I/51IwmuOPQyL._SL1052_.jpg" alt="Work Image">
</div>
</div>
</div>
</main>

load div diagonally on scrolling

.main_div2_sub {
padding-left: 0;
width: 0;
height: 0;
border-style: solid;
border-width: 0 0 80px 100vw;
border-color: transparent transparent #56c3b0 transparent;
}
.top_div
{
height:100px;
}
.bottomdiv
{
height:100px;
background-color:#56c3b0;
}
<div class="top_div"></div>
<div class="div2">
<div class="main_div2_sub">
</div>
<div class="bottomdiv"></div>
</div>
I want to load div2 diagonally(wiper animation) on scrolling how can I do that.
unfortunately searching for it hasn't given me much results.

jQuery div hover slide effect

I have this div here:
<div style="
width: 259px;
height: 201px;
background-color: #282c2f;
box-shadow: 0px 8px 10px #000;
border-radius: 10px;
border: 2px solid #282c2f;">SHOP</div>
That when a user hovers, the grey box needs to slide down into a teal box. So the new color is shown, and a link is ready to be clicked.
It should slide into:
<div style="
width: 259px;
height: 201px;
background-color: #00e7b4;
box-shadow: 0px 8px 10px #000;
border-radius: 10px;
border: 2px solid #282c2f;"><a href="shop.htm">SHOP</div>
Is there anything where I can see an effect similar to this working? Perhaps plugin suggestions? Not sure how to start on this.
Very similar to what I am looking for, except the black disappears as it slides out of the div: http://jsfiddle.net/bUcZg/
I believe this is what you're trying to accomplish. I haven't tested for browser compatibility, so you may want to do that and play around with it.
Basically just involved adding an additional div, and using slideDown on the new div.
<div id="newTarget" style="display:none;width:100px; height:100px; background-color:teal; border: teal solid 1px; position:absolute;">
<a id="newTargetLink" href="#">Link</a>
</div>
http://jsfiddle.net/bUcZg/22/
You can chain animations in jQuery. If I understand you correctly you could do it like this:
trigger.hover(function() {
target.animate({top: 0}).animate({opacity : 0});
}
Example: http://jsfiddle.net/bUcZg/21/

Styling a class after added via jQuery

I am trying to style a button depending on whatever it was clicked or not. To be more precise, I have a button which in the normal state and hover state has some CSS styling ( not important ), and when it's clicked, a certain class is added to it ( in my case selected ).
And if that class it's added another CSS style should be applied to it. Well, I have the JavaScript ( it's more jQuery ) which adds the class I need to the button, and the CSS style. But it seems like nothing is happening.
I will paste some of the code so you can see what I'm using for that, but I'll paste the link to the actual working thing.
/*
The jQuery used for adding the class
I'm using log() to check if anything happens, but only till I make it work
*/
var iqns = $(this).find('.iqn');
$(iqns).each(function() {
var iqn = $(this).parent();
$(iqn).on('click', function() {
if($(this).hasClass('.selected')) {
log('Rmoved / Added Class');
$(this).removeClass('.selected');
$(this).addClass('.selected');
} else {
log('Added Class');
$(this).addClass('.selected');
}
});
});
<!-- A part of the HTML mockup so you can see what's the class I'm looking for -->
<div id="509247" class="product-wrapper">
<div class="product">
<div class="description">
<div class="thumb">
<i class="icon">
<img src="http://0.s3.envato.com/files/5880011/Pool.jpg" alt="Thumb">
<span class="preview" data-image-link="http://2.s3.envato.com/files/5880010/Pool.jpg">
<img src="assets/gfx/zoom-icon.png" alt="Zoom">
</span>
</i>
</div>
<div class="info">
<div class="sales">
<div class="icon">
<img src="assets/gfx/sales-icon.png" alt="Sales Icon">
</div>
<div class="text">
<p>2</p>
</div>
</div>
<div class="rating">
<img src="assets/gfx/empty-star.png" alt="Rating">
<img src="assets/gfx/empty-star.png" alt="Rating">
<img src="assets/gfx/empty-star.png" alt="Rating">
<img src="assets/gfx/empty-star.png" alt="Rating">
<img src="assets/gfx/empty-star.png" alt="Rating">
</div>
</div>
</div>
<div class="purchase">
<div class="info">
<i class="icon">
<i class="iqn"></i>
<span class="tooltip">$ 7</span>
</i>
</div>
<div class="proceed">
<a class="button" href="http://photodune.net/item/pool/509247">Purchase</a>
</div>
</div>
</div>
</div>
/*
Some of the CSS ( it is actually LESS )
*/
.icon {
position: relative;
margin: 0px auto;
margin-top: 12px;
margin-left: 12.5px;
display: block;
cursor: pointer;
.dimensions(35px, 35px);
.background(#noise-monochrome, #323b43, #242a30);
.border(1px, 1px, 1px, 1px, #242a30);
.border-radius(25px, 25px, 25px, 25px);
.shadow-normal-inset(0px 1px 2px rgba(000, 000, 000, 0.5), 1px 1px 1px rgba(255, 255, 255, 0.1) inset);
.text-format(center, none, none, inherit, none, normal, normal, normal, #ffffff);
.iqn {
position: relative;
margin: 0px auto;
display: block;
.dimensions(35px, 35px);
.background(url(../gfx/price-icon.png), 0px 0px, no-repeat);
}
.tooltip {
position: absolute;
display: block;
top: 0px;
left: 40px;
pointer-events: none;
.dimensions(50px, 35px);
.background(#1f252a);
.border(1px, 1px, 1px, 1px, #1a1f23);
.border-radius(5px, 5px, 5px, 5px);
.font-format(Arial, 16px, normal, bold, normal);
.text-format(center, none, none, inherit, none, normal, 35px, normal, #03b0f0);
.opacity(0);
.transition (all, 0.25s, ease-in-out);
}
.tooltip:before {
position: absolute;
top: 7.5px;
left: -10px;
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right: 10px solid #1f252a;
content: '';
z-index: 5;
}
.tooltip:after {
position: absolute;
top: 6.5px;
left: -11px;
width: 0;
height: 0;
border-top: 11px solid transparent;
border-bottom: 11px solid transparent;
border-right: 11px solid #1a1f23;
content: '';
z-index: 0;
}
&:hover {
.background(#noise-monochrome, #3c4750, #2c353c);
.iqn {
.background(url(../gfx/price-icon.png), 0px -35px, no-repeat);
}
}
&:hover > .tooltip {
.opacity(1);
left: 50px;
.transition(all, 0.25s, ease-in-out);
}
&.selected {
.background(#noise-monochrome, #2c353c, #3c4750);
.shadow-normal-inset(0px 1px 2px rgba(000, 000, 000, 0.5) inset, 1px 1px 1px rgba(255, 255, 255, 0.1));
.iqn {
.background(url(../gfx/price-icon.png), 0px -35px, no-repeat);
}
.tooltip {
.opacity(1);
left: 50px;
.transition(all, 0.25s, ease-in-out);
}
}
}
But what I pasted won't be very helpful, probably the link will help more: Anchor ; navigate to the Shop page.
I would appreciate it if someone could help me out with identifying the problem, I'm not so good using the console, perhaps that would help me a lot.
You dont need to set a dot (.) to add a new class, remove and the code should work.
$(this).removeClass('selected');

Is it possible to have a non-rectangular div?

I need to shape ONE div tag in the following shape:
Is it possible to make it cross browser? I don't necessarily need rounded corners. I need it so I can change the color of the borders of the whole div on hover, so I assume it can't be achieved by using two divs.
Yeah, you can do that using HTML and CSS like this: http://jsfiddle.net/broofa/364Eq/
It's essentially using three divs to aggregate the mouse events, like so:
<div id="outer">
<div class="inner"></div>
<div class="inner"></div>
</div>
And I use a :hover rule on the outer element to affect the border colors on the inner divs:
#outer .inner {border-color: red}
#outer:hover .inner {border-color: blue}
The only quirk with this markup is that the content area - the area you drew in your image - is that it's two divs, not one. So text won't wrap and flow the way you might expect. Also, this may not work so well on older (IE6-7) browsers. But FF, Chrome, Safari, Opera should probably be okay.
A one div solution using pseudo elements:
/* relevant styles for shape */
.tab {
border-top-left-radius: 0px;
margin-left: 100px;
}
.tab:before {
content:"";
display: block;
position: relative;
height: 50px;
width: 50px;
right: 52px; /* width + border width */
top: -2px;
background-color: white;
border: inherit;
border-right-width: 0px;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
/* styles to look like example */
div{
box-sizing: border-box;
background-color: white;
border: 2px solid red;
height: 100px;
width: 200px;
border-radius: 5px;
}
div:hover {
border-color: green;
}
<div class="tab"></div>
See this jsFiddle example:
<div id="main">
<div id="div1" class="border">
</div>
<div id="div2" class="border">
</div>
</div>
You can either use a map or use 2 divs and alter the borders so it looks like one shape.
two options that I can think of:
1) give the div a background image and use CSS pseudo class :hover to change the background image to one that indicates a hover state
2) put three div's inside a wrapper, and position them so so you have one in the upper left hand corner, and then two stacked on top of each other, so that you can simulate the top half of a larger div missing the upper left half border. I don't think CSS alonw can target all the divs in order to change their borders, so will probably have to use JS to execute the hover behavior, by applying an event handler to all three divs.
No. Divs are ALWAYS rectangular. You could fake it in a number of ways (using a background image would be one option).
As for using two DIVs, sure you could. The hover could be done with CSS3 and child selectors of a parent div or you could JavaScript to change the class of both divs when hovering over either one of them.
Definitely requires two or three div's unless you use a background image
Here's a three-div solution
http://jsfiddle.net/pxfunc/SUuF6/
Its cross-browser compatible. The hover won't work in IE6, but it will in IE7+. The rounded corners will show based on browser support
HTML:
<div id="fancyShape">
<div id="main"><div></div>
<div id="panHandle"></div>
</div>
CSS:
#fancyShape {position:relative;width:504px;height:304px;}
#main {
margin-left:100px;
width:400px;
height:300px;
border:solid 2px #000;
border-radius:0 15px 15px 15px;
}
#panHandle {
width:100px;
height:120px;
position:absolute;
top:0;left:0;
border-top:solid 2px #000;
border-left:solid 2px #000;
border-bottom:solid 2px #000;
border-radius:15px 0 0 15px;
}
/* hover effect */
#fancyShape div {background-color:#fff;}
#fancyShape:hover div {background-color:#ff0;border-color:red;}
Perhaps you could use Border-radius along with 2 or 3 div's to get the look you want. The only issue then is it's not supported in all browsers.
Use multiple divs, as others have suggested.
http://jsfiddle.net/thomas4g/7B5MA/14/
Keep in mind that it'll be very hard to flow content in this.
<!DOCTYPE HTML>
<html>
<head>
<style>
html{height: 100%; width: 100%;}
body{height: 100%; width: 100%;}
#wrapper{
position: relative;
top: 50px;
right: 25%;
width: 565px;
height: 440px;
margin: 0 auto;
padding: 0px;
}
#left{
position: absolute;
width: 100px;
height: 50px;
border: 2px solid black;
border-right: none;
-moz-border-radius-bottomleft: 10px;
border-bottom-left-radius: 10px;
-moz-border-radius-topleft: 10px;
border-top-left-radius: 10px;
background-color: #ffffff;
}
#right{
position: absolute;
left: 100px;
width: 440px;
height: 440px;
border: 2px solid black;
-moz-border-radius: 10px;
-moz-border-radius-topleft: 0px;
border-top-left-radius: 0px;
border-radius: 10px;
padding-left: 25px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"> </script>
<script type="text/javascript">
$(document).ready(function(){
$('#wrapper').hover(
function () {
$(this).children('#left').css({'border':'2px solid red', 'border-right':'none'});
$(this).children('#right').css({'border':'2px solid red'});
},
function () {
$(this).children('#left').css({'border':'2px solid black', 'border-right':'none'});
$(this).children('#right').css({'border':'2px solid black'});
});
});
</script>
</head>
<body>
<div id="wrapper">
<div id="right">Some content here</div>
<div id = "left"></div>
</div>
</body>
</html>
You can use CSSPIE for rounded orners for IE

Categories