简体   繁体   中英

CSS & DIV : Passing parameters with Div classes?

I've been working on a new website template which I'm happy with at the moment. However I have a problem. I have a navigation bar that has a position:fixed. Now I want to have a logo and the menu buttons in the navigation bar. As I want the logo to be on the left and the buttons to be on the right.

So far I have figured a few ways. Number 1 is just making a CSS class for every logo and button in the bar. I want to avoid this one as it's cheap coding. The other way is to somehow pass a value into the CSS class via the DIV brackets to alter the position of the elements.

That's where my problem lies. I have no idea how to pass a value around in CSS and DIV. Does anyone have any ideas? I'd really appreciate it :)

I've never heard of passing parameters using CSS and Div's. I would suggest you place your nav bar with a relative position and then place your logo and other things you want inside the nav bar with an absolute position.

You should take a look at CSS generation languages like LESS/SASS/Stylus etc.

The idea is that you can write code in those languages (and pass variables) and have it generate your CSS. Here is an example in LESS if you want to generate 30 styles.

http://blog.thehippo.de/2012/04/programming/do-a-loop-with-less-css/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM