【问题标题】:Responsive design not working for text响应式设计不适用于文本
【发布时间】:2013-06-07 16:17:41
【问题描述】:

我想为我的页面进行响应式设计,我已经完成了布局,并且在调整大小时效果很好,但是当我在页面中添加文本然后调整大小时,事情变得一团糟。这是因为布局正在相应地调整自己的大小,但文本并没有自行调整大小。如何解决?

这里是html代码:

<body>

<div id="mainpage">

<div id="menu">
<div id="menuhomepage"><a href="#"></a></div>
<div id="menublog"><a href="#"></a></div>
<div id="menuphoto"><a href="#"></a></div>
<div id="menuabout"><a href="#"></a></div>
<div id="menulinks"><a href="#"></a></div>
<div id="menucontact"><a href="#"></a></div>
</div>

<div id="header">
<div id="headertext"><a href="#">logologo</a></div>
</div>

<div id="content">

<div id="articles"></div>

<div id="sidebar">
<div id="searchbar"></div>
<div id="tempus"></div>
<div id="categories"></div>
<div id="blogroll"></div>
<div id="archieve"></div>
</div>

</div>

</div>

<div id="footer"></div>
</body>

下面是 CSS 代码:

body
{
    background-image: url(images/background.jpg);
    min-height: 1000px;
    background-repeat: repeat-x;
    background-color: #DBE2D0;
    width: 100%;
    margin: 0%;
    font-size: 100%;
    min-width: 150px;
}

#mainpage
{
    width: 80%;
    min-height: 900px;
    margin-left: 10%;
}

#menu
{
    width: 100%;
    height: 60px;
}

#menuhomepage
{
    background-color: #5D7144;
    width: 30%;
    height: 60px;
    float:left;
}

#menuhomepage a
{
    text-decoration: none;
    color: White;
    margin-left: 60%;
    margin-bottom: 10px;
}

#menublog
{
    background-color: #5D7144;
    width: 10%;
    height: 60px;
    margin-left: 0.1%;
    float: left;
}

#menuphoto
{
    background-color: #5D7144;
    width: 15%;
    height: 60px;
    margin-left: 0.1%;
    float: left;
}

#menuabout
{   background-color: #5D7144;
    width: 10%;
    height: 60px;
    margin-left: 0.1%;
    float: left;
}

#menulinks
{   
    background-color: #5D7144;
    width: 10%;
    height: 60px;
    margin-left: 0.1%;
    float: left;
}

#menucontact
{
    background-color: #5D7144;
    width: 24.5%;
    height: 60px;
    margin-left: 0.1%;
    float: left;
}

#header
{
    height: 170px;
}

#header a
{
    text-decoration: none;
    font-size: 40pt;
    color: White;
}

#headertext
{
    padding-left: 40%;
    padding-top: 5%;
}

#content
{
    background-color: White;
    min-height: 1600px;
}

#articles
{
    width: 60%;
    border: 2px solid Gray;
    min-height: 1400px;
    margin-left: 5%;
    margin-top: 50px;
    float: left;
}

#sidebar
{
    width: 25%;
    border: 2px solid Gray;
    min-height: 1400px;
    margin-left: 5%;
    margin-top: 50px;
    float: left;
}

#searchbar
{
    width: 96%;
    border: 2px solid Gray;
    min-height: 150px;
    margin-left: 1%;
    margin-right: 1%;
    margin-top: 10px;
    float: left;
}

#tempus
{
    width: 96%;
    border: 2px solid Gray;
    min-height: 100px;
    margin-left: 1%;
    margin-right: 1%;
    margin-top: 30px;
    float: left;
}

#categories
{
    width: 96%;
    border: 2px solid Gray;
    min-height: 350px;
    margin-left: 1%;
    margin-right: 1%;
    margin-top: 10px;
    float: left;
}

#blogroll
{
    width: 96%;
    border: 2px solid Gray;
    min-height: 350px;
    margin-left: 1%;
    margin-right: 1%;
    margin-top: 10px;
    float: left;
}

#archieve
{
    width: 96%;
    border: 2px solid Gray;
    min-height: 350px;
    margin-left: 1%;
    margin-right: 1%;
    margin-top: 10px;
    float: left;
}

#footer
{
    background-image: url(images/footer.png);
    width: 100%;
    height: 200px;
    margin-top: 50px;
    margin-left: 0px;
}

在这里查看 jsfiddle 代码:http://jsfiddle.net/2NNNy/

在添加“logologo”文本并调整大小时,字体大小没有调整大小,为什么?

【问题讨论】:

  • 不包括小提琴链接。
  • 是什么让您认为它应该使用该代码调整大小?

标签: html css responsive-design


【解决方案1】:

仅液体布局就完成了削减......

您将需要深入研究媒体查询以获得您想要的效果。

这里有一些很好的例子。看看源码!

http://mediaqueri.es/

您可能还想试试这个开发者指南...

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

@media (min-width: 700px) { 
   font-size: 75%;
}

@media (min-width: 500px) { 
   font-size: 50%;
}

【讨论】:

  • 感谢您的链接。我正在搜索它们。
【解决方案2】:

应该可以了,希望对你有帮助

@media screen and (max-width: 320px) { /* for screen size less or equal to 320px*/
     #header a{
        font-size: 80%; /*Changes as per your requirement*/
     }    
}

@media screen and (max-width: 700px) { /* for screen size less or equal to 700px*/
#header a{
    font-size: 120%; /*Changes as per your requirement*/
} 
}

并将其包含在您的 head 标签中

<meta name="viewport" content="width=device-width, initial-scale=1.0">

【讨论】:

  • 我在我的 CSS 文件中写了这个,但是在我的 HTML 文件中写什么来链接这个 CSS 样式呢?
  • 完美运行。非常感谢。
【解决方案3】:

始终使用百分比作为字体大小,不要忘记添加 页面标题中的视口元数据

假设你的正文 font-size 为 100%,默认 font-size 为 16px,如果你想为段落应用 13px,你可以像这样轻松计算

13/16 即 81%,很简单吧,

编码愉快 :)

【讨论】:

  • 但这并不能解决我的问题,因为默认字体大小将始终为 16px,因此当我想在调整浏览器大小时调整它的大小时,我的文本会相应地显示出来。
  • 好的,你已经给定了一个固定的 40pt,以百分比为单位,并为不同的媒体查询断点应用不同的字体大小
  • 是的,这就是我想要做的,但我无法理解媒体查询语法。我知道断点,但我不知道如何链接 HTMl 和 CSS 以进行媒体查询。你能告诉我在 HTML 文件和 CSS 文件中具体写什么吗?
猜你喜欢
  • 2014-02-11
  • 2023-03-09
  • 2021-06-07
  • 1970-01-01
  • 2014-11-09
  • 2018-09-20
  • 2016-08-18
  • 2014-05-21
  • 1970-01-01
相关资源
最近更新 更多