简体   繁体   English

如何在中间水平调整按钮(在 js 中创建)?

[英]How can I adjust a button (created in js) horizontally middle?

I tried "text-center" class, and other bootstrap classnames.我尝试了“文本中心”class 和其他引导类名。

const evaluate = document.createElement('button');
evaluate.className="btn btn-outline-dark";
this.canvas.appendChild(evaluate);
evaluate.textContent = 'Calculate';
evaluate.id = 'eval'; 

You have to add style text-align您必须添加样式text-align
see this reference page.请参阅此参考页。 https://developer.mozilla.org/ko/docs/Web/CSS/text-align https://developer.mozilla.org/ko/docs/Web/CSS/text-align

const btn = document.createElement('button');
btn.id = 'eval'
btn.className='btn btn-outline-dark';
btn.textContent = 'Calculate';
btn.style = 'text-align:center';

this.canvas.appendChild(btn);

You need to add the class text-center to the parent.您需要将 class text-center Try adding a div with this class name and append the button to it.尝试使用此 class 名称和 append 按钮添加一个div Here is an example:这是一个例子:

 const parent = document.createElement('div'); parent.className = 'text-center'; const evaluate = document.createElement('button'); evaluate.className="btn btn-outline-dark"; evaluate.textContent = 'Calculate'; evaluate.id = 'eval'; parent.appendChild(evaluate); document.body.appendChild(parent);
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM