Applying CSS styles to all elements inside a DIV

后端 未结 7 923
孤独总比滥情好
孤独总比滥情好 2020-12-02 21:59

I would like to apply a CSS file to a concrete DIV in my page. This is the page structure:


...


        
相关标签:
7条回答
  • 2020-12-02 22:37

    If you're looking for a shortcut for writing out all of your selectors, then a CSS Preprocessor (Sass, LESS, Stylus, etc.) can do what you're looking for. However, the generated styles must be valid CSS.

    Sass:

    #applyCSS {
        .ui-bar-a {
           color: blue;
        }
        .ui-bar-a .ui-link-inherit {
           color: orange;
        }
        background: #CCC;
    }
    

    Generated CSS:

    #applyCSS {
      background: #CCC;
    }
    
    #applyCSS .ui-bar-a {
      color: blue;
    }
    
    #applyCSS .ui-bar-a .ui-link-inherit {
      color: orange;
    }
    
    0 讨论(0)
  • 2020-12-02 22:42

    Alternate solution. Include your external CSS in your HTML file by

    <link rel="stylesheet" href="css/applyCSS.css"/> 
    

    inside the applyCSS.css:

       #applyCSS {
          /** Your Style**/
        }
    
    0 讨论(0)
  • 2020-12-02 22:49
    #applyCSS > * {
      /* Your style */
    }
    

    Check this JSfiddle

    It will style all children and grandchildren, but will exclude loosely flying text in the div itself and only target wrapped (by tags) content.

    0 讨论(0)
  • 2020-12-02 22:58

    Write all class/id CSS as below. #applyCSS ID will be parent of all CSS code.

    For example you add class .ui-bar-a in CSS for applying to your div:

    #applyCSS .ui-bar-a  { font-size:11px; } /* This will be your CSS part */
    

    Below is your HTML part:

    <div id="applyCSS">
       <div class="ui-bar-a">testing</div>
    </div>
    
    0 讨论(0)
  • 2020-12-02 22:59

    I do not understand why it does not work for you, it works for me : http://jsfiddle.net/igorlaszlo/wcm1soma/1/

    The HTML

    <div id="pagina-page" data-role="page">
        <div id="applyCSS">
        <!--all the elements here must follow a concrete CSS rules-->
            <a class="ui-bar-a">This "a" element text should be red
                <span class="ui-link-inherit">This span text in "a" element should be red too</span>
            </a>      
        </div>
    </div>
    

    The CSS

    #applyCSS * {color:red;display:block;margin:20px;}
    

    Maybe you have some special rules that you did not share with us...

    0 讨论(0)
  • 2020-12-02 23:02

    You could try:

    #applyCSS .ui-bar-a {property:value}
    #applyCSS .ui-bar-a .ui-link-inherit {property:value}
    

    Etc, etc... Is that what you're looking for?

    0 讨论(0)
提交回复
热议问题