开发者

How to make a div top center?

开发者 https://www.devze.com 2022-12-12 03:16 出处:网络
I\'m now doing it this way,which is not ce开发者_开发百科ntered: $div = $(\'<div style=\"background-color:yellow;position:absolute;top:0;\"><b>Loading...</b></div>\').appendTo

I'm now doing it this way,which is not ce开发者_开发百科ntered:

$div = $('<div style="background-color:yellow;position:absolute;top:0;"><b>Loading...</b></div>').appendTo('body');


For auto margins to work you also need to define a width for the div as well, else it just takes up the whole screen width and you'll see no difference.

However, in this instance all you need is to add text-align: center; to your original CSS as far as I can see?


Give it

margin: 0 auto;


<div style="text-align: center">
  <div style="text-align: left; margin: 0 auto; width: 50%; background: yellow">
    Your text here
  </div>
</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消