Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access two Ids in one css selector

Tags:

I have div which has three buttons as,

<div id="buttons">     <input id="preview" class="ButtonStyle" type="submit" value="Preview" name="preview">     <input id="add" class="ButtonStyle" type="submit" value="Save" name="add">     <input id="Cancel" class="ButtonStyle" type="submit" value="Cancel" name="Cancel"> </div> 

I set its style. I want that both add and cancel button have their left-margin: 5px; Right now I am doing it in this manner,

#outboxmidpg #buttons input[type="submit"]{     font-weight: bold;     width: 70px; }  #outboxmidpg #buttons input[id="Cancel"] {     margin-left: 5px; }  #outboxmidpg #buttons input[id="add"] {     margin-left: 5px; } 

I want to do it in one line. I tried this, but it didn't work and it removes the cancel button margin too.

#outboxmidpg #buttons input[id="Cancel"] input[id="add"] {     margin-left: 5px; } 

Is there anyway that I can achieve the style in one line?

Thanks

like image 771
Basit Avatar asked Mar 28 '12 06:03

Basit


People also ask

Can you have two IDS CSS?

You cannot have multiple IDs for a single div tag. There is never any need for multiple ids on the same tag since ids are unique either one would serve to uniquely identify that specific tag provided you first get rid of the other id which is stopping things working.

Can one element have 2 IDS?

The HTML id attribute is used to specify a unique id for an HTML element. You cannot have more than one element with the same id in an HTML document.


2 Answers

#buttons input:nth-child(2), #buttons input:nth-child(3){     margin-left:5px; } 

does this work for you ?

or simply:

#Cancel, #add{     margin-left:5px; } 

With , seperation you start a complete new CSS Selector and combine them.

like image 103
mas-designs Avatar answered Sep 18 '22 07:09

mas-designs


Best practice to do is: Just put all the id's/class and separate them by commas (,) then insert your custom style on its body.

#Button_One, #Button_Two { vertical-align: middle;     padding-top: 10px;     margin-top:  1px; } 

Hope it helps :)

like image 44
spongecode Avatar answered Sep 18 '22 07:09

spongecode