Multiple html div's using same css style
That selector will apply to #container1,#container2, and any h5s in #container3. I think you want:
#container1 h5,
#container2 h5,
#container3 h5 {
/* styling */
}
This is exactly what classes are intended for, however. If you add class="container"
to each of your container div
s, you can simply use the following rule:
.container h5 {
/* styling */
}
styling multiple divs with same class name differently
.right:nth-child(1) {
background: red;
}
.right:nth-child(2) {
background: yellow;
}
...
https://www.w3schools.com/CSSref/sel_nth-child.asp
using same css class from multiple pages
You can create a .myStyleForPage1
class for your @media all and (min-width: 800px) {...
But also you can create another class like myStyleMQ
, and
page1: <div class="myStyle myStyleMQ">...</div>
page2: <div class="myStyle">...</div>
page3: <div class="myStyle">...</div>
Because you can have more than 1 class in an element.
HTML applying style to multiple div in CSS
Give the div a class. Use a class selector.
<div id="container-frame-{{ i }}" class="container-frame"
.container-frame {
border-style: solid;
border-width: 5px;
border-color: green;
}
You could also use an attribute selector.
[id^="container-frame-"] {
border-style: solid;
border-width: 5px;
border-color: green;
}
Applying same style to multiple child divs
Try this:
#id1 > div, #id2 > div {
border: 1px solid white;
width: 100px;
height: 50px;
margin: 5px;
}
Multiple CSS selectors should be separated by a coma.
Applying Style to Multiple Div's in JavaScript
for...in
iterates over enumerable properties in an object so it is not correct to use it in your case: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
querySelectorAll
returns a NodeList, which has a handy forEach
method:
boxes.forEach(box => box.style.backgroundColor = "lightblue");
How to apply in page style to different divs
Duplicate style declarations like that are going to end up in having one of them ignored. Also while class declarations can start with a number, you can't do that with IDs. Notice that I changed your outer div IDs from #1
to #outer1
and #2
to #outer2
.
.outer{ width:100px; height:100px; background-color:blue;}.inner{ width:50px; height:50px; margin:10px;}
<style>#outer1 div.inner{background-color:red}</style><div id="outer1" class="outer"> content <div class="inner"> more content </div></div>
<style>#outer2 div.inner{background-color:green}</style><div id="outer2" class="outer"> content <div class="inner"> more content </div></div>
Related Topics
Sticky Scrollbar at Bottom of Table
How to Override Background Image Defined in CSS with Another CSS
How to Make Body Background Image Transparent in CSS
CSS Triangle + "After" Implementation
Making a Row of Divs All Be The Same Height Using CSS
Editing Angular Material's Table Cell Padding
How to Make The Animation Smooth
Taming The Automatic Telephone Number Thing in The Windows 10 Edge Browser
CSS Style for Links Pointing to The Current Page
Width: 100% Without Scrollbars
Which Monospace Font Does a Browser Use
Why Is My Multi-Column Spacing Not Working in Chrome
How to Inherit Only One Element of CSS Shorthand