How to combine :first-child and :hover? - html

I have an unordered list I'm using for a menu. Each item has a background image and a :hover image. The background image on the first element is different that the rest, so I use the following to style it, which works fine:
#prodNavBar ul:last-child li:first-child {...}
Since I want a roll-over image on this element as well, I've tried adding :hover, like so:
#prodNavBar ul:last-child li:first-child:hover {...}
...but this doesn't work. What's the syntax to combine :first-child and :hover?

Chaining :first-child and :hover as you do here should work just fine. If you're using IE6, however, only the last pseudo-class in the chain will be recognized.
In other words, you're doing it right.

li:first-child:hover should work. Which browser are you testing with? IE doesn't support last-child
Here is a sample test case.

SOLVED Similar Question Answered
.aston-menu-light>ul>li:last-child > a:hover {
color:red !important;
}

You can also use the following css code
#prodNavBar ul:last-child li:nth-child(2n-1):hover
#prodNavBar ul:last-child li:nth-child(2n):hover
I use this in my project
.buttons button:nth-child(2n) { background: white; border: 1px solid white; border-radius: 3px; box-shadow: 0 0 3px tomato; transition: box-shadow .2s ease-in-out; }
.buttons button:nth-child(2n):hover { box-shadow: 0 0 10px tomato; }
.buttons button:nth-child(2n):active { box-shadow: 0 0 10px tomato; border: 1px solid tomato; }
.buttons button:nth-child(2n-1) { background: white; border: 1px solid white; border-radius: 3px; box-shadow: 0 0 3px #39FF14; transition: box-shadow .2s ease-in-out; }
.buttons button:nth-child(2n-1):hover { box-shadow: 0 0 10px #39FF14; }
.buttons button:nth-child(2n-1):active { box-shadow: 0 0 10px #39FF14; border: 1px solid #39FF14; }
<div class="buttons">
<button type="submit">submit</button>
<button type="reset">reset</button>
</div>

Related

Cannot make the CSS button clickable

That's my first try:
.pricingTable-firstTable_table__getstart {
color: white;
background-color: #71ce73;
margin-top: 30px;
border-radius: 5px;
cursor: pointer;
padding: 15px;
box-shadow: 0px 3px 0px 0px #66ac64;
letter-spacing: 0.07em;
transition: all 0.4s ease;
}
<div class="pricingTable-firstTable_table__getstart" href="https://website.com">JOIN</div>
It doesn't click, and doesn't change anything, I appreciate the help
The usual way to achieve this is wrapping your div inside an a tag:
<a href="https://website.com">
<div class="pricingTable-firstTable_table__getstart">JOIN</div>
</a>
You could also solve this (less elegantly imo) using an onclick event in JavaScript:
<div class="pricingTable-firstTable_table__getstart" onclick="window.location.href='https://website.com';">JOIN</div>
If you want an anchor link to look like a button. Style it something like this:
Css
.link-button {
padding: 5px 10px 5px 10px;
border: 1px solid blue;
background-color: lightblue;
}
.link-button:hover {
background-color: blue;
cursor: pointer;
}
And the markup
<a class="link-button">Anchor as button</a>
But I prefer to use buttons for operations, and show navigation as anchors. Because people recognize them for that.

Does :focus work with specificity as :hover does?

Here is my problem. I want the input-group-addon that holds an icon (search icon, calendar icon, etc) to inherit the hover, focus, and active states of its input field by specificity. I have it working for hover but for some reason specificity is ignoring the focus state. I thought it was a conflicting css directive in my code but I isolated the problem in CODEPEN and it does it there as well.
In summary, I want the input group addon border to change to yellow seamlessly with its input field when I focus on it (tab or click), as it does when I hover on it.
My HTML:
<div class="input-group controls">
<input type="text" class="form-control" placeholder="Search by Name" />
<span class="input-group-addon right search"></span>
</div>
My CSS (Use Chrome if possible. I didn't include here the corssbrowser stuff to make it simpler to read) Also, this is originally built on SCSS:
.mar40 {
margin: 40px auto;
}
.form-control {
border-width: 2px;
border-color: #8f8f8f;
-webkit-box-shadow: none;
box-shadow: none;
color: #bbbbbb;
-webkit-border-radius: 34px;
-moz-border-radius: 34px;
-ms-border-radius: 34px;
border-radius: 34px;
background: #211E1E;
}
.form-control:focus,
.form-control:hover {
border-color: rgba(248, 151, 29, 0.77);
-webkit-box-shadow: none;
box-shadow: none;
outline: none;
transition: all 1s ease;
}
.form-control .input-group-addon {
background: #8f8f8f;
border-color: #555555;
border-width: 2px;
}
.controls .input-group-addon.right.search {
background: #30373e;
border: 2px solid #8f8f8f;
color: #bbbbbb;
border-left: none;
border-radius: 0px 20px 20px 0;
padding: 4px 10px;
min-width: 0;
}
.controls .input-group-addon.right.search:before {
content: "\f4a4";
font-family: 'Ionicons';
font-size: 16px;
}
.controls:focus .input-group-addon.right,
.controls:hover .input-group-addon.right,
.controls:active .input-group-addon.right {
border: 2px solid rgba(248, 151, 29, 0.77) !important;
border-left: none !important;
transition: all 1s ease;
}
.controls:focus .input-group-addon.right:before,
.controls:hover .input-group-addon.right:before,
.controls:active .input-group-addon.right:before {
color: rgba(248, 151, 29, 0.77);
transition: all 1s ease;
}
Desired effect illustration on hover/focus/active
This is what I am getting on focus
And the handy dandy CODEPEN
Thanks!
:focus applies for the input and not the parent container and so your selector group should be as follows. (Note the changed selector in the first line)
.form-control:focus + .input-group-addon.right,
.controls:hover .input-group-addon.right,
.controls:active .input-group-addon.right {
border: 2px solid rgba(248, 151, 29, 0.77) !important;
border-left: none !important;
transition: all 1s ease;
}
As far as I know, when you :hover the child you are also indirectly hovering on the parent and so the .controls:hover .input-group-addon.right also works when .form-control:hover is applicable. Thus both the .form-control and .input-group-addon.right get the border.
But when you focus on the .form-control, the focus selector applies only to the input and doesn't get applied to its container. Thus only the .form-control gets the border and not the .input-group-addon. So, the selector must be changed to style the .input-group-addon based on the input and not the container's focus.
CodePen Demo

CSS active is not working for selecting the tabs

Once we select the any tabs like account,bills,data,usage.Hovering working perfect.
But selected backgroundcolor is not active state,
Here is my css
.header :active, .footer:active {
border: none;
background:yellow;
box-shadow: 0px 0px 1px #777;
}
JSFiddle
Live demo
you should remove the space between header and :active
.header:active, .footer:active {
border: none;
background:yellow;
box-shadow: 0px 0px 1px #777;
}

How to reuse and override Css style?

ok, here is myResource.css
.gwtCellButton button {
margin: 0;
padding: 5px 7px;
text-decoration: none;
....more styles here...
}
.gwtCellButton button:active {
border: 1px inset #ccc;
}
.gwtCellButton button:hover {
border-color: orange;
color: orange;
}
Now I want to have .gwtCellButtonSmall that is exactly like .gwtCellButton except that it has padding: 1px 2px;
Ofcourse if i do like this, then I can duplicate code:
.gwtCellButtonSmall button {
margin: 0;
padding: 1px 2px;
text-decoration: none;
....more styles here...
}
.gwtCellButtonSmall button:active {
border: 1px inset #ccc;
}
.gwtCellButtonSmall button:hover {
border-color: orange;
color: orange;
}
If I understand your question correctly, you want to have two elements with similar styles with one having different padding.
Is so, you can share styles between the two elements:
.gwtCellButton button, .gwtCellButtonSmall button{
margin: 0;
padding: 5px 7px;
text-decoration: none;
...
}
Then use !important to override the padding for the specific element:
.gwtCellButtonSmall button{
padding: 1px 2px !important
}
Or you could use something like Sass.
You should not need to duplicate any code or, worse, use !important.
This problem can be solved through the use of modifier classes by specifying two classes on each HTML element: a base gwtCellButton class and a modifier class (regular and small in this example).
.gwtCellButton button {
margin: 0;
text-decoration: none;
}
.gwtCellButton.regular button {
padding: 5px 7px;
}
.gwtCellButton.small button {
padding: 1px 2px;
}
Using the !important declaration unnecessarily can lead to specificity issues down the line.
Use !important. The property which has !important overrides the exactly property if there are any other.
So your case,
padding: 1px 2px!important;
Heavily using them causes you some problems sometimes. Thus, do not forget to have a quick look at this summary too.

position of website elements

I have an issue with rendering my website for IE, Chrome and Opera. In Firefox the positioning works well:
while in the other browsers it looks like crap:
I have tried several positioning and padding options, but no luck. The problems appeared as I replaced the drop down menu with a jQuery replacement to enhance it graphically. The original dropdown is still there but with the css-option "display: none". I'd be thankful for a hint!
Here is the css:
This is the big blue box
.searchHomeForm a, .searchHomeForm a:hover {
color:#000000;
}
A invisible box around the three elements
div.searchHomeForm , .searchform {
height: 37px;
margin-left: auto;
margin-right: auto;
}
The white search bar
.search_bar {
position: inherit;
height: 25px;
letter-spacing: 0.02em;
line-height: 25px;
padding: 9px 0 0px 9px;
width: 390px;
border: 1px solid #95B6D6;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.11) inset;
border-radius: 0.25em 0 0 0.25em;
}
the jQuery Dropdown replacement
#searchformReplacement {
background: #EBEBEB;
padding: 0px 1px 5px 0;
margin-bottom: 3px;
border-top: 1px solid #95B6D6;
border-bottom: 1px solid #95B6D6;
width: 109px;
position: inherit;
}
the find button
.find_button {
background: url("../images/lupevufindsearchsubmit1.png") no-repeat scroll #bBbBbB;
-moz-border-radius: 0.25em;
border-radius: 0 0.25em 0.25em 0;
position: inherit;
height: 36px;
line-height: 36px;
margin: 0px 0 3px -1px;
padding: 4px 10px 4px 10px;
width: 60px;
border-top: 1px solid #95B6D6;
border-right: 1px solid #95B6D6;
border-bottom: 1px solid #95B6D6;
border-left: none;
box-shadow: 2px 2px 5px rgba(76, 133, 187, 0.50) inset;
transition: all 0.2s ease-in-out 0s;
}
Try removing position: inherit from the .search_bar {}, #searchformReplacement {}and .find_button {} add display:inline-block for each
or add display:inline and float:left for each. You may have to clear floats if you use float:left
maybe use float: left; on the three elemetns next to each other?
I made you a little example to have the required position, I'm using the inline-block propriety (and I love it) :
Html
<div id="container">
<input type="text" class="inline-block" />
<div class="inline-block">
Your custom select
</div>
<button type="submit" class="inline-block">Search</button>
</div>
CSS
.inline-block {
display:inline-block;
*display:inline; /*IE hack*/
*zoom:1; /*IE hack*/
}
#container {
background:lightBlue;
width:300px;
margin:0 auto;
text-align:center;
}
See the working fiddle !
Yes, clearing your floats are important as madhushankarox has pointed out. But you don't always need to use floats, especially not in your case. Plus here's an extra bonus if you ever need to place your form into a liquid layout page. It should proportion itself out equally on most screens that are wide or thin.
CSS
/*the blue rounded box*/
#bluebox {
padding:3% 5%;
margin:0 25%;
background:#d0dcea;
border:solid 1px #b7c2d2;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
.fieldset-search {
text-align:center;
}
/*The white search bar*/
.input-search {
padding:5px;
margin:0;
width:50%;
vertical-align: baseline;
border: solid 1px #b7c2d2;
background: #fff;
outline: 0;
}
/*the jQuery Dropdown replacement*/
.list-search {
padding:4px;
margin:0 0 0 -5px;
}
/*the find button*/
.submit-search {
padding:4px 10px;
margin:0 0 0 -5px;
}
HTML
<div id="bluebox">
<div class="fieldset-search">
<input type="text" name="search" class="input-search">
<select name="list" class="list-search"><option></option></select>
<button type="search" class="submit-search">Go</button>
</div>
</div>