简体   繁体   English

CSS和DIV:通过Div类传递参数?

[英]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. 1号只是为栏中的每个徽标和按钮制作了一个CSS类。 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. 另一种方法是通过DIV括号以某种方式将值传递到CSS类中,以更改元素的位置。

That's where my problem lies. 那就是我的问题所在。 I have no idea how to pass a value around in CSS and DIV. 我不知道如何在CSS和DIV中传递值。 Does anyone have any ideas? 有人有什么想法吗? I'd really appreciate it :) 我真的很感激:)

I've never heard of passing parameters using CSS and Div's. 我从未听说过使用CSS和Div传递参数。 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. 您应该看看CSS生成语言,例如LESS / SASS / Stylus等。

The idea is that you can write code in those languages (and pass variables) and have it generate your CSS. 这个想法是,您可以使用这些语言编写代码(并传递变量),并使其生成CSS。 Here is an example in LESS if you want to generate 30 styles. 如果要生成30种样式,这是LESS中的示例。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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