How to move an element down a litte bit in html

133,297

Solution 1

You can set the line height on the text, for example within the active class:

.active {
    ...
    line-height: 2em;
    ....
}

Solution 2

<div class="row-2">
 <ul>
     <li><a href="index.html" class="active"><p style="margin-top: 10px;">Buy</p></a></li>
 </ul>

Play with it

Solution 3

You can use vertical-align to move items vertically.

Example:

<div>This is an <span style="vertical-align: -20px;">example</span></div>

This will move the span containing the word 'example' downwards 20 pixels compared to the rest of the text.

The intended use for this property is to align elements of different height (e.g. images with different sizes) along a set line. vertical-align: top will for instance align all images on a line with the top of each image aligning with each other. vertical-align: middle will align all images so that the middle of the images align with each other, regardless of the height of each image.

You can see visual examples in this CodePen by Chris Coyier.

Hope that helps!

Solution 4

A simple way is to set line-height to the height of the element.

Solution 5

You can use the top margin-top and adjust the text or you could also use padding-top both would have similar visual effect in your case but actually both behave a bit differently.

Share:
133,297

Related videos on Youtube

novicePrgrmr
Author by

novicePrgrmr

Updated on July 05, 2022

Comments

  • novicePrgrmr
    novicePrgrmr almost 2 years

    That sounds weird I know, but I am having trouble getting a piece of text to move down a tiny bit so it's centered on the tab it's on.

    here's what it looks like:

    enter image description here

    I want buy to be centered vertically.

    Here is the html:

    <div class="row-2">
         <ul>
             <li><a href="index.html" class="active">Buy</a></li>
         </ul>
    </div>
    
  • bradley.ayers
    bradley.ayers about 13 years
    What happens if the user changes their text size?
  • bradley.ayers
    bradley.ayers about 13 years
    What happens if the user changes their text size?
  • novicePrgrmr
    novicePrgrmr about 13 years
    tried that and it made the tab bigger, text stayed in the same place
  • bradley.ayers
    bradley.ayers about 13 years
    That means you've probably used the wrong approach to style the tabs. What My Head Hurts suggested is the best way to do this.
  • StepUp
    StepUp almost 7 years
    How it can be done? Is it correct line-height:100%;?
  • John Gilmer
    John Gilmer over 4 years
    This helped me. I had a situation where I had several links in a table cell td and wanted to move one of them down a bit.

Related