简体   繁体   English

如何将文字与图片中的图片垂直对齐<div>

[英]How to align text vertically with an image inside a <div>

I am trying to have text on the left side of a while there is an image in the corner. 我正在尝试在左侧有文字的同时在角落里有一个图像。 My problem is that the text is on the bottom. 我的问题是文本在底部。 I've tried vertical-align and a few other things. 我已经尝试过垂直对齐和其他一些东西。 Here is the code: 这是代码:

    <div id="taskbar">
        <div id="links">
            <img src = "link"/> <!--Need a version where the white is not in the image. Should look nicer -->
            <ul>
                <li>Home</li>
                <li>About</li>
                <li>Jobs</li>
                <li>Social</li>
                <a href = "link"> <li>Blog</li> </a>
                <li>FAQ</li>
                <li>More</li>
            </ul>
        </div>
    </div>
    #taskbar
    {
        position: absolute;
        top: 0px;
        left: 0px;
        width: 100%;
        display: inline-block;
        background-color: lightgrey;
    }
    ul
    {
        list-style-type: none;
        text-align: right;
        padding-left: 25px;
    }
    li
    {
        display: inline;
         padding: 25px;
    }
    div img
    {
       padding-top: 5px;
       padding-left: 5px;
       height: 75px;
       width: 75px;
    }
    a
    {
        text-decoration: none;
    }

Add this. 加上这个

  ul  {
      list-style-type: none;
      text-align: left; /* or right, which ever you want */
      padding-left: 25px;
      display: inline-block;
    }
    div img
    {
      display: inline-block;
    }

All i have done is add inline-block to the ul and image. 我所做的就是将内联块添加到ul和图像中。

Update css Using Float:left 使用 Float:left 更新CSS Float:left

li
    {
        display: inline;
        float:left;
         padding: 25px;
    }
    div img
    {
       padding-top: 5px;
       padding-left: 5px;
       height: 75px;
       width: 75px;
       float:left;
    }

Live Demo 现场演示

对齐内部的图像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直对齐 div 内的图像和文本。 我的代码:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起来像这样: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此处输入图像描述"></a></p><p> 我希望“KRON”与图像对齐。 我做错了什么?</p></div> - Align image and text inside <div> horizontally and vertically

暂无
暂无

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

相关问题 垂直对齐Div内的图像和文本 - Vertically Align Image and Text Inside a Div 将文本与div中的图像垂直对齐 - Vertically align a text with an image inside a div 对齐内部的图像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直对齐 div 内的图像和文本。 我的代码:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起来像这样: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此处输入图像描述"></a></p><p> 我希望“KRON”与图像对齐。 我做错了什么?</p></div> - Align image and text inside <div> horizontally and vertically 如何在DIV内垂直对齐文本和图像? - How do I align text and an image vertically inside a DIV? <a>在div中</a>垂直对齐<a>文本</a> - Vertically Align <a> text inside a div 使div和图像在div内垂直对齐 - make div and image vertically align inside a div 如何在div中垂直对齐图像? - How to Align Vertically the image in a div? 如何垂直对齐div文本? - How to vertically align div text? 如何将 div 与文本垂直对齐 - How to vertically align a div with text 如何垂直对齐div内的图像与动态高度? - How to vertically align an image inside a div with dynamic height?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM