[英]I am having trouble with centering the heading of a paragraph
.center { text-align: center }
<h1 class="center">Title</h1> <div style="float: left;"> <p>Some Text</p> </div> <div style="float: right;"> <img src="image.png"> </div>
When I run this code the heading appears on the center of the page.当我运行此代码时,标题出现在页面的中心。 However, I want the heading to center above the paragraph.
但是,我希望标题在段落上方居中。 Can anyone help me do this?
谁能帮我做到这一点?
Try with following:尝试以下操作:
<div style="float: left;"> <h1 class="center">Title</h1> <div> <p>Some Text</p> </div> </div> <div style="float: right;"> <img src="image.png"> </div>
I recommend you ditch floats and use modern flex-box for alignment.我建议你放弃浮动并为 alignment 使用现代 flex-box。 You will find there is much greater depth of control.
你会发现控制的深度要大得多。
.row-wrap { display: flex; }.p-wrap { flex: 1; flex-direction: column; }.p-wrap h1 { text-align: center; }.img-wrap { flex: 0; padding: 10px; }
<div class="row-wrap"> <div class="p-wrap"> <h1>Title</h1> <p>Some Text</p> </div> <div class="img-wrap"> <img src="https://i.stack.imgur.com/jvyJq.jpg"> </div> </div>
Try it with a table:用一张桌子试试:
.center { text-align: center }
<table> <tr> <td class="center"><h1>Your title</h1></td> </tr> <tr> <td><p>Your Paragraph</p><img src="image.png" style="float: right"></td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.