这里的CSS newby ..。
我正在研究一个响应性的框架,并想象我将如何完成不同的任务。
根据屏幕的大小,它们将类添加到body标记中,例如:
.PhoneVisible,.DesktopVisible等.
它们也有类可以将链接链接到按钮中:
.btn,小按钮,地中海按钮,大按钮
我对你如何改变你的CSS感到困惑。例如:
<a href="#" class="MyButtonOptions">XXXX</>
.PhoneVisible .MyButtonOptions { btn small-button }
.TabletVisible .MyButtonOptions { btn med-button }
.DesktopVisible .MyButtonOptions { btn large-button }
你必须单独设置不同的选项吗?
即.PhoneVisible .MyButtonOptions {高度:30;}?
感谢所有的建议!
发布于 2013-08-27 15:33:41
看看这个查询。
另一种方法是附加一些“开关代码”的调整大小事件。
就像这样:http://jsfiddle.net/s5dvb/
HTML
<div id="body" class="limit400">
<h1>Hey :D</h1>
</div>
CSS
.limit400 h1 { font-size:10px; }
.limit1200 h1 { font-size:50px; }
JS
$(window).on('resize', function() {
if($(window).height() > 400) {
$('#body').addClass('limit1200');
$('#body').removeClass('limit400');
}else{
$('#body').addClass('limit400');
$('#body').removeClass('limit1200');
}
})
关于框架,尝试http://purecss.io/或http://getbootstrap.com/
希望能帮上忙。
发布于 2013-08-27 16:00:23
CSS媒体查询无疑是要走的路。
您可以根据浏览器大小、像素密度等轻松地分离CSS。
下面是来自CSS-戏法的示例列表。
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
@media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
@media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
@media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
发布于 2021-05-05 07:11:39
就像发布的一样,您可以使用上面的方法,并将其与类场景联系起来。而不是切换类,而是使用同一个类并根据屏幕大小更改它应用的样式。
如下图所示,任何具有“调整大小”类的元素都将有一个边距-左和边距--根据媒体大小而有不同的值,因此默认值为15%,但是如果屏幕在800到1200 (px)之间,它将有10%,而小于800 px则没有右边距,左边距为5%。
.adjust-me-based-on-size{
margin-left: 15%;
margin-right: 15%;
}
@media only screen and (min-width: 800) and (max-width: 1200) {
.adjust-me-based-on-size {
margin-left: 10%;
margin-right: 10%;
}
}
@media only screen and (max-width: 800px) {
.adjust-me-based-on-size {
margin-left: 5%;
margin-right: 0%;
}
}
https://stackoverflow.com/questions/18477016
复制