开发者

css float:right and vertical align?

开发者 https://www.devze.com 2023-01-08 21:36 出处:网络
i am experimenting with html and css and trying to figure out how to make this work... I am just trying to make the #menu float to the right of the h1 but be on the same baseline so... but obviously f

i am experimenting with html and css and trying to figure out how to make this work... I am just trying to make the #menu float to the right of the h1 but be on the same baseline so... but obviously float:right makes it float to top-right? any way to make it float to bottom-right or align with the bottom of the containing div?

here is the html:

<!doctype html>
<html>
    <head>
        <title>Website.com</title>
        <link rel="Stylesheet" href="style.css" type="text/css" />
    </head>
    <body>
        <div>
            <h1><a href="#" title="Website.com">Website.com</a></h1>
            <div id="menu">
                <ul>
                    <li><a href="#" title="Home">Home</a></li>
                    <li><a href="#" title="Link1 Description">Link1</a></li>
                    <li><a href="#" title="Link2 Description">Link2</a></li>
                    <li><a href="#" title="Link3 Description">Link3</a></li>
                    <li><a href="#" title="About Website.com">About</a></li>
                </ul>
            </div>
        </div>
        <hr />开发者_运维问答;
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mattis elit et augue pellentesque fermentum semper urna interdum. Nullam egestas augue ut risus molestie mollis ut sed dolor. Curabitur fermentum, lorem sed suscipit euismod, diam urna vulputate sapien, ac venenatis velit eros sed leo. Duis venenatis, metus at scelerisque fringilla, neque arcu dignissim arcu, quis sodales lorem mauris eget tellus. Phasellus fermentum est eget erat pretium mollis. Cras eu nunc dui, sed fermentum libero. Vivamus posuere pellentesque tellus in interdum. Vestibulum eleifend fringilla enim, in vehicula justo tristique a. Aenean congue vestibulum iaculis. Sed tristique interdum lectus, vel aliquam nisi fringilla ac. Mauris ligula nisl, gravida id consequat in, vestibulum at risus. Vivamus vitae massa lorem, vel molestie tellus. Nulla et magna orci. Nunc turpis ipsum, facilisis eget tristique sit amet, scelerisque quis ligula. Mauris in molestie purus. Cras eget magna vel enim imperdiet aliquam.</p>
        <p>Vestibulum vel eros lacus, vel viverra magna. Duis mollis nibh ut erat accumsan ut pulvinar ipsum dapibus. Aliquam vehicula tempus fermentum. Morbi ut turpis sem, pretium sodales libero. Vestibulum dapibus, ligula in molestie scelerisque, lacus est aliquam elit, ut vulputate sapien nisl vitae elit. Cras pulvinar mi nisl. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin in est orci. Ut rutrum lobortis quam vitae commodo. Maecenas dapibus aliquam ante eget mattis. Proin justo eros, bibendum quis scelerisque eget, fermentum eu purus. Vivamus viverra ligula a dolor iaculis ullamcorper. Aliquam erat volutpat. Nunc libero nulla, sodales at dictum vel, tempus quis est.</p>
        <p>Nullam pharetra tincidunt lectus ac sollicitudin. Duis in venenatis eros. Phasellus malesuada quam vel sapien ultricies tincidunt. Duis condimentum posuere semper. Vivamus eleifend libero eget ligula egestas adipiscing. Proin dapibus leo non urna pellentesque convallis. Suspendisse massa leo, semper vitae tincidunt at, mattis et sapien. Maecenas consequat hendrerit odio et feugiat. Sed dignissim massa a leo sollicitudin imperdiet consequat purus vehicula. Mauris sit amet nulla a turpis porta accumsan. Morbi interdum pellentesque massa, vel accumsan massa aliquam quis. Sed sed ligula neque. In hac habitasse platea dictumst. Curabitur vehicula scelerisque ligula non tincidunt.</p>
        <hr />
        <p id="footer">Use of this site constitutes acceptance of our <a href="#">User Agreement</a> and <a href="#">Privacy Policy</a>. &copy; 2010 Website.com. All rights reserved.</p>
    </body>
</html>

and here is the css:

body
{
    font-family: verdana, sans-serif;
    min-width: 800px;
}

h1
{
    display: inline;
    font-variant: small-caps
}

h1 a
{
    color: #090;
    text-decoration: none;
}

h1 a:hover
{
    color: #0A0;
}

#menu
{
    float: right;
    display: inline;
    margin: 0;
    padding: 0;
    font-variant: small-caps;
}

#menu ul
{
    margin: 0;
    padding-left: 0;
    float: left;
    font-weight: bold;
}

#menu ul li
{
    float: left;
    display: inline;
}

#menu ul li a
{
    color: #090;
    background-color: #F3F3F3;
    padding: 2px 6px 4px 6px;
    text-decoration: none;
}

#menu ul li a:hover
{
    font-weight: bolder;
    color: #0A0;
    background-color: #F3F3F3;
    border-bottom: 4px solid #0A0;
    padding-bottom: 0;
}

#footer
{
    text-align: center;
    font-size: x-small;
}

here is what is looks like now:

css float:right and vertical align?

thanks for help!


I haven't looked into this much, but if you set the containing div's position: relative, you can just make the ul position: absolute; bottom: 0; right: 0 and it should go where you want it.

Example:

div {position: relative}
ul {position: absolute; bottom: 0; right: 0}
li {float: left; list-style: none}

--

<div>
    <h1>Header</h1>
    <ul>
        <li>One</li>
        <li>Two</li>
        <li>Etc...</li>
    </ul>
</div>


There's no property floating it bottom-right or top-right. But without changing your html structure you can just add a top margin to your menu div

#menu {
  ....
  margin-top:20px;
}


You can use table:

<table id="title">
  <tr>
    <td>
      <h1><a href="#" title="Website.com">Website.com</a></h1>
    </td>
    <td>
      <div id="menu">
          <ul>
              <li><a href="#" title="Home">Home</a></li>
              <li><a href="#" title="Link1 Description">Link1</a></li>
              <li><a href="#" title="Link2 Description">Link2</a></li>
              <li><a href="#" title="Link3 Description">Link3</a></li>
              <li><a href="#" title="About Website.com">About</a></li>
          </ul>
      </div>
    </td>
  </tr>
</table>

And add this into your CSS file:

#title
{
  width:100%;
}

#title td+td
{
  text-align:right;
  vertical-align:center;
}

Vertical align is default set to center, so you need not to set it.
Or if you don't want to use table, you can just set padding-top:10px; into #menu ul.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号