css3 - create a div square, and center it accordingly the view port using less -


i trying create square(or div) in browser according size of screen, using percentage, want square 40% of height of screen, , amount of percentage in pixels , use width in order square. , use these values center it. know javascript should easy, new less , wondering how can done. tried following , doesnt work:

@base:calc(40% * 1px);  #mytransform {     background-color:#ccc;    height:@base;    width:@base;    position:absolute;    top:50%;    left:50%;    margin-top:-(@base/2);    margin-left:-(@base/2);   } 

how can transform percentage pixels?

you cannot desire precompiled less

less css preprocessor. means processes code form css before browser ever sees it; , far less concerned, browser not exist. means is, 40% of height of browser window totally unknown less. knows 40%, having no idea translate pixels @ later time.

you either want stick javascript, or use html mark-up squaring effect.

client-side compiling (not recommend production)

i need stress fact client-side compiling recommended development. if has javascript turned off, no styling. , have turned on going experience slowdown in page loading.

now, reason invalid type error because returned value needs made number less understands (i think treating returned value string). can done (see changes @base assignment):

@base: (0.4 * unit(`window.innerheight`, px));  #mytransform {     background-color:#ccc;    height:@base;    width:@base;    position:absolute;    top:50%;    left:50%;    margin-top:-(@base/2);    margin-left:-(@base/2);  } 

my css output on 1 run @ less2css.org

#mytransform {   background-color: #ccc;   height: 243.60000000000002px;   width: 243.60000000000002px;   position: absolute;   top: 50%;   left: 50%;   margin-top: -121.80000000000001px;   margin-left: -121.80000000000001px; } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

android - Inheriting from Theme.AppCompat* -