Results 1 to 3 of 3

Thread: [RESOLVED] List Item Margin

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Resolved [RESOLVED] List Item Margin

    I'm wanting to create a tab control, but I'm having some issues with styling the list items(<li>). For some reason they're showing a space between them even if I have the margin set to 0 and I'm not sure why they're doing this. Here is my code that I'm currently using:
    Code:
    <html>
    
    <head>
    	<style>
    		.tabControl {
    			display: block;
    		}
    		
    		.tabControl ul {
    			list-style-type: none;
    			margin: 0;
    			padding: 0;
    		}
    		
    		.tabControl ul li {
    			border: 1px solid #000000;
    			border-top-left-radius: 7px;
    			border-top-right-radius: 7px;
    			cursor: pointer;
    			display: inline-block;
    			margin: 0;
    			padding: 15px 0;
    			text-align: center;
    			width: 150px;
    		}
    		
    		.tabContent {
    			border-bottom: 1px solid #000000;
    			border-left: 1px solid #000000;
    			border-right: 1px solid #000000;
    			height: 250px;
    			overflow: hidden;
    		}
    		
    		.tabContent div {
    			display: inline-block;
    			height: 100%;
    			padding: 0 1%;
    			width: 98%;
    		}
    		
    		.active {
    			border-bottom-style: none !important;
    			cursor: default !important;
    			font-weight: bold;
    		}
    	</style>
    </head>
    
    <body>
    <div class="tabControl">
        <ul>
            <li class="active">Tab1</li>
            <li>Tab2</li>
            <li>Tab3</li>
        </ul>
        <!-- TODO: The amount of <div> equal the amount of <li> -->
    	<div class="tabContent">
    		<div>
    			<p>Content of Tab1</p>
    		</div>
    		<div>
    			<p>Content of Tab2</p>
    		</div>
    		<div>
    			<p>Content of Tab3</p>
    		</div>
    	</div>
    </div>
    </body>
    </html>
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: List Item Margin

    I think it has to do with using inline-block.

    Have you tried using display: block, and then left floating the li's? That's what I typically do and it works.

    So change:

    Code:
    .tabControl ul li {
    			border: 1px solid #000000;
    			border-top-left-radius: 7px;
    			border-top-right-radius: 7px;
    			cursor: pointer;
    			display: inline-block;
    			margin: 0;
    			padding: 15px 0;
    			text-align: center;
    			width: 150px;
    		}
    To

    Code:
    .tabControl ul li {
    			border: 1px solid #000000;
    			border-top-left-radius: 7px;
    			border-top-right-radius: 7px;
    			cursor: pointer;
    			display: block;
                            float: left;
    			margin: 0;
    			padding: 15px 0;
    			text-align: center;
    			width: 150px;
    		}
    Then you have some other aligning to do, but it fixes the initial problem.

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: List Item Margin

    That does fix the spacing issue between items, but it then moves my tabContent <div> on side of the <ul>. So I tried setting the width of the <ul> to 100% and that doesn't seem to work.

    Edit: I set the display of my .tabControl <div> to inline-block and that fixed that issue. Thanks kfcSmitty.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

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



Click Here to Expand Forum to Full Width