【发布时间】:2016-10-13 03:18:34
【问题描述】:
所以我最近才开始学习响应式网页设计并在我的 CSS 中使用媒体查询。我已经明白了如何让手机响应和优化。
如果有人只是觉得无聊或有兴趣看这个,你能告诉我我是否走在正确的轨道上,或者我是否违反了任何严重的编码规则?哈。
这是我正在处理的部分内容:(这是指移动的小盒子,忽略背景)
<style>
.three img {
position: relative;
top: 0;
}
#shoutout{
position: absolute;
margin: 40% 45%;
border: 2px solid black;
background-color: white;
padding: 7% 14%;
z-index: 1;
}
.sotext p{
font-size: 120%;
font-weight: bold;
text-align: center;
}
@media screen and (max-width: 1023px){
#shoutout{
text-align: center;
font-size: 75%;
margin-top: 40%;
}
.sotext p{
text-align: center;
font-size: 100%;
}
}
@media screen and (max-width: 740px){
#shoutout{
text-align: center;
margin-top: 35%;
margin-left: 45%;
}
.sotext p{
text-align: center;
font-size: 60%;
}
}
</style>
<head>
<!-- Header Placeholder-->
</head>
<body>
<div>
<section id="shoutout">
<!-- shoutut box -->
<div class="sotext">
<p>Placeholder Text</p>
</div>
</section>
<section class="three">
<img src="http://static1.squarespace.com/static/55bed56ee4b04fdc6e0dd0d8/t/575d8fed4d088eb0ab810e52/1465749487419/mother_daughter.png" alt="shoutout image" />
</section>
</div>
<body>
【问题讨论】:
-
删除重复,.sotext p 已经居中对齐,你只添加媒体查询中改变的元素,其余保持不变。基本上,您希望在基本元素中为您的元素提供所需的所有代码,然后在媒体查询中调整需要调整的代码。
-
这可能更适合CodeReview,但请先查看他们的发布指南。
标签: html css responsive-design media-queries