I am trying to build a navigation menu using nested lists, however whenever I set a height for the li's it breaks the lists and the sub menus lay over the final li, I have link to what I mean,
Nested List Example
How can I fix my code so I achieve something similar to the following?
List item
List item
Sub List item
Sub List item
Sub List item
Sub List item
List item
Change your CSS to this.
.seconday_nav {
width: 95px;
float: left;
margin: 32px 0px 0px 0px;
}
ul.subnav {
margin-left: 60px;
}
.seconday_nav ul.subnav li {
width: 93px;
text-align: right;
padding: 10px 0px;
border: 1px solid green;
display: block;
height: 25px;
}
.seconday_nav ul li a, .seconday_nav ul.subnav li a {
background-image: -webkit-gradient(linear, left top, right top, color-stop(0.35, white), color-stop(0.68, #f4f5f5));
background-image: -moz-linear-gradient(left center, white 35%, #f4f5f5 68%);
display: block;
width: 100%;
height: 100%;
padding: 0px 10px 0px 10px;
}
What I did, is put a margin-left of 60 only on your sub navigation. This now pushes that UL out from the left and gives it the appearance your looking for.
Several problems here:
.seconday_nav {
width: 95px;
float: left;
margin: 32px 0px 0px 0px; }
.seconday_nav ul li, .seconday_nav ul.subnav li {
width: 93px;
text-align: right;
padding: 10px 0px;
border: 1px solid green;
display: block;
height: 25px; } /* PROBLEM 1 */
.seconday_nav ul li a, .seconday_nav ul.subnav li a {
background-image: -webkit-gradient(linear, left top, right top, color-stop(0.35, white), color-stop(0.68, #f4f5f5));
background-image: -moz-linear-gradient(left center, white 35%, #f4f5f5 68%);
display: block;
width: 100%; /* PROBLEM 2 */
height: 100%;
padding: 0px 10px 0px 10px; }
Problem 1: you are giving height of 25px to element which contains all sublist items .seconday_nav ul li affects li that contains subnav.
Problem 2.: You are giving padding to element which width is declared to 100% which always gives 100% of parent + padding so it overflows parent. Since you already give a elements display: block there is no need to give them 100% width, only height.
That should help you start solve your problem :)
Related
My goal is to prevent box-shadow from overlapping on top of nearby elements by using :before and z-index.
But the shadow is going underneath the container of the list item that casts it because of the z-index.
It works fine if its parent container is just the body.
Is there a workaround regarding this or should I change my HTML and CSS
HTML (PUG)
div#main
ul
li
li
li
CSS (Stylus)
#main
background-color lightyellow
height 300px
width 300px
ul
padding 10px
li
background-color lightblue
height 50px
width 50px
margin 10px
position relative
&::before
content ''
box-shadow 0px 0px 15px 20px rgba(0,0,0,0.5)
position absolute
top 0px
right 0px
bottom 0px
left 0px
z-index -1
you are using an absolutely positioned pseudo elements without setting position: relative to its parent, i.e. why its causing this type of issues also you haven't set some basic CSS rules for a better results as:
Code Snippet
html,
body {
margin: 0;
padding: 0;
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#main {
background-color: lightyellow;
height: 300px;
width: 300px;
}
ul {
padding: 10px;
margin: 0;
position: relative;
}
ul li {
background-color: lightblue;
height: 50px;
width: 50px;
margin: 10px;
position: relative;
overflow: hidden;
}
ul li::before {
content: '';
box-shadow: 0px 0px 15px 20px rgba(0, 0, 0, 0.5);
position: absolute;
top: 0px;
left: 0px;
display: inline-block;
width: 100%;
height: 1px;
}
<div id="main">
<ul>
<li>List01</li>
<li>List02</li>
<li>List03</li>
</ul>
</div>
I found an answer, I don't know if this is the best way to go
HTML (PUG)
ul
li
div.content
span All
li
div.content
span By
li
div.content
span Myself
li
div.content
span ANYMORE!!!
CSS (STYLUS)
body
margin 15px
ul
display inline-block
li
width 120px
height 50px
.content
background-color lightyellow
border 1px solid rgba(0,0,0,0.85)
widows 100%
height 100%
position relative
&::after
box-shadow 0px 0px 15px 5px rgba(0,0,0,0.5)
position absolute
top 0
right 0
left 0
bottom 0
content ''
z-index -1
span
position absolute
top 50%
left 50%
transform translate(-50%, -50%)
I am trying to make a tabbed interface so that there is no line underneath the selected tab, regardless of the font size of the text inside the tab, and using only CSS2. I added a bottom border but am not sure how to remove the bottom border underneath the selected tab. If I try a negative margin it simply adds a space between the bottom border and the tabs. I could try using an image to create the bottom border instead of using the bottom-border CSS feature; however, I'm trying to avoid this. Any ideas?
http://jsfiddle.net/yet5uehy/
HTML:
<body>
<div id="tabs">
<ul>
<li><span>Tab1</span></li>
<li id="selected"><span>Tab2</span></li>
<li><span>Tab3</span></li>
</ul>
</div>
</body>
CSS:
body {
/* Centers and adjusts length of the line that is
separating the tabs from the rest of the page */
margin-left: auto;
margin-right: auto;
width: 98%;
}
#tabs {
float: left;
width:100%;
font: 12px Arial;
/* Adds line separating tabs from rest of page */
border-bottom-style: solid;
border-bottom-color: #cccccc;
border-bottom-width: 1px;
}
#tabs ul {
list-style: none;
margin: 0;
/* Adds padding on sides of the entire tabbed bar */
padding:5px 5px;
}
#tabs ul li {
float:left;
background-image: url('righttab.jpg');
background-repeat: no-repeat;
background-position: right top;
/* Adds space between each tab */
margin:0px 3px;
padding:0;
}
#tabs ul li a {
display: block;
float:left;
text-decoration: none;
color: #000000;
background-image: url('lefttab.jpg');
background-repeat: no-repeat;
background-position: left top;
/* Adds padding on sides of hyperlink area
to reveal curved edges of tab */
padding:0px 3px;
margin:0px;
}
#tabs ul li a span {
float: left;
background-image: url('midtab.jpg');
background-repeat: repeat-x;
background-position: center top;
/* Adds padding between the tab text
and the edges of the tab */
padding:3px 5px;
margin:0px;
}
/* Formatting for selected tab */
#tabs li#selected {
background-image: url('right-selected.jpg');
background-repeat: no-repeat;
background-position: right top;
}
#tabs li#selected a {
display:block;
font-weight: bold;
background-image: url('left-selected.jpg');
background-repeat: no-repeat;
background-position: left top;
}
#tabs li#selected a span {
background-image: url('mid-selected.jpg');
background-repeat: repeat-x;
background-position: center top;
}
Here you go: http://jsfiddle.net/th8bucda/
I modified the end of your css for the selected item:
#tabs li#selected a {
display:block;
font-weight: bold;
background-image: url('http://s10.postimg.org/kberhjcr9/left_selected.gif');
background-repeat: no-repeat;
background-position: left top;
**border-bottom-style: solid;
border-bottom-color: #fff;
border-bottom-width: 5px;
margin-bottom:-5px;**
I created a fiddle with what I guess can help you in the right direction. Because I have no clue how your images look like, this fiddle is without images.
The only modified CSS is:
#tabs li#selected {
background-image: url('right-selected.jpg');
background-repeat: no-repeat;
background-position: right top;
/* added: */
background-color: #ffffff;
height:21px; // one pixel more then original tab
position: relative;
margin-top:-1px;
top:1px; // position tab over bottom border
}
See fiddle: http://jsfiddle.net/hf5th1wz/
I want to contain the teal hover within the borders of my social media links. I’ve tried adjusting the padding and heights and widths via CSS properties but when hovering, it still overlaps over the right border.
This is what it looks like while not hovering:
This is what it looks like when hovering:
The image sizes are each 19px × 15px.
#box {
width: 200px;
height: 50px;
background-clip: padding-box;
position: relative;
margin: 0;
left: 1.4em;
background: rgba(0, 0, 0, 1);
float: right;
z-index: 200;
}
#boxlist li {
height: 50px;
width: 20px;
position: relative;
list-style-type: none;
display: inline-block;
bottom: 1em;
margin-left: -2.5em;
float: left;
}
.imgli:hover {
background: rgba(0, 255, 255, 1);
}
.imgli {
border-left: 1px solid rgba(153, 153, 153, 1);
padding-right: 4em;
}
.imgli:first-child {
left: -0.1em;
border: none;
}
.imgli:nth-child(2) {
left: 1em;
}
.imgli:nth-child(3) {
left: 2em;
}
<header>
<div id="box">
<ul id="boxlist">
<li class="imgli"><img src="images/banner-social-icon-twitter.png" class="boximg"></li>
<li class="imgli"><img src="images/banner-social-icon-facebook.png" class="boximg"></li>
<li class="imgli"><img src="images/banner-social-icon-email.png" class="boximg"></li>
</ul>
</div>
</header>
The overlapping is happening, I believe, because of the
margin-left:-2.5em combined with the fixed width of the container, you are still experiencing overlap, despite the fact that your elements are floating.
Without doing a detailed lookover of your layout, one solution is to apply a background color to your <li>s to prevent the overlap, see the update I made to your fiddle:
http://jsfiddle.net/VVj3R/1/
I just added the background line to .imgli's definition and it seems to work.
.imgli {
border-left: 1px solid rgba(153,153,153,1);
padding-right:4em;
background-color:black;
}
You may want to change black to something else, as long as its an opaque color.
PS the images didn't show up in your fiddle because you used relative path names.
Try making your code bit simpler.. like this:
<div id="box">
<ul>
<li><div class="button" id="btn1"></div></li>
<li><div class="button" id="btn2"></div></li>
<li><div class="button" id="btn3"></div></li>
</ul>
</div>
CSS:
#box ul {
margin: 20px;
padding: 0px;
}
#box li {
float: left;
display: block;
background: #ededed;
padding: 1px;
}
#box .button {
width: 50px;
height: 50px;
background-color: #000;
}
#box .button:hover {
background-color:rgba(0,255,255,1);
}
#btn1 {
background-image: url(someicon.png);
background-repeat: no-repeat;
background-position: center center;
background-size: 40px 40px;
}
Here is fiddle:
http://jsfiddle.net/tb2Ug/
I have a list of nav items that I want to eventually be able to swipe through so I've created an unordered list which initially has a width of 1000% for testing and the links are positioned inline-block. This works well if there are enough links to fill the whole width of the page but if there is only a few links they get stuck to the left of the nav, ideally what I would like to do is have these centered. Ive tried adding text-align: center to the nav but this centers the links in the 1000% wide space and not the 100% page width. Can anyone recommend a solution as I thought this may be achievable with just CSS
JS Fiddle (with just a few links): http://jsfiddle.net/HS4VE/
CSS
nav {
padding: 10px 0;
overflow: hidden;
text-align: center;
border: 1px solid #cccccc;
border-left: 0;
border-right: 0;
}
nav li {
display: inline-block;
vertical-align: middle;
zoom: 1;
margin-right: -4px;
position: relative;
}
nav a {
color: white;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #454545), color-stop(100%, #363636));
background-image: -webkit-linear-gradient(#454545, #363636);
background-image: -moz-linear-gradient(#454545, #363636);
background-image: -o-linear-gradient(#454545, #363636);
background-image: linear-gradient(#454545, #363636);
font-size: 14px;
height: 25px;
line-height: 25px;
padding: 0 15px;
width: 186px;
display: block;
border-right: 1px solid white;
text-align: center;
}
nav a.is-active {
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fe57ae), to(#fe329b));
background-image: -webkit-linear-gradient(#fe57ae, #fe329b);
background-image: -moz-linear-gradient(#fe57ae, #fe329b);
background-image: -o-linear-gradient(#fe57ae, #fe329b);
background-image: linear-gradient(#fe57ae, #fe329b);
}
.inner {
width: 1000%;
}
Use this:
.inner {
white-space:nowrap;
max-width: 1000%;
}
Demo: http://jsfiddle.net/HS4VE/3/
see jsFiddle example here
I'm applying padding-top to an li to try to align the text nearer to the bottom. But it's just making the li bigger, even though there seems plenty of room to fit the text.
Any ideas?
<ul>
<li class="padded">x</li>
<li>x</li>
</ul>
li {
width: 25px;
height: 25px;
border: solid 1px black;
display: inline;
margin: 0 2px 0 0;
float: left;
}
.padded {
padding: 3px 0 0 0;
text-align: center;
}
I get the same results in IE7 and Chrome, not checked any other browser.
The li.padding is growing larger because you have a height of 25px plus a padding-top of 3px.
The you should decrease the height of the li.padding if you want to increase the top-padding, yet have it remain the same height as the plain list item. So to have a 25px high block with 3px padding-top, you should set the height to 22px with a padding of 3px.
li {
width: 25px;
height: 25px;
border: solid 1px black;
display: inline;
margin: 0 2px 0 0;
float: left;
}
.padded {
padding-top: 3px;
height:22px /* original height (25px) minus padding-top (3px) */
text-align: center;
}