tags:

views:

73

answers:

4

I was wondering if there was any "easy" way to add through css lets say:

border: 1px solid red;

to all divs no matter what their id´s are.

I realize this might be a very very basic question (or no possible at all) and I hope it is clear enough.

Just to clarify, lets say I´ve got:

HTML

<div id="one">

</div>

<div id="two">

</div>

and CSS

#one{
height: 10px;
width: 10px;
}

#two{
height: 10px;
width: 10px;
}

The result I actually want is:

#one{

height: 10px;
width: 10px;
border: 1px solid red;
}

#two{
height: 10px;
width: 10px;
border: 1px solid red;
}

I want to achieve this without having to go one by one.

Thanks in advance!!

Please ask for any clarification needed!

+10  A: 
div {
    border: 1px solid #000000;
}
McAden
I cant believe I could no see that coming, thank you very much. sorry for the dumb question, thank you very much
Trufa
Not a stupid question at all, merely not fully understanding how css works. I would recommend using a class though if this is intended to be useful. most pages have so many div objects adding a border to each would be pretty crazy.
McAden
A: 

I agree with @McAden's answer. Alternatively, you can use jquery to add the style on the fly:

<script type="text/javascript">
    $('div').css('border','1px solid #000');
</script>
code90
The down-voter really *should* have explained their down-vote, but I'd hazard a guess that it's to do with over-complicating things. What you say is *true*, but over-kill for the particular situation.
David Thomas
A: 

Perhaps this will help you:

div#one, div#two{
    border:1px solid red;
}
Oto Brglez
Not quite what he asked, but it's good to teach him the comma syntax.
Christian Mann
A: 

As McAden was saying, you may want to specify which divs you want to style. Instead of adding a class to each div you may want to try an approach like this,

.theseDivs div{
    /*styles here*/
}

<div class="theseDivs">
    <div>Style applied here</div>
    <div>and here, </div>
</div>
<div>but not here</div>