How can I make an element as wide as it is high in css?

SomeNorwegianGuy

I know I can make an element as high as it is wide using padding-top/bottom

#element {
  width: 40%;
  padding-top: 40%;
}

The reason the above works is because, when giving padding-top/bottom a percentage value, it is relative to the width of the parent, not the height.

how can i do the same thing, just making it as wide as it is high instead of the other way around?

It needs to be responsive, and the solution should work in all major browser including IE8+

Andreas

You might need javascript using jquery it should be something like:

$('#element').css({
     width: + $('#element').height()
})

but the above is very rough I didn't even test it

Update it works- see my fiddle: fiddle for above

or I think I might been a bit sloppy if you prefer:

var el=$('#element');
el.css({
    width: + el.height()
});

this

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

make canvas as wide and as high as parent

How can I center an element with css?

Make an element as wide as the grandparent

How can I make this css animation smooth

How do I make a heatmap with wide data?

how can I make diagonal lines with css

How can I make my SQL Server table collapse on a unique ID to make into wide format?

How can I override Bootstrap CSS of an <a> element?

How can I make this CSS animation smooth?

LaTeX table too wide, how can I make it fit?

How can I make a dotted arrow in CSS?

How can I fix the css for this element?

How i can make a dynamic css class?

How can I make it so the first element in a DIV has a different CSS to others?

How can i make this css star smaller?

How can I make all inserted images in the textarea 100% wide

How can I make tabs with only CSS?

How can I make a <p> element display on the hover of its parent <div> using CSS?

How can i make a color opacity in CSS?

How can I make this menu pure CSS?

How can I make a fixed CSS animation

How can I make HIGH LOW loop with analog value

How can I make the last element of this CSS DYNAMIC Columns grid to occupy all the columns?

How can I make the element stay in its place with CSS when hovering

How can I make all elements equally wide in flexbox?

How can I make a CSS grid unresponsive to a changing element inside of it?

How can I make the element appearing when checkbox is checked when this element is outside its tag with CSS ? Symfony

How can I animate cutting an element with CSS?

In CSS how can I make an element with "position: absolute" align left but also be contained right?

TOP Ranking

HotTag

Archive