Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
Like Tree3Likes
  • 1 Post By TheGAME1264
  • 1 Post By Ronald Roe
  • 1 Post By DC Web Design

Thread: How To Centralise A Floated Group of Links?

  1. #1
    Junior Member princeeternity's Avatar
    Join Date
    Jul 2014
    Location
    Jharkhand, India
    Posts
    15
    Member #
    39703

    Post How To Centralise A Floated Group of Links?

    Hi. I have a footer menu with six items. Now, I specify these arguments to the links inside them:

    Code:
    	display: block;
    	width: 5em;
    	padding: .4em;
    	margin: 10px 0;
    	float: left;
    	text-align: center;
    This group of links is locked inside a <div> element. However, because they're floated left, and have a fixed width, they line up from the left side of the viewport. This leaves a bigger space on the right side than that on the left.

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    You don't. Float: left does exactly what you're seeing...moves something to the left.

    The question is: why are you floating them in the first place?
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Junior Member princeeternity's Avatar
    Join Date
    Jul 2014
    Location
    Jharkhand, India
    Posts
    15
    Member #
    39703
    To make the list behave as navbar links?

  5. #4
    Senior Member Vapr_Arts's Avatar
    Join Date
    Oct 2013
    Location
    California
    Posts
    1,930
    Member #
    37412
    Liked
    544 times
    I dont even see a question? What is the problem? You floated them left, and they are floating left?

  6. #5
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    It's a footer menu. Personally, I'd take out the display: block; and the float: left; and you'll probably get what you want as long as you set text-align: center; to the containing div.

    If you're looking for a certain behavior (say a change in background color on hover), you may want to define padding and/or line-height.
    princeeternity likes this.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  7. #6
    Junior Member princeeternity's Avatar
    Join Date
    Jul 2014
    Location
    Jharkhand, India
    Posts
    15
    Member #
    39703
    footer.jpg

    This is a footer.

    If there's no display: block and float: left, they'll probably look like a simple list.

    But as you can see, even when they're lists, they are centrally aligned. If I remove two or three items, they just don't "keep floated to the left because that's what they're meant to do because they're floated left". They still centre align.

    The purpose of float: left in a navigation bar (like this footer), is to align each item AFTER the previous one, and not start BELOW each one. And there IS some style that can be applied to some containing element which can do the trick.

  8. #7
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Okay, I don't have a clue what you're talking about with the second sentence, but display: block, and float: left on links that are child elements of lists have no bearing on whether or not they "look like a list". That has to do with the list elements themselves (your ul in this case, assuming you've coded this thing correctly).

    Links are inline elements by default. That means that they don't need to be floated and they don't need to be set to display: block; to be centered in a containing div by default. They will be centered as would plain text, spans, strongs, ems, and any other inline tags would by default. If they aren't, it means you've done something else incorrectly, in which case we're going to have to see your code. What I told you was correct.

    My guess, without having looked at your particular code, is that you've got a div containing a bunch of hyperlinks, which is a semantically incorrect way to handle a footer (or any menu, for that matter). So show us your site (yes, you can include a link here...you have a mod's permission) and someone will probably be able to advise you assuming your code isn't the HTML equivalent of Three Mile Island.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  9. #8
    Junior Member princeeternity's Avatar
    Join Date
    Jul 2014
    Location
    Jharkhand, India
    Posts
    15
    Member #
    39703
    Reason I cannot show you the code: My file is a test file, that inherits style from three stylesheets. I haven't uploaded it on server, I'm out of subdomains. And come on, it's just a test site for experimenting.

    Restatement: I totally understand what you're saying, and we both are having confusions here. Let me restate. It's a group of links, floated left. Cool. They line up after each other. Cool. As links, they have full reason to be stuck on the left. But here's it. A navigation bar doesn't look good stuck on the left. Or right. It feels good when it's centred. So how do I position it in centre? The entire footer?

    There must be something like wrapping it in a "div with margin: auto" or something... I just don't know what.

    If that still didn't make any sense, then I must be wrong somewhere. Never mind and I'll look at it by myself. Thanks. And oh of course I'll like your posts hehe

  10. #9
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    You need to wrap it in a <nav> tag, give that tag a width, and set margin:0 auto; There are other ways, but that's the easiest.
    princeeternity likes this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  11. #10
    Senior Member DC Web Design's Avatar
    Join Date
    Jan 2014
    Location
    Washington, DC
    Posts
    128
    Member #
    38178
    Liked
    37 times
    You can use floats on the li's, but you have to set a fixed width to the parent element and set the left/right margins to auto which will have a "centering" effect.

    You can also try using inline display on the li's instead of floats, and text-align: centering the parent element. I can't remember if this works off the top of my head but it's worth a try.
    princeeternity likes this.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Tags for this Thread

All times are GMT -6. The time now is 07:43 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com