创建布局的最佳实践(使用服务器端代码)
为了解决这个问题,我们假设我有一个容器元素,该元素内部有三列,右边距为 10 像素,在第三列上,我想将右边距设置为 0 像素。
现在有两种方法可以做到这一点,我可以使用 jquery 来选择第 n 个子元素,但我也可以在服务器端使用简单的循环计数来获取第三个元素。我的问题是实现这样的目标的推荐做法是什么?在服务器端进行意味着,即使用户浏览器上禁用了 javascript,布局也能完美工作。然而,出于这些装饰原因而使用服务器端代码的想法可能不是理想的实践,并且服务器端应该严格用于功能。
我想知道人们对此有何看法。
Lets assume for the sake of this question, I have a container element, with three columns inside that container and with a right margin of 10 pixels, on the third column I want to set the right margin to 0 pixels.
Now there are two ways I can do this, I can do this using jquery to select the nth-child, but I can also do this server-side using a simple loop count to get the third element. My question is what is the recommended practice of achieving something like this? Doing it server side means, the layout works perfect even if javascript is disabled on the users browser. However, the idea of using server side code for these kind of cosmetic reasons, may not be ideal practice, and server-side could should be used strictly for functionality.
I'd like to know what peoples views are on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 CSS
:last-child
怎么样?如果您真的关心 IE6,您可以在最后一列的服务器端代码中添加某种类(例如
final-column
),但不能添加内联样式。最后,不要将 Javascript 用于样式目的。
What about using CSS
:last-child
?If you really care about IE6, you can add some kind of class (like
final-column
) in the server-side code for the last column, but no inline styles.Finally, don't use Javascript for styling purposes.
如果渲染后布局不会改变,我相信使用服务器端 HTML 生成应该是一种更可靠的方法。
If the layout is not gonna be changed after rendered, I believe using server-side HTML generation should be a more robust way.