如何将元素居中?

时间:2016-01-23 11:09:25

标签: html css html5

我想将一个元素居中,以便上传文件。现在它是左对齐的。

<p class="text-muted">Bla-bla-bla
<input type="file" name="attachment" id="attachment" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
</p>    

我测试了).text-align = 'center';",但它不起作用。

更新:

<div class="col-md-4">
                    <span class="fa-stack fa-4x">
                        <i class="fa fa-circle fa-stack-2x text-primary"></i>
                        <i class="fa fa-tasks fa-stack-1x fa-inverse"></i>
                    </span>
                    <h4 class="service-heading">Practical Session #1</h4>
                    <p class="text-muted" style="text-align:center;">Bla-bla-bla
                    <input type="file" name="attachment" id="attachment" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" /></p>              
                </div>

enter image description here

1 个答案:

答案 0 :(得分:0)

使用内联样式: style =“display:block; margin:0 auto; 这应该解决它

<div class="buttonHolder">
<p class="text-muted" style="text-align:center;">Bla-bla-bla</p>
<input type="file" name="attachment" class="attachment" onchange="document.getElementById('moreUploadsLink');" style="display: block; margin: 0 auto;"/></p>              

</div>