Jump to content

Recommended Posts

 

Learning html and css when you start, you just cram things in, afterwards you almost turn on auto pilot when writing it, but today i just realised why can't you reference in CSS.... eg:

 

.autoMargins{
  margin-left:auto;
  margin-right:auto;
}
.someContainer{
  .autoMargins;
  /*some more styling*/
}
.anotherContainer{
    .autoMargins;
  /*some more styling*/
}

 

Is or was this ever a consideration for future releases? And if not, why not?

Link to comment
https://forums.phpfreaks.com/topic/252029-referencing-in-css/
Share on other sites

Not sure if you're aware, but you just have to put both classes in the html. Essentially the same thing. But I agree it would seem more efficient to do it in the css.

.automargin {
margin:0 auto;
}
.container {
/* styles here */
}
.anothercontainer {
/* styles here */
}

The html code would be:
<div class="automargin container">
</div>

<div class="automargin anothercontainer">
</div>

 

Just thought I'd state the obvious  :D

 

Never heard of the others, but I'm going to look into them.

Link to comment
https://forums.phpfreaks.com/topic/252029-referencing-in-css/#findComment-1292764
Share on other sites

:D yea I know... that is most likely why i never even stopped to think as i was using that method.

 

But a basic example, take a look at the following:

<div class="big center">some sontent</div>
<div class="small center">some sontent</div>
<div class="other center">some sontent</div>

 

But then the above could look like this if 'center' could have called into others in the css file, thus reducing the size of the css file and html:

<div class="big">some sontent</div>
<div class="small">some sontent</div>
<div class="other">some sontent</div>

 

 

Link to comment
https://forums.phpfreaks.com/topic/252029-referencing-in-css/#findComment-1292823
Share on other sites

:D yea I know... that is most likely why i never even stopped to think as i was using that method.

 

But a basic example, take a look at the following:

<div class="big center">some sontent</div>
<div class="small center">some sontent</div>
<div class="other center">some sontent</div>

 

But then the above could look like this if 'center' could have called into others in the css file, thus reducing the size of the css file and html:

<div class="big">some sontent</div>
<div class="small">some sontent</div>
<div class="other">some sontent</div>

 

 

 

To be fair, with that example - the CSS file size will increase. With SASS/LESS it basically adds in those properties (last time I checked), so instead of

// css
.center { margin: 0 auto; }
.big { font-size: 120%; }
.normal { font-size: 100%; }
.small { font-size: 80%; }

// html
<div class="center big">...</div>
<div class="center small">..</div>

 

You'll have this:

// css
.big { font-size: 120%; margin: 0 auto; }
.normal { font-size: 100%; margin: 0 auto; }
.small { font-size: 80%; margin: 0 auto; }

// html
<div class="big">...</div>
<div class="small">..</div>

 

So the only time it really reduces it is if you have many calls to the same style choices. The way to save file size/bandwidth in this case would be to combine them:

// css
.big, .normal, .small { margin: 0 auto; }
.big { font-size: 120%; }
.normal { font-size: 100%; }
.small { font-size: 80%; }

// html
<div class="big">...</div>
<div class="small">..</div>

 

However, IMO the whole point of the using ".center .big" is to allow for the HTML to be more versatile during redesigns, which is why I'll continue to stick with it - especially for things like rounded edges / shadows.

Link to comment
https://forums.phpfreaks.com/topic/252029-referencing-in-css/#findComment-1292845
Share on other sites

// css
.big, .normal, .small { margin: 0 auto; }
.big { font-size: 120%; }
.normal { font-size: 100%; }
.small { font-size: 80%; }
// html
<div class="big">...</div>
<div class="small">..</div>

 

Yea like a reset sheet. However I often find it easier to remember different rule sets than to remember to create a common set and add to it as you wrote out above, and just think it would be easier to call them into others when required instead of the other way around, it feels a little more like conventional scripting then (to me anyway)

Link to comment
https://forums.phpfreaks.com/topic/252029-referencing-in-css/#findComment-1292974
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.