I am trying to add image/Icon to bootstrap dropdown btn list options HERE
It works somehow but as you can see from the demo and following image the hover function does not reacting (highlighting)on the whole li area!
Can you please let me know how to fix this highlits all width of the li element?
Here is my code as well
CSS:
li.one {
background-image: url("http://i1275.photobucket.com/albums/y443/Behseini/lister_zps15367983.png") !important;
background-repeat: no-repeat;
background-position: 5px 7px;
width: 60px;
height: 25px;
}
and the HTML
<div class="btn-group">
<button class="btn span2">Select</button>
<button class="btn dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li class="one">Item 1</li>
<li class="two">Item 2</li>
<li class="three">Item 3</li>
<li class="four">Item 4</li>
<li class="five">Item 5</li>
<li class="six">Item 6</li>
<li class="divider"></li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
Thanks
Using list item background as an icon is a bad idea since it makes laying on the text really tricky (as you experienced).
I'd definitely encourage you to add a new, separate element for the icons. By convention, icons are added in bootstrap in format <i class="icon-[name]"></i>. If you want custom icons, you can of course define your own classes and related CSS styles.
Here's a quick example:
HTML:
<li class="one"><i class="icon-custom-1"></i>Item 1
CSS:
.icon-custom-1 {
background-image: url("http://i1275.photobucket.com/albums/y443/Behseini/lister_zps15367983.png") !important;
background-repeat: no-repeat;
background-position: 0px 7px;
width: 60px;
height: 25px;
}
On a related note, you can wildcard all icon-* styles so you don't have to copy&paste the same stuff everywhere:
div[class*='icon-custom-'] {
/* Insert common CSS styles here */
}
Note that I'm using extra custom- to separate this custom icon formatting from icons provided natively by bootstrap.
Happy bootstrapping!
If you're simply looking to have the highlight extend to the right when hovered I would suggest removing the width: 60px; from each of your li.one, li.two etc.
Maybe add some extra margin on your li a selector as well to reduce the overlap.
Overall I would agree with jsalonen that you should look into utilizing the built-in icon code in Bootstrap.
Related
https://codepen.io/arandomcodepenuser/pen/NWjYGwo
Ok, so I have this top navbar, and the problem is that I can't change the html only the styling, because I am using a Wordpress plugin, and this navbar has block elements on the navbar, and there's one of them that has a dropdown within the element and not below, and I can't use javascript to change this, I am wondering if it's possible for the dropdown embedded within the li element to push down the other elements on the navbar when it appears on hover.
Here's the html:
<div>
<ul class="top-bar__menu">
<li id="menu-item-265276" class=""><span>Find Us</span></li>
<li id="menu-item-280208" class="">
<span>About</span>
<ul class="sub-menu">
<li id="menu-item-268209" class=""><span>About Us</span></li>
<li id="menu-item-265276" class=""><span>Find Us</span></li>
<li id="menu-item-280209" class=""><span>Our Team</span></li>
</ul>
</li>
</ul>
</div>
Here's the css styling for the dropdown menu:
.sub-menu {
display: block;
}
.sub-menu li {
clear:both;
width: 100%;
}
ul.sub-menu {
display: inline;
background-color: #fff;
max-width: 100px;
}
I'm trying to add sprite images to the menu items in wordpress/ubermenu.
The custom class:
#menu-item-4.sprite.icon-image a > img:first-child
{ background-position: -161px 0px!important; width: 22px; height: 22px;}
is applied to
id="menu-item-4"
It should affect only the first image element, instead the style is applied to most images menu-item-4.
How to select this specific image?
<ul class="menu-id-1">
<li id="menu-item-2">
<ul class="submenu-id-3">
<li id="menu-item-4" class="sprite icon-image"> <-- Costum CSS Class added here
<a href="">
<img> <-- CSS to select this element only
<span></span>
<span></span>
</a>
<ul class="menu-submenu-id-5">
<li id="menu-item-6">
<a href="">
<img> <-- This element will have other icon
<span></span>
<span></span>
</a>
</li>
<li d="menu-item-7">
<a href="">
<img>
<span></span>
<span></span>
</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Your CSS selector selects all img-tags, that are directly a child of an a-tag inside your #menu-item-4.
try this:
#menu-item-4 > a img
{ background-position: -161px 0px!important; width: 22px; height: 22px;}
Its probably better to add classes to a-tags or the img-tags
Remove the *:first-child at the end. Your > selector is searching for the first image that appears inside your anchor and the *:first-child selector is confusing its path since there are no child elements for this image.
Your selector should be something like this:
#menu-item-4.sprite.icon-image a > img
This literally means - find and apply only to, the first image that you come across.
I suggest that you add a class to your anchor and simply address that.
e.g.
#menu-item-4.sprite.icon-image .anchor-class > img
I added font-awesome icons to my navbar and styled it with css. All works well except on the link with the dropdown list - once clicked - it shows two icons instead of only one (see screenshot). One is properly placed and the other one appears below the word 'link' and above the dropdown menu.
Here is the html code:
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="active">Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
and here the css code:
ul li a:before {
font-family: "FontAwesome";
content: "\f067";
position: absolute;
top: 0;
left: 0;
display: block;
text-align: center;
color: #FFF;
width: 100%;
height: 100%;
margin-top: -26px;
}
I would greatly appreciate it if someone could tell me how to get rid of the icon (=white cross) under the word dropdown.
Thanks in advance for your help.
I think that you are seeing extra + icons because your css selector is incorrect. In actual fact you are probably getting 5 extra + icons (1 for each <a> in the dropdown menu).
To solve this you need to target only the <a>'s under the navbars <ul> not the dropdowns <ul>
try this selector: ul > li > a:before
EDIT
I have forked and corrected your bootply below:
http://www.bootply.com/OSTDVMekNE
The issue was on line 52 of your css (in bootply)
.cross a:before, .cross:hover > a:before {
should have been
.cross > a:before, .cross:hover > a:before {
The thing is that your CSS is applying to way more that you want it to. Your imbedded UL is also triggering your CSS rules. You probably have even more white crosses appearing but you can't see them because your background is white.You should apply a class to the links that you want to have your white cross and then apply the css rules only to that class.
I've got a WP theme built on TB. I'd like to make the menu navigation fixed at the top of the screen when scrolling. The creator didn't use the navbar class for the menu. Instead there's a #menu id, so using the usual navbar-fixed-top solution doesn't work. Here's the markup for the header below. I'm hoping someone can shed some light on how I can accomplish this, especially if it can be done using CSS customization. I'm new to all this, so please forgive any misuse of terms and correct me. Thanks very much!
<header style="opacity: 1; margin-top: 0px; ">
<div class="container">
<div class="row">
<div class="span3">
<div id="logo">
<a href="SITE URL">
</a>
</div>
</div>
<div class="span9">
<!-- Mobile Menu -->
<a id="mobile-nav" class="menu-nav" href="#menu-nav"><span class="menu-icon"></span></a>
<!-- Standard Menu -->
<div id="menu">
<ul id="menu-nav" class="sf-js-enabled">
<li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-9 current_page_item menu-item-14">Home<mark class="bar"></mark></li>
<li id="menu-item-266" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-266">About<mark class="bar"></mark></li>
<li id="menu-item-13" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-13">Blog<mark class="bar"></mark></li>
</ul>
</li>
<li id="menu-item-198" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-198">SITE NAME<mark class="bar"></mark>
<ul class="sub-menu sf-js-enabled" style="float: none; width: 20em; display: none; visibility: hidden; ">
<li id="menu-item-569" class="menu-item menu-item-type-post_type menu-item-object-portfolio menu-item-569" style="white-space: normal; float: none; width: 100%; ">PAGE NAME<mark class="bar"></mark></li>
<li id="menu-item-565" class="menu-item menu-item-type-post_type menu-item-object-portfolio menu-item-565" style="white-space: normal; float: none; width: 100%; ">PAGE NAME<mark class="bar"></mark></li>
<li id="menu-item-454" class="menu-item menu-item-type-post_type menu-item-object-portfolio menu-item-454" style="white-space: normal; float: none; width: 100%; ">PAGE NAME<mark class="bar"></mark></li>
</ul>
</li>
<li id="menu-item-265" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-265">Contact<mark class="bar"></mark></li>
</ul>
</div>
</div>
</div>
</div>
Finally after weeks of searching and trying out solutions to create a fixed navigation/menu bar in the Banshee theme, I've found it. For anyone else who's been trying to figure this out, I'm posting it below. The reason it's so difficult to find is that Banshee doesn't use the option built into Twitter Bootstrap (navbar-fixed-top). Instead, it uses the header as the part to alter to get this to work.
header {
position: fixed;
width: 100%;
height: 100px;
text-center;
background: #d6c493;
-webkit-box-shadow: 0px -2px 8px 2px #424756;
box-shadow: 0px -2px 8px 2px #424756;
z-index:999;
}
#media (min-width : 980px) {
#main {
padding-top: 80px;
}
}
EDIT: Someone else suggested the #media section so I could delete the top margin I had, and it works great.
This code also puts a subtle drop shadow under the header as well. Values of the header height and margin-top will have to be experimented with to make it work for individual sites in case that's been altered from the theme's defaults (mine was altered). The usual TB recommendation of adding padding to the body does not work with this solution since it doesn't use the navbar-fixed-top class.
Hope this helps someone else out. But…
NEW PROBLEM:
With the fixed menu, when I use a jQuery slider (Revolution Slider) the image placement is fine under the menu at desktop viewing size, but once I start resizing the window smaller, the images resize smaller, but start moving up under the fixed menu. I can't find a way to get them to stay in position under the menu. If I add any padding at all, even if I specify just for the top, it seems to always increase the space between the slider's bottom and the body. This is a responsive theme and the images are resizing responsively.
Help, please. Many thanks to anyone who takes a look.
This selects all <B> tags directly preceded by <A> tags:
A+B {
/* styling */
}
What is the selector for all <A> tags directly followed by <B> tags?
Here's sample HTML fitting my question:
<a>some text</a>
<b>some text</b>
Do you mean to style A given that it has a B element directly inside or followed? Like this:
<A>
<B>
</B>
</A>
// OR
<A>
</A>
<B>
</B>
You can't do such a thing in CSS (yet). Eric Meyer states that this kind of selector has been discussed quite a few times on the CSS mailing list, and isn’t doable. Dave Hyatt, one of the core WebKit developers, comments with a good explanation of why it can’t be done.
Check out: Shaun Inman's blog post and the comment by Eric Meyer.
David Hyatt weighs in, too.
You can’t in css.
Edit: To be a bit more helpful, if you use for example jQuery (a JavaScript library), you can use .prev().
You can ONLY do the converse: This selects all tags directly preceded by tags.
This is logically equivalent to your request.
I often use this to style a row of many checkboxes with labels
CSS:
label+input {
margin-left: 4px;
}
DOM:
<input id="a" name="a" type="checkbox"/><label for="a">...</label>
<input id="b" name="b" type="checkbox"/><label for="b">...</label>
<input id="c" name="c" type="checkbox"/><label for="c">...</label>
Although it's not very handy, nowadays you could achieve this behavior by reversing the order of your elements both when you generate the HTML and by applying the CSS rules: display: flex and flex-direction: column-reverse
ul {
display: flex;
flex-direction: column-reverse;
}
.b ~ .a {
color: red;
}
<ul>
<li class="a">A 3</li>
<li class="c">C 2</li>
<li class="c">C 1</li>
<li class="b">B 1</li>
<li class="a">A 2</li>
<li class="a">A 1</li>
</ul>
Also, if you have 2 or more inline elements, you could achieve it by applying float: right, as they will be displayed in reverse order:
ul {
float: left;
list-style-type: none;
}
li {
float: right;
}
li:not(:first-child) {
margin-right: 20px;
}
.b ~ .a {
color: red;
}
<ul>
<li class="a">A 3</li>
<li class="c">C 2</li>
<li class="c">C 1</li>
<li class="b">B 1</li>
<li class="a">A 2</li>
<li class="a">A 1</li>
</ul>
You can now use the :has() css selector (caniuse):
.first:has(+ .second) {
background: #ff0000;
}
That can be read: select all elements with class ".first" that are followed by element of class ".second"
<div class="first">Foo</div>
<div class="second">Bar</div>