简体   繁体   English

在div中对齐图像和标签

[英]aligning an image and label in a div

I have a label and an image in a div which acts as a navbar in a mobile app. 我在div中有一个标签和一个图像,它在移动应用程序中充当导航栏。 I need the text to be centred and the image to be on the right. 我需要文本居中,图像在右边。 I can't manage to get the right combination. 我无法设法找到正确的组合。 Code here: 代码在这里:

<div data-role="header">
    <div class="centered">
         <img src="../images/culogo50x40.png" alt="logo" height="25px" class="c1">
         <h3>Login</h3>
    </div>
</div>

In class centred, I have: 以课堂为中心,我有:

.centered { 
width: 100%;
height: auto; 
position: fixed; 
top: 20%; 
background-color: red;
text-align:center; 
-webkit-backface-visibility: hidden;
}

and in class c1, I have: 在c1课上,我有:

img.c1 {
    float: right;
    display: inline;
}

You can position your img absolute and make the right:0; 您可以将img position absolute ,并right:0; to float it right. 使它浮动。 To make it vertical middle just make the following changes to your style 要使其垂直居中,只需对样式进行以下更改

img.c1 {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
}

DEMO 演示

NOTE: margin:auto works only with either fixed width or height to your element. 注意: margin:auto仅对元素固定widthheight有效。

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

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