javascript - How would you call specific CSS stylesheet in a React component on a specific site? -


so i'm working on platform built on react , platform has global css set clients way.

a subset of affiliates under common group name want new sticky ad component has change css bit footer not covered up.

so normally, i'd check our global variable value is, window.client.group, , if it's group, add css or css stylesheet through javascript in affiliate js file (our old generic platform).

the new css needed is:

  @media (max-width:767px){     #ad201 {width:100%;position:fixed;bottom:0;left:0;z- index:99999;margin:0;border:1px solid rgb(232, 232, 232);background- color:#fff;margin: 0 !important;}     .footer .container {padding-bottom:50px;}   } 

in react though, what's best , proper way this? can see it's complicated needing in media query.

i have start using group , matchmedia, what's best way bring in css? whole stylesheet? (stickyad.css? other way? , tips on how it?)

const group = (window.client.group).tolowercase(); console.log(group);  const mq = window.matchmedia("(max-width: 767px)");  if ((mq.matches) && (group === 'premiere')) {   // bring in new css } else {   // nothing } 

thanks advice !

it depends on how control have on ad201 , footer.

i'm assuming footer component you've created in react. in case, add class premiere-footer-fix (you can think of better name) components being rendered when detect group:

render() {   const group = (window.client.group).tolowercase();    return (     <footer classname={group === 'premiere' ? 'premiere-footer-fix' : ''}/>   ) } 

or if import handy classnames package,

import classnames 'classnames';  // ...  render() {   const group = (window.client.group).tolowercase();   const classes = classnames({     'premiere-footer-fix': group === 'premiere'   });    return (     <footer classname={classes}/>   ) } 

then wherever declare css footer, add like:

@media (max-width:767px) {     .footer.premiere-footer-fix .container {       padding-bottom: 50px;     } } 

as ad, you'd have provide more info how it's being inserted page since it's not clear how control have on element. add premiere ad's classlist , find place insert bit of css:

@media (max-width:767px) {   #ad201.premiere {     width: 100%;     position: fixed;     bottom: 0;     left: 0;     z-index: 99999;     margin: 0;     border: 1px solid rgb(232, 232, 232);     background-color: #fff;     margin: 0 !important;   } } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - VueJS2 and the Window Object - how to use? -