How to remove border on active li tab - html

I have a list ul with items li. Under the list there is a box surrounded with border. The top border of the box is also the bottom border of the list items.
What I want to do know is to remove the bottom border of the active tab. That means removing the top border of the content box along the active tab. Is this possible or do I need to use a different approach?
li {
display: inline-block;
padding-top: 0;
padding: 15px;
border-right: 1px solid #e6e6e6;
cursor: pointer;
border-top: 1px solid #e6e6e6;
font-family: 'Cera';
font-size: 13px;
}
ul {
list-style-type: none;
margin: 0 auto;
border-left: 1px solid #e6e6e6;
padding-left: 0px;
}
.content-box {
display: block;
min-height: 100px;
margin: 0 auto;
border: 1px solid #e6e6e6;
overflow: hidden;
padding-bottom: 10px;
}
.active {
position: relative;
background-color: #f8f8f8;
top: -3px;
}
<ul id="menu">
<li class="active" data-nav="1">Prerender</li>
<li data-nav="2">Prefetch</li>
<li data-nav="3">Preconnect</li>
<li data-nav="4">DNS-prefetch</li>
</ul>
<div class="content-box box1 expanded">
<h3 id="isPrerender"> Prerendered page:</h3>
<ul class="results" id='pagetitle1'></ul>
</div>
Here's how I'd like it to look:

I suggest that you use negative margin to overlap elements.
Use a margin-top:-1px to overlap the top border of the lower box with the bottom edge of the top boxes. This allows the background-color of the active top box to cover the top border of the lower box.
Use margin-left:-1px on all top boxes except the first one to overlap the borders on their left and right sides. Otherwise, with a border on only one side, the active box will be missing a piece of border where it rises above the others.
I've removed the white space between <li> elements because, since they are display:inline-block, that space is rendered as gaps between the boxes.
I'm using additional padding to raise the active top box, instead of using negative top. This keeps the text inside the active box at the same height as the other boxes.
I've aligned the top boxes with vertical-align:bottom to keep them flush against the bottom box.
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
display: inline-block;
padding: 15px;
margin-left: -1px;
border-style: solid;
border-color: #e6e6e6;
border-width: 1px 1px 0 1px;
cursor: pointer;
font-family: 'Cera';
font-size: 13px;
vertical-align: bottom;
}
li:first-child {
margin-left: 0;
}
.content-box {
min-height: 100px;
border: 1px solid #e6e6e6;
margin-top: -1px;
padding: 10px;
}
.active {
background-color: #f8f8f8;
padding-top: 18px; /* 15 + 3 */
}
<ul id="menu">
<li data-nav="1">Prerender
</li><li class="active" data-nav="2">Prefetch
</li><li data-nav="3">Preconnect
</li><li data-nav="4">DNS-prefetch</li>
</ul>
<div class="content-box box1 expanded">
<h3 id="isPrerender">Prefetched page:</h3>
<ul class="results" id='pagetitle1'></ul>
</div>

If your idea is to slide down the tab to hide the border , then you should reset vetical-align on li (and eventually mind the white-space) , then increase the padding of 1px (for a one px border) and low it down of that extra pixel(s) like you tried.
li {
display: inline-block;
padding-top: 0;
padding: 15px;
border-right: 1px solid #e6e6e6;
cursor: pointer;
border-top: 1px solid #e6e6e6;
font-family: 'Cera';
font-size: 13px;
vertical-align: bottom;
}
ul {
list-style-type: none;
margin: 0 auto;
border-left: 1px solid #e6e6e6;
padding-left: 0px;
}
.content-box {
display: block;
min-height: 100px;
margin: 0 auto;
border: 1px solid #e6e6e6;
overflow: hidden;
padding-bottom: 10px;
}
.active {
position: relative;
background-color: #f8f8f8;
padding-bottom: 16px;/* increase height of 1 px here, can be any value you want */
top: 1px;/* low it done at least the border's thickness to hide */
}
body {
margin: 1em;
}
<ul id="menu">
<li class="active" data-nav="1">Prerender</li><!-- kill that white space via comments
--><li data-nav="2">Prefetch</li><!--
--><li data-nav="3">Preconnect</li><!--
--><li data-nav="4">DNS-prefetch</li>
</ul>
<div class="content-box box1 expanded">
<h3 id="isPrerender"> Prerendered page:</h3>
<ul class="results" id='pagetitle1'></ul>
</div>

Related

Menu item slightly off tilt?

I am building a menu, and the last item 'Book Now' is slightly off tilt (pushing down). All i did is add a border, which seems to break the perfect horizontal alignment. Is there any way to fix this?
Codepen
HTML:
<div class="navibar">
<a class="logo" href="#">Logo</a>
<ul class="left-bar">
<li>
ACCOMMODATIONS
</li>
<li>
DINING
</li>
<li>
SPA & WELLNESS
</li>
<li>
MEETINGS & EVENTS
</li>
<li>
ADVENTURES
</li>
</ul>
<ul class="right-bar">
<li>
<a class="btn btn-ghost" href="#">BOOK NOW</a>
</li>
</ul>
<div style="clear:both"></div>
</div>
CSS:
* {
list-style: none;
margin: 0px;
padding: 0px;
text-decoration: none;
}
.navibar {
margin: 0 auto;;
width: 1100px;
background: rgba(18, 23, 26, 0.4);
padding: 20px;
}
.navibar li a {
color: white;
display: inline-block;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 20px;
padding-right: 20px;
}
.logo {
float:left;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
padding-right: 100px;
}
.navibar li {
float: left;
}
.left-bar {
float: left;
}
.right-bar {
float: right;
}
.btn:link,
/*Prevents color change when clicked */
.btn:visited {
/*<a> is a inline element which doesn't allow padding, so need to change to inline-block */
/* 10 on top and bottom and 30 left and right */
font-weight: 300;
word-spacing: 3px;
font-family: brandon-grotesque;
text-decoration: none;
/*Takes away line on bottom of words */
transition: background-color 0.2s, border 0.2s, color 0.2s;
/* makes color subtly change instead of instantly. More applealing */
}
.btn-full:link, .btn-full:visited {
background-color: #fff;
/* From flat UI colors */
border: 1px solid #fff;
color: #fff;
margin-right: 10px;
}
.btn-ghost:link, .btn-ghost:visited {
border: 2px solid #fff;
color: #fff;
}
I might be wrong, but I am pretty sure Borders don't add padding or margin.
Filler text because Stack Overflow says I need more text. Really SO?
Simply use margin-top with negative border width
.btn-ghost:link, .btn-ghost:visited {
border: 2px solid #fff;
margin-top: -2px;
color: #fff;
}
Before the border they were aligned but the 2px border pushes the element down by 2px. You can move the item up or add an invisible border or margin to the other items if you like

Topnav gets messed up by border-right

Alright I am trying to make a header that is separated with a line between the links. Now I use border-right but then I mess up the 100%. I changed the width to 19% per link but then I don't fill up the entire 100%. I tried outline, but there seems no way to put the outline on the right side only. I am sure that I am not the first one to encounter this problem. What is the best solution?
a {
color: black;
}
#logoDiv {
padding: 35px 0 35px 35px;
background-color: #999;
}
#topNavUl {
height: 30px;
list-style-type: none;
padding: 0 0 0 0;
}
#topNavUl li {
height: 100%;
width: 19%;
float: left;
text-align: center;
}
#topNavUl .notLast{
border-right: 1px solid grey;
}
<div id="topNavDiv">
<ul id="topNavUl">
<li class="notLast">Home</li>
<li class="notLast">Clients</li>
<li class="notLast">Projects</li>
<li class="notLast">Coworkers</li>
<li id="lastTopNavLi">Contact</li>
</ul>
</div>

How do I display the bottom border of parent instead of top border of child?

Here is what I have - http://jsfiddle.net/SQApr/
CSS
/*
** MainNav is the div containing the navigation information
** This is defining overall size and shape
*/
#mainNav {
clear: both;
min-height: 40px;
width: 100%;
font-size: 18px;
position: relative;
}
/*
** Main list padding and style
*/
#mainNav ul {
padding: 0;
margin: 0 auto;
list-style: none;
}
/*
** Expand nav list for new information
*/
#mainNav ul:hover {height: 240px;}
/*
** Main item size and position
*/
#mainNav li {
float: left;
width: 19.805%;
height: 40px;
border-left: 1px solid #E8DEA5; /*******************************************/
border-right: 1px solid #E8DEA5; /* Make the border exist for sizing issues */
border-top: 1px solid #E8DEA5; /*******************************************/
}
/*
** Main item on hover
*/
#mainNav li:hover {
background-color: #ffffff; /* White */
border-left: 1px solid green;
border-right: 1px solid green;
border-top: 1px solid green;
border-bottom: 1px solid white;
}
/*
** Main item link formatting
*/
#mainNav li a {
margin: 0;
display: block;
line-height: 40px;
text-align: center;
text-decoration: none;
color: #000000; /* Black */
}
/*
** Main div position and bg color on list item hover
*/
#mainNav li:hover .mainDiv {
position: absolute;
left: 0;
background-color: #ffffff; /* White */
}
/*
** Any div within mainNav's li must have position relative
*/
#mainNav li div {
position: relative;
padding: 0;
margin: 0;
}
/*
** Main div position
*/
#mainNav li .mainDiv {
width: 1024px; /* Same as #wrapper in styles.css */
height: 200px;
left: -9999px;
border: 1px green solid;
}
#mainNav li .title {
clear: both;
position: relative;
top: 30px;
left: 50px;
font-size: 24px;
font-weight: bold;
color: #0b5a5a; /* Gray blue */
border-bottom: 2px solid #0b5a5a; /* Gray blue */
}
.navLinks li {
float: left;
display: block;
border: none;
}
HTML
<div style="width:1024px;">
<div id="mainNav">
<ul>
<li>Home
<div class="mainDiv">
<span class="title">Welcome to the website!</span>
<div style="border:red 1px solid;
top: 60px;
left: 60px;
width: 400px;
height: 80px;">
Here will be a paragraph filled with more information about what the site does
and how it will benefit the community and companies. Or anything else you
would like to say on every page.
</div>
<div style="border:red 1px solid;
clear: both;
top: -60px;
left: 600px;
width: 200px;
height: 80px;">
<ul class="navLinks">
<li>item 1</li>
<li>item 2</li>
<li>Third link</li>
</ul>
</div>
</div>
</li>
<li>Community
<div class="mainDiv">
<span class="title">Community</span>
Browse People & Companies</br>
Directory</br>
Make Your Voice Heard</br>
Forums
</div>
</li>
<li>Information
<div class="mainDiv">
<span class="title">Information</span>
First link</br>
List within a list
First link</a></br>
Second link</a></br>
Section Title</br>
Third link
</br>
Third link
</div>
</li>
<li>Business Opportunities
<div class="mainDiv">
<span class="title">Business Opportunities</span>
First link</br>
Second link</br>
Third link
</div>
</li>
<li>Support
<div class="mainDiv">
<span class="title">Support</span>
FAQs</br>
Site Map</br>
Third link
</div>
</li>
</ul>
</div>
</div>
When ever you roll over the list items to display the hidden div they contain, the top border of the div overlaps the bottom border of the list item. I need to reverse this to make it look like the list item opens up into the div.
Any ideas?
give the div that opens up a z-index: -1
like here: http://jsfiddle.net/SQApr/3/
You can use the z-index property to put the nav over the mainDiv, giving the mainDiv a lower value than the nav.
z-index at W3Schools
Change li:hover a - add white bottom border, make its position relative to add z-index
See: http://jsfiddle.net/SQApr/1/
By the way: I also had to add negative margin to li:hover .mainDiv
Edit:
Chanckjh version is much simpler than mine.

align a horizontals menu li items

I am having real troubles with trying to align a horizontal menu.So far my menu is looking like
I have 2 centered elements to make up the menu in the image you can see a gray border (slide-nav class) that has been centered within the page. Now I am trying to do the same for the menu
I have had to hard code the li widths but ideally I would like them to fit automatically. Is it possible without javascript to align the menu items in the center?
My html
<nav class="slide-nav">
<ul class="slider">
<li class="selected">
<div>
<span class="heart"></span>
<div>
Get Started</div>
</div>
</li>
<li>
<div>
<span class="price-tag"></span>
<div>
Get Results</div>
</div>
</li>
<li>
<div>
<span class="star"></span>
<div>
Track & Engage</div>
</div>
</li>
<li>
<div>
<span class="people"></span>
<div>
Features</div>
</div>
</li>
</ul>
</nav>
css
.slide-nav
{
border-bottom: solid 1px #f2f2f2;
margin: 0 auto;
width: 856px;
}
.slider
{
list-style: none;
height: 38px;
margin: 0 auto;
width: 722px;
}
.slider li
{
border-bottom: solid 7px transparent;
cursor: pointer;
display: inline-block;
width: 150px;
}
.slider li div
{
line-height: 31px;
}
.slider li div div
{
text-indent: 6px;
}
.slider li.selected > div
{
border-bottom: solid 7px #592970;
}
Here the CSS that u have to change with
.slide-nav
{
border-bottom: solid 1px #f2f2f2;
margin: 0 auto;
width: 856px;
text-align:center;
}
.slider
{
list-style: none;
height: 38px;
margin: 0;
padding: 0;
}
.slider li
{
border-bottom: solid 7px transparent;
cursor: pointer;
display: inline-block;
padding:0 10px;
}
I believe this has been answered in detail here.
Basically you want to have your individual buttons rendered with display:inline-block which would allow for them to be justified. There's a trick however with adding a "dummy" line break to force justification.
I just got rid of the widths, removed margin: 0 auto from .slider and added the ole text-align: center.
Check out a live demo:
http://jsfiddle.net/RJL7J/
Hope this helps.

Tabbed view of pages using css and javascript

I want to create a tabbed view of pages similar to that of the profile page of stack overflow, as can be seen in the image below.
I have been able to create a tabbed interface, but I am unable to remove the border below the tab, because the border has been actually given to the div below. If I give the border to the tab, then I can't extend the border over the area where there is not a tab.
Here is the html that I am using
<div id="centerDiv">
<div id="centeredMenu">
<ul class="tabs">
<li><a class="active" href="#">Questions</a></li>
<li>Blogs</li>
<li>Posts</li>
</ul>
</div>
</div>
<div style="clear:both;"></div>
<div class="favContentBox">
<!-- The content goes here -->
</div>
<div class="favContentBox">
<!-- The content goes here -->
</div>
<div class="favContentBox">
<!-- The content goes here -->
</div>
I have as many favContentBox as there are the ul li elements. And the javascript is
$(document).ready(function(){
var currentTab = 0;
function openTab(clickedTab) {
var thisTab = $(".tabs a").index(clickedTab);
$(".tabs li a").removeClass("active");
$(".tabs li a:eq("+thisTab+")").addClass("active");
$(".favContentBox").hide();
$(".favContentBox:eq("+thisTab+")").show();
currentTab = thisTab;
}
$(".tabs li a").click(function() {
openTab($(this));
return false;
});
$(".tabs li a:eq("+currentTab+")").click()
});
And the css goes like this
.favContentBox
{
border:1px solid #808080;
padding-left:20px;
padding-right:20px;
min-height: 500px;
}
.tabs
{
margin:0 0 0 0;
padding:0 0 0 0;
left:50%;
text-align:center;
clear:left;
position:relative;
float:left;
}
.tabs li
{
list-style: none;
float: left;
right:50%;
display:block;
position:relative;
}
.tabs li a
{
display: block;
color:black;
font-weight: bold;
text-align: center;
text-decoration: none;
width:100px;
padding: 5px 0 5px 0;
border-left: 1px solid #808080;
border-top: 1px solid #808080;
border-right: 1px solid #808080;
margin-left:20px;
background-color:#F0F0F0;
}
Add a white bottom border to the tab and make the tab one pixel smaller than its container (to account for the top border). Here's an all CSS solution for the tab hovering.
Demo: http://jsfiddle.net/ThinkingStiff/sCgMg/
HTML:
<ul id="tabs"><!--
--><li class="tab">summary</li><!--
--><li class="tab selected">answers</li><!--
--><li class="tab">questions</li><!--
--><li class="tab">tags</li><!--
--></ul>
CSS:
#tabs {
border-bottom: 1px solid #666666;
font: bold 15px/15px Helvetica, Tahoma, Arial;
height: 30px;
margin: 0;
padding: 0;
padding-left: 10px;
}
.tab {
color: #777;
cursor: pointer;
display: inline-block;
height: 23px;
font-size: 13px;
line-height: 13px;
margin-left: 2px;
margin-right: 2px;
padding-top: 8px;
text-align: center;
vertical-align: top;
width: 80px;
}
.tab:hover {
border: 1px solid #666666;
border-bottom: 1px solid white;
height: 22px;
margin-top: 5px;
padding-top: 2px;
width: 78px;
}
.selected {
border: 1px solid #666666;
border-bottom: 1px solid white;
color: black;
font-size: 15px;
line-height: 15px;
padding-top: 6px;
width: 78px;
}
.selected:hover {
height: 23px;
margin-top: 0;
padding-top: 6px;
width: 78px;
}
Script:
$( ".tab" ).click( function () {
$( ".selected" ).removeClass( "selected" );
$( this ).addClass( "selected" );
} );
Output:
(Don't just copy and paste! Read the explaination below first!)
HTML:
<ul>
<li>Tab 1</li>
<li>Tab 2</li>
<li>Tab 3</li>
</ul>
<div class="content-boxes">
<div class="content1">Content 1</div>
<div class="content2">Content 2</div>
<div class="content3">Content 3</div>
</div>
CSS:
ul li {
/* I've left out all the floating and other obvious stuff,
since you didn't ask for that */
position: relative;
top: 1px;
background-color: #fff;
border: solid 1px #808080;
border-bottom: none;
z-index: 2;
}
.content-boxes>div {
position: relative;
z-index: 1;
}
The essence of this code is:
Moving the tabs down by 1 pixel while leaving the content boxes' positions as they are with `position: relative; top: 1px;`
Giving the tabs a background color to cover up the content boxes' borders
z-index the tabs on top of the content boxes with `position: relative; z-index: 1/2;` (z-index only works on positioned elements)
I didn't test the code, so you will have to work out the details on your own. For example, this code would push all tabs down instead of just the active one. But I think you get the basic approach.
Hope this helps.