20

I have the following piece of HTML/CSS code which is used to display pages based on the number of rows retrieved from a database.

.paginate {
    font-family:Arial,Helvetica,sans-serif;
    padding:3px;
    margin:3px;
}

.disableCurrentPage {
    font-weight:bold;
    background-color:#999;color:#FFF; 
    border:1px solid #999;
    text-decoration:none;color:#FFF;
    font-weight:bold;
}

.paging {
    cursor: pointer; 
    background-color: transparent;border:1px solid #999;
    text-decoration:none;
    color:#9CC;
    font-weight:bold;
}
<div class='paginate'>
    <input type="submit" name="btnFirst" value="First" 
           class="disableCurrentPage" disabled="disabled"/>
    <input type="submit" name="btnPrev" value="Previous" class="paging"/>
        
    <input type="submit" name="btnPage" value="1"
           class="disableCurrentPage" disabled="disabled"/>
    <input type="submit" name="btnPage" value="2" class="paging"/>
    <input type="submit" name="btnPage" value="3" class="paging"/>
    <input type="submit" name="btnPage" value="4" class="paging"/>
    <input type="submit" name="btnPage" value="5" class="paging"/>
    <input type="submit" name="btnPage" value="6" class="paging"/>
    <input type="submit" name="btnPage" value="7" class="paging"/>
    <input type="submit" name="btnPage" value="8" class="paging"/>
    <input type="submit" name="btnPage" value="9" class="paging"/>
    <input type="submit" name="btnPage" value="10" class="paging"/>
        
    <input type="submit" name="btnNext" value="Next" class="paging"/>
    <input type="submit" name="btnLast" value="Last" class="paging"/>
</div>

Upto this there is no question. I want to apply the CSS class something like the following to all of those buttons on mouse hover.

.button:hover {
    border:1px solid #999;
    color:#000;
}

Those buttons with the name attribute btnPage are generated dynamically in a loop. Therefore, I think it is inconvenient to apply the preceding CSS class based on the id attribute.

So, how can this class be applied to those buttons on hover?

0

3 Answers 3

35

Add the below code

input[type="submit"]:hover {
    border: 1px solid #999;
    color: #000;
}

If you need only for these button then you can add id name

#paginate input[type="submit"]:hover {
    border: 1px solid #999;
    color: #000;
}

DEMO

Sign up to request clarification or add additional context in comments.

7 Comments

this will target all the inputs, not the ones with btnPage name attribute as Tiny asked.
@GeorgeKatsanos He is asking for all buttons (I want to apply the CSS class something like the following to all of those buttons on mouse hover.). Those buttons with the name attribute btnPage are generated dynamically so it is not a good idea to assign the class name coz you cant give class name for dynamically generated buttons. This is what he is saying
Well his English is not perfect obviously.. I think he should clarify. If he wants all inputs to have some styling then #paginate input {} will do it - but I don't understand why he had to mention the name btnPage attribute part..
@GeorgeKatsanos :) his questions is clear. The reason why he has mentioned the btnPage attribute is to say its not possible to style the button with class name since it is dynamically generated.
but it is. CSS will be applied to all elements, even if they're loaded with an Asynchronous call or whatever. That's the thing.
|
5

The most efficient selector you can use is an attribute selector.

 input[name="btnPage"]:hover {/*your css here*/}

Here's a live demo: http://tinkerbin.com/3G6B93Cb

4 Comments

This doesn't work when you add the custom style tinkerbin.com/noZjmZkA The result showing in your page is default hover style of button
You changed my example, that's not what I pasted.
I changed to show you the effect. It should work with that style. In your demo if you remove the css also it gives the same result
I changed the url. The problem is that input elements should not be changed with CSS rules.
2

You have two options:

  1. Extend your .paging class definition:

    .paging:hover {
        border:1px solid #999;
        color:#000;
    }
    
  2. Use the DOM hierarchy to apply the CSS style:

    div.paginate input:hover {
        border:1px solid #999;
        color:#000;
    }
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.