简体   繁体   English

在同一行中显示文本和图像

[英]display text and image in same line

I'm having problem with css styles.I want to display the file and delete image in same line. 我的CSS样式有问题。我想在同一行中显示文件并删除图像。

1 st image 第一张图片 在此处输入图片说明

In this image icon display slight above from doc.If I include css code it appears link this. 在此图像图标中,略高于doc.If我包括CSS代码,则显示为链接此。

I want to display the image 20% from margin-right.For testing I changed to 66%. 我想从右边距显示20%的图像,为了进行测试,我更改为66%。

在此处输入图片说明

In 2nd imgae is a screen shot for without using css style. 在第二张imgae中,是不使用CSS样式的屏幕截图。 I attached my css and html code 我附上了CSS和HTML代码

css code:
img {
  display: inline-block;
  float: right;
  margin-right:66%;   //realy I want  margin-right:20%;
  }

html in php
 echo '<div style="text-align:left;">';
            while($fet=mysql_fetch_assoc($filesql1))
            {

              $file=$fet['file_name'];
               $ef=$fet['cf_id'];
              $next1 = basename($file);
              echo "<h3><a  class=doc href='".$file."' title='".$file."' download><p style='margin-left:1cm;'>".$next1."</a>";
               echo '<a href=#><img src="image/delete1.png"  width="10" height="10" title="Remove" onclick="myFunction('.$fet['cf_id'].');"></a></span>';
            }   
         echo '</div>';   

As far as I can see, the problem comes from the fact that your CSS applies to the <img> tag, which is enclosed in an <a> tag. 据我所知,问题出在您的CSS应用于<img>标记的事实,该标记包含在<a>标记中。 The behaviour is changed by whatever CSS is applied to <a> . 通过将CSS应用于<a>可以更改行为。 You should modify your CSS so that it applies to <a><img> . 您应该修改CSS,使其适用于<a><img> The simple way would be to give a specific class to this <a> tag. 简单的方法是为此<a>标记提供特定的类。

in your first screenshot the image aligns to the top of your line-height (because the css makes it a float), in the second screenshot it is aligned to the the center of the line-height by browser-default - this is close to the baseline in your case but not exactly on the line. 在您的第一个屏幕截图中,图像与行高的顶部对齐(因为css使它浮动),在第二个屏幕截图中,浏览器默认将其与行高的中心对齐-这与您的情况下的基线,但不完全一致。 To work on with your css-code: 要使用CSS代码,请执行以下操作:

img {
display: inline-block;
float: right;
margin-right:20%;
position: relative;
top: 4px; /* maybe 3px or 5px or even 6px will look better; try it out */
}

This will put your image on the line in most browsers but you will have to allow others to show the image slightly above or beneath the line. 这将使您的图像在大多数浏览器中显示在行上,但是您将不得不允许其他人在行上方或行下方显示图像。 This is a known problem with aligning images to text because not all browsers render the baseline for the text in the same place. 这是将图像与文本对齐的一个已知问题,因为并非所有浏览器都在同一位置呈现文本的基线。

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

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