First of all, do not put your CSS classes in use with names suggesting a visual intent, such as "minheightstyle". Part of the CSS idea is to separate content and style, a proven advantage that you are trying to invalidate with the class names that you show. So, this is your first rule of thumb - if you want to mark an element, you donβt mark it just for styling, you put it in a hint about how this element differs from others in relation to its content. For example, with your three div s, if all are the same, then they can be selected as children of their parent, for example:
#parent > div { min-height: 300px; }
If one of them is a selected menu item (for example), you can assign it a class of "selected" and adjust it accordingly:
#selected { min-height: 300px; }
In general, try talking about structure when designing selectors, rather than thinking about style. This is probably the advice that you discard by resorting to simpler measures, but I assure you that this is the best investment you can make if you are serious about web design today. Separation of content and style is absolutely necessary, and not only with today's HTML and CSS, it is relevant in other areas.
And secondly, you must remember that the rules that you write are applied slavishly by the browser - that is, elements that ultimately exceed you with your stylesheets must use their own style in accordance with CSS requirements, recounted from the fact that was, That is, if you (for example) decided to redefine the style of all elements with the following selector:
* { margin: 0; padding: 0; }
.. because you decide that you are tired of small discrepancies between browsers, applying your small margins and gaskets here and there, and you want steel controls for fields and gaskets on your pages, then you should know that the browser will bind the rule above (either compute the style right then, and there, or put it off for later) for every element that you have. Knowing this, you should understand whether it is better to apply the rule above to some elements. The same reasoning is usually applied to background images - is it better to apply the background color to the children of the element or just to the element itself (the result is often indistinguishable visually)?
<div id="menu"> <div>Apples</div> <div>Oranges</div> <div>Bananas</div> </div>
#menu > div { background-color: brown; }
or
#menu { background-color: brown; }
As for your immediate problem, a good rule of thumb is code minimization, including both markup and style. Get rid of identical class names for children, CSS is quite capable of choosing them without class names:
<div id="foo"> <div>my text in red bg</div> <div>my text in blue bg</div> <div>my text in grey bg</div> </div>
#foo > div { min-height: 300px; float: left; } #foo > div:nth-child(1) { color: red; } #foo > div:nth-child(2) { color: green; } #foo > div:nth-child(3) { color: blue; }
Of course, there are other ways to choose things in the above, but just try applying knowledge of how CSS works. Abstraction from details is good, but optimization requires knowledge of these details. Try not to talk about the style when developing your markup - type it as if the author (your) style was always turned off or typed its tag elements based on the content. Then apply CSS, browse (often need wrappers, but this is the life of web developers now), and repeat. But try to keep the content and style separate - the change should have minimal impact on the other.