-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
111 lines (87 loc) · 3.68 KB
/
Copy pathindex.html
File metadata and controls
111 lines (87 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Convert HTML selectors to percentages</title>
<style type="text/css">
body {
padding: 0;
margin: 0;
}
img, td, span, a {
border: solid 2px orange;
padding: 10px;
}
table {
width: 960px;
}
.td1, .td2 {
width: 480px;
}
</style>
</head>
<body>
<table>
<tr>
<td>Title</td>
</tr>
<tr>
<td>
<table>
<tr>
<td class="td1"><a href="#"><img src="image.png" alt="" width="60" height="60" class="img1"></a>
</td>
<td class="td2"><a href="#"><span class="text1">Text 1</span></a>
<br><span class="date1">Date 1</span>
<br><span class="description1">Description 1</span>
</td>
</tr>
<tr>
<td class="td3"><a href="#"><img src="image.png" alt="" width="60" height="60" class="img2"></a>
</td>
<td class="td4"><a href="#"><span class="text2">Text 2</span></a>
<br><span class="date2">Date 2</span>
<br><span class="description2">Description 2</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
<div class="results"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function () {
$("*").not("html, head, meta, title, link, style, script, img, a")
.each(function (index) {
var selector = $(this).parents()
.map(function () {
return this.tagName;
})
.get().reverse().join(" ");
if (selector) {
selector += " " + $(this)[0].nodeName;
}
var id = $(this).attr("id");
if (id) {
selector += "#" + id;
}
var classNames = $(this).attr("class");
if (classNames) {
selector += "." + $.trim(classNames).replace(/\s/gi, ".");
}
// outerWidth(true) would include border, margin, and padding
selector_width = $(this).width();
selector_parent_width = $(this).parent().width();
selector_percentage = selector_width / selector_parent_width * 100;
$(this).width(selector_percentage + "%");
console.log(index + ": " + selector + " (" + selector_width + " -> " + selector_percentage + "%)");
selector_path = selector.split(/\s+/);
last_selector = selector_path[selector_path.length-1];
console.log(last_selector);
$(".results").append("<p>" + index + ": " + selector + " (" + selector_width + " -> " + selector_percentage + "%)" + "</p>");
});
});
</script>
</body>
</html>