Showing posts with label to the reviewing of front time. Show all posts
Showing posts with label to the reviewing of front time. Show all posts

Thursday, October 3, 2013

Horizontal image align CSS

I’m having some trouble aligning a main image. It should be center-aligned horizontally, yet keeps going all over the place. The page can be found here http://0034.eu/propmanager/

<img src="images/background-space.png" class="displayed" border="0" />IMG.displayed{    display: inline-block;    margin-left: auto;    margin-right: auto;}

That’s basically the CSS I have applied to the image, all the source code is on main index.html (no separate style sheet).

Thanks!

Add this to your CSS style.

img.displayed {    display: table-caption;    margin: 0 auto;}

EDIT

From the inputs of IlyaStreltsyn, I agree with the point of clearing the right with display:block for the image to be centered.

For Instance,

img.displayed {    display: block;    margin: 0 auto;    clear: right;}

Monday, September 30, 2013

Loop through nested objects with jQuery

Hey everyone I am trying t find the most dynamic way to loop through an array & return specific values return specific values… The json is deeply structured & may change, could there be a $.each() formula that can help?

Example:

var myobj = {    obj1: { key1: 'val1', key2: 'val2' },    obj2: { key1: '2val1',            key2: { nest1: 'val1', nest2: 'val2', nest3: 'val3' },            key3: { nest1: 'K3val1', nest2: 'K3val2',                  nest3: [                         { nest1: 'val1', nest2: 'val2', nest3: 'val3' },                          { nest1: 'val1', nest2: 'val2', nest3: 'val3' }                        ]                 }          },    obj3: { key1: 'dddddval1', key2: 'val2' }    }

now lets say i want to retrieve “K3val2” value yet instead of hardcoding it like so: myobj.obj2.key3.nest2 is there a dynamic way I do this with $.each() mybe?

You can simply nest calls to $.each:

Live Example | Live Source

// Loop the top level$.each(myobj, walker);function walker(key, value) {    // ...do what you like with `key` & `value`    if (value !== null && typeof value === "object") {        // Recurse into children        $.each(value, walker);    }}

If you want to know how deep you are, you can do that too:

Live Example | Live Source

var path = "";// Loop the top level$.each(myobj, walker);function walker(key, value) {    var savepath = path;    path = path ? (path + "." + key) : key;    // ...do what you like with `key` & `value`    if (value !== null && typeof value === "object") {        // Recurse into children        $.each(value, walker);    }    path = savepath;}