Unique ID CSS | Why is my styling being picked up elsewhere? - css

A tricky one here.
I have styling for two UL's on a page which both contain anchors.
Each of the UL's have their own specific ID and specific styling which is all correct.
Here is the confusing part - say I have this:
#nav {
margin: 20px 0 0 0;
}
#nav li {
float: left;
}
#nav li a {
display: block;
text-transform: uppercase;
color: #555454;
font-size: 14px;
padding: 11px 17px;
}
And then this:
#gt-list
{
margin: 10px 0 0 0;
}
#gt-list li, a
{
color: #fff;
margin: 0 0 10px 0;
}
#gt-list li a:hover
{
color: #ff6b00;
}
#gt-list li img
{
float: left;
margin: 0 15px 0 0;
width: 20px;
}
#gt-list li span
{
float: left;
display: inline-block;
margin: 2px 0 0 0;
}
Here is HTML to go with:
<ul id="nav">
<li class="selected">
<a href="#">
Home
</a>
</li>
<li>
<a href="#">
About us
</a>
</li>
<li>
<a href="#">
Ways to give
</a>
</li>
<li>
<a href="#">
Our Work
</a>
</li>
<li>
<a href="#">
News
</a>
</li>
<li>
<a href="#">
Learn
</a>
</li>
<li>
<a href="#">
Contact Us
</a>
</li>
</ul>
The above is actual styling used on a site.
So here is my issue: the #nav is picking up the LI styling from #gt-list along with anchor styling.
I have inserted all parent div ID's to each UL and this had no affect.
I don't understand this!?!?

This rule has a comma in it, which means it will be applied to all li elements under the one with that id AND all anchor elements, regardless of where they are.
#gt-list li, a

The culprit is:
#gt-list li, a
{
color: #fff;
margin: 0 0 10px 0;
}
The comma between li and a causes the styles specified to be applied to a globally as it denotes:
All li within #gt-list AND all a.
Whereas what you want it to read is:
All li AND a within #gt-list
Change it to
#gt-list li a
{
color: #fff;
margin: 0 0 10px 0;
}

Related

Weird padding / spacing in list design

I've been working on a design with three links spanning the width of the device on mobile. I can't figure out why I can't get the spacing right. What looks off?
Here's the design :
And here's what the coded version is looking like :
Here's my CSS :
.b-nav-Wrapper {
width: 100%;
}
.b-nav {margin: 0 auto;}
.b-nav ul {
list-style: none;
}
.b-nav ul li{
display: inline-block;
width: 33.33%;
}
.b-nav ul li a{
text-decoration: none;
color: rgb(151,151,151);
}
.navNumber {
float: left;
width: 20%;
font-family: "korolev-condensed",sans-serif;
font-size: 2.5875em;
opacity: .50;
}
.navLink {
float: right;
width: 65%;
padding-top: 4px;
font-family: "mrs-eaves-xl-serif",sans-serif;
font-size: 1.2em;
line-height: 1em;
font-style: italic;
font-weight: 500;
}
*edit: here's my HTML :
<nav class="b-nav-Wrapper cf">
<div class="b-nav">
<ul>
<li class="active">
<a href="#">
<p class="navNumber active">01</p>
<p class="navLink active">Now Reading</p>
</a>
</li>
<li>
<a href="#">
<p class="navNumber">02</p>
<p class="navLink">Browse My Books</p>
</a>
</li>
<li>
<a href="#">
<p class="navNumber">03</p>
<p class="navLink">Notes & Quotes</p>
</a>
</li>
</ul>
</div>
</nav>
You didn't put your html, that makes us guessing about it. But if .b-nav ul li is referred to numbered parts, you should try width less than 33.33%. Because just 1px margin or padding of other elements cause it to break into two lines. If it doesn't solve, put your link or html.

How can I make the whole area of an unorderd list clickable?

I would like to make the entire area of my un ordered list clickable for a single URL. So far without luck.
The CSS markup so far is as follows:
#artListContainer {
margin: 0 0 0 0;
}
#artListContainer ul {
list-style-type: none;
width: 590px;
margin: 20px 0 0 0;
}
#artListContainer h3 {
font: bold 18px/1.5 Helvetica, Verdana, sans-serif;
color:#333333;
}
#artListContainer li img {
float: left;
margin: 0 15px 0 0;
}
#artListContainer li p {
font: 200 12px/1.5 Helvetica, Verdana, sans-serif;
}
#artListContainer li {
padding: 10px;
overflow: auto;
}
#artListContainer li:hover {
background: #eee;
cursor: pointer;
}
My HTML markup currently looks like this:
<div id="artListContainer">
<ul>
<li>
<img src="themes/default/templates/articles/articlethumbs/8.png">
<h3>Title goes here</h3>
<p>description goes here.</p>
<span style="font-weight:bold">Views: </span>(327)
<span style="font-weight:bold">Comments: </span>(4)
<span style="font-weight:bold">Likes: </span>(4)
</li>
</ul>
</div>
Many thanks in advance for any help or suggestions.
This is a thing.
<a href="#">
<ul>
<li>Stuff</li>
<li>Stuff</li>
<li>Stuff</li>
<li>Stuff</li>
</ul>
</a>
As above you can wrap an anchor tag around everything. That's only valid code from HTML5 so if you are using HTML4 it won't validate.
It is poor for accessibility doing it that way though. Ideally you should have a single link and bind its href to the container element with Jquery.

how to overlap a list of menus over an image

When the menu "product" is clicked or mouse over, the another list of menus appear.. but the image block which is below the menu bar, moves away from the position. if i use css [ position:absolute;], then the image box remains static and the product's sub-menu overlaps the image block, which is what i wanted. but the image blocks width & height settings change drastically, thereby spoiling the alignment.
pls chk the codings in jsFiddle
.home_menu {
border: 1px solid black;
width: 98%;
height: 3.3%;
margin-right: auto;
margin-left: auto;
}
div#menuDemo {
clear: both;
//border:1px solid black;
height: 78%;
width: 100%;
position: relative;
left: 0;
top: 0;
background-color: #A55927;
/*Remove this next one in production - Used for demo purpose only*/
margin-bottom: 0.1%;
padding-top: 0.7%;
z-index: 4;
}
div#menuDemo ul {
list-style: none;
margin: 0;
padding: 0;
background-color: #A55927;
}
div#menuDemo > ul > li {
float: left;
text-align: center;
}
div#menuDemo ul li {
width: 25%;
//border: 5px solid purple;
}
div#menuDemo ul li a {
text-decoration: none;
font-weight: bolder;
text-align: center;
}
div#menuDemo > ul > li > ul {
display: none;
text-align: center;
}
div#menuDemo > ul > li:hover > ul {
display: block;
text-align: center;
}
.sub1 {
width: 100%;
//border:1px solid green;
}
.colouring {
color: black;
font-weight: bolder;
}
.colour {
//border:1px solid blue;
color: black;
text-align: center;
//width:100%;
}
.wrapper {
border: 5px solid pink;
width: 98.8%;
height: 82%;
margin-top: 1%;
z-index: 2;
}
.uniform_block {
border: 5px solid green;
width: 100%;
height: 40%;
cursor: pointer;
}
.uniform_block img {
width: 100%;
height: 100%;
}
<body>
<div class="home_menu">
<div id="menuDemo">
<ul>
<li id="homeMenu">About Us
</li>
<!-- <li >About Us</li> -->
<li>Products
<ul class="sub1">
<li> Uniforms
<ul>
<li> &nbsp
</li>
<li> Automobile Industry Uniforms
</li>
<li> Pharmaceutical Uniforms
</li>
<li> Food Industry Uniforms
</li>
<li> Government Sector Uniforms
</li>
<li> School/College Uniforms
</li>
<li> &nbsp
</li>
</ul>
</li>
<li>Shoes
<ul>
<li> &nbsp
</li>
<li> Industrial Shoes
</li>
<li> Safety & Security Shoes
</li>
<li> Executive Shoes
</li>
<li> &nbsp
</li>
</ul>
</li>
</ul>
</li>
<li>Contact Us
</li>
</ul>
</div>
</div>
<div class="wrapper">
<div class="uniform_block">
<img src=" http://t0.gstatic.com/images?q=tbn:ANd9GcSH-kRi3rkVciPcH_c6dDJJI6C1ntzwcKl9MoVQIyuKk8F7unpf" />
</div>
<div class="home_footer">
<div class="footer_contents"></div>
</div>
</div>
</body>
kindly help. My requirement is, when i mouse over the "product menu", the drop down menu should be viewed above the image block which is below the menu bar.
Add position:absolute to the css of your ul menu (in your case, the sub1 class), and remove the width:100% so it can inherit the default width of its parent. Absolute positioning will prevent your browser from trying to put your ul element after the previous element on the page.
ul.sub1 {
position:absolute;
}
http://jsfiddle.net/C2YXp/2/

Horizontal navigation can't align to right

I know this has been discussed here before - as I've read through a lot of questions about the same thing. And have tried the solutions, but I just can't seem to make this stupid nav right align (needing li blocks to align to the right). Can someone please point out my mistake - thank you.
http://jsfiddle.net/gstricklind/vP38J/4/
CSS
ul#menu-main-top {
float: right;
}
.nav-bar > li {
border: 1px solid #333;
display: block;
float: left;
line-height: 38px;
margin: 0;
padding: 0;
position: relative;
}
ul#menu-main-top li a {
color: #222222 !important;
}
.top-nav > li > a {
color: #E6E6E6 !important;
}
.nav-bar > li > a:first-child {
margin: 0 0 0 10px;
padding: 0 0 0 30px;
}
.nav-bar > li > a:first-child {
display: block;
font-size: 14px;
padding: 0 20px;
position: relative;
text-decoration: initial;
}
​HTML
<div class="eight columns">
<ul id="menu-main-top" class="top-nav nav-bar hide-for-small">
<li id="menu-item-58">
Home
</li>
<li id="menu-item-94">
Calendar
</li>
<li id="menu-item-59">
Meanings
</li>
<li id="menu-item-77">
About Us
</li>
<li id="menu-item-67">
Contact Us
</li>
<li id="menu-item-343" class="active">
My Account
</li>
<li class="logout">
Logout
</li>
</ul>
</div>
Is this what you were trying to do?
http://jsfiddle.net/vP38J/5/
Relevent changed code:
.nav-bar > li {
border:1px solid #333;
display:block;
float: right;
line-height:38px;
margin:0;
padding:0;
position:relative;
}
Also, if you are looking to have the order remain the same, just reverse the order of the list in HTML.

Odd Internet Explorer 7 bug; not calculating padding on links correctly

It would appear that I am suffering from a new bug in IE7, as I can't seem to find any reference to it anywhere else. It is best explained using screenshots, so here are a couple of links (and as a note, it's not a requirement for it to work in IE6, so I don't even want to know what it looks like under that!):
How it should be displayed (using Safari 4):
http://dl-client.getdropbox.com/u/45961/safari4.png
How IE7 is displaying it:
http://dl-client.getdropbox.com/u/45961/ie7.png
Here's the CSS for that menu chunk:
#mm #leftNav .navigation {
width: 100%;
margin-bottom: 0;
float: left;
}
#mm #leftNav li {
list-style: none;
display: inline;
margin: 0;
}
#mm #leftNav .navigation li ul {
display: none;
}
#mm #leftNav .navigation li a {
text-decoration: none;
color: #ffffff;
font-size: 11pt;
padding-left: 20px;
}
#mm #leftNav .navigation li {
cursor: pointer;
margin-right: 4px;
padding-left: 8px;
padding-right: 8px;
padding-top: 10px;
padding-bottom: 8px;
overflow: visible;
}
.menu_item {
background: #419185;
}
.menu_item:hover {
background: #48a093;
}
.currentcat {
background-color: #4aa8a6;
}
.currentcat:hover {
background: #4aa8a6;
}
And here is the HTML:
<div id="mm">
<div id="leftNav">
<ul class="navigation">
<li class="menu_item">
<a class="icon icon-base">Base</a>
</li>
<li class="menu_item">
<a class="icon icon-devices">Devices</a>
</li>
<li class="menu_item">
<a class="icon icon-management">Management</a>
</li>
<li class="menu_item">
<a class="icon icon-iptools">IP Tools</a>
</li>
<li class="menu_item">
<a class="icon icon-config">Configuration</a>
</li>
<li class="menu_item">
<a class="icon icon-admin">Administration</a>
</li>
</ul>
<div id="subnav"></div>
</div>
</div>
Any ideas?
top and bottom padding are not supported on inline elements (some browsers will render it, others won't)
Here's a good article on the problem:
http://www.maxdesign.com.au/presentation/inline/
If you really need correct padding, you should change the menu items to "display:block" and "float:left"
Hehe, activa beat me to it.
Indeed, move your margin/padding to the A element, kinda like so:
mm #leftNav .navigation li a {
text-decoration: none;
color: #ffffff;
font-size: 11pt;
display:block;
float:left;
background: #419185;
margin-right: 4px;
padding-left: 20px;
padding-right: 8px;
padding-top: 10px;
padding-bottom: 8px;
}
mm #leftNav .navigation li {
cursor: pointer;
}
.menu_item {
}

Resources