如何将图片移动到div的中心?
我尝试使用 text-align:center,但它不起作用。
谁能给我一个快速提示?非常感谢我:)!
<!-- Logo -->
@if( $user->logo_path)
<img class=" img-rounded" style="text-align:center;" src="/files/logo_path/{{$user->id}}" alt="logo" width="100" >
@else
<img class=" img-rounded " style="text-align:center;" src="/img/default.PNG" alt="logo" width="100" >
@endif
最佳答案
您需要申请 text-align:center
< img >
的父 div 属性元素,前提是您的 < img >
元素没有任何类型的定位。
确保 < img >
元素没有 display:block
属性,如果确实如此,则将其更改为 display:inline
或 display:inline-block
HTML:
<div class="parent_div" style="text-align:center;">
<!-- Logo -->
@if( $user->logo_path)
<img class=" img-rounded" src="/files/logo_path/{{$user->id}}" alt="logo" width="100" >
@else
<img class=" img-rounded " src="/img/default.PNG" alt="logo" width="100" >
@endif
</div>
关于html - 如何使用内联 css 将图像移动到 div 的中心?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27298235/