Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right Align an inline UL which is inside a div

Tags:

html

css

I have a pagination output which is show within

    . An example is posted here: http://jsfiddle.net/6N4bD/1/

    The ul is wrapped around 2 divs

    1st div is 550 width 2nd div called "paginationDiv" basically wraps the ul around

    The ul has list-style: none. What I am trying to do is make it float right, but it keeps appearing as a block. I have tried quite a few things but nothing seems to work. If I add a width to the paginationDiv then it works but it's not accurate because it will never be fixed width

    Here is what it looks like:

    <div class="parentDiv">
       <div class="paginationDiv">
          <ul id="paginationLinks">
            <li>Page 1</li>
            <li>Page 2</li>
          </ul> 
        </div>
     </div>
    

    That's the html code

    Here is the css:

    div.parentDiv { 
      width: 550px; 
    }
    div.paginationDiv {
      float: right;
    }
    #paginationLinks ul {
      border: 0;
      padding: 0;
      margin: 0;
    }
    #paginationLinks li {
      list-style: none;
    }
    

    I have posted an example here: http://jsfiddle.net/6N4bD/1/

    like image 664
    Adil Avatar asked Jan 24 '11 12:01

    Adil


    People also ask

    How do I align ul items to the right?

    To make a right-aligned version of the list, only three changes need to occur. First, set the "UL" "text-align" to "right". Second, change the left "background-position" from "0" to "100%" - which makes the image align up with the right edge. And finally change "padding-left" to "padding-right".

    How do I align something inside a div?

    You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.


    1 Answers

    give float:left to #paginationLinks li and then see the result

    like image 82
    Mahima Avatar answered Oct 17 '22 06:10

    Mahima