Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: width/height attribute respond only to px (not %)

Tags:

css

I want to create a red square on in the webpage.

When I write the following html element:

<div style="{'background': 'red', 'table-layout': 'fixed', 'width': '**10%**','height' : '**10%**'}"

I get a white webpage.

However, when I replace '%' with 'px' and write:

<div style="{'background': 'red', 'table-layout': 'fixed', 'width': '**10px**','height' : '**10px**'}"

I get a small red square at the corner of the screen. Probably, I use the percent feature wrong. Can you tell me what is the problem?

like image 377
CrazySynthax Avatar asked Oct 28 '25 05:10

CrazySynthax


1 Answers

<div class="parent" style="width: 100%; height: 500px">
  <div style="width: 10%; height: 10%; background: red"></div>
 </div>

i think you need to have a parent which your percentage width and height would base.

like image 87
GvM Avatar answered Oct 29 '25 22:10

GvM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!