Html 如何创建响应性字体大小
我试着在我的幻灯片上放一些文字,让字体的大小能够响应。我发现这个问题: 这和我想要实现的目标非常相似。我一直在努力,并利用字体大小和行高百分比,但它似乎没有做任何事情。到目前为止,我的代码如下所示: HTML:Html 如何创建响应性字体大小,html,css,fonts,responsive,responsiveness,Html,Css,Fonts,Responsive,Responsiveness,我试着在我的幻灯片上放一些文字,让字体的大小能够响应。我发现这个问题: 这和我想要实现的目标非常相似。我一直在努力,并利用字体大小和行高百分比,但它似乎没有做任何事情。到目前为止,我的代码如下所示: HTML: 这个页面中还有其他HTML元素、css和js内容,所以可能是从其他地方继承了一些与字体相关的内容,或者我根本不知道自己在做什么。无论采用哪种方式,查看此页面并调整窗口大小都可能是最简单的方法。不要使用像素作为字体大小。尝试em、rem或基于%的值,而不是像素 你也可以参考这个链接,这是
这个页面中还有其他HTML元素、css和js内容,所以可能是从其他地方继承了一些与字体相关的内容,或者我根本不知道自己在做什么。无论采用哪种方式,查看此页面并调整窗口大小都可能是最简单的方法。不要使用像素作为字体大小。尝试em、rem或基于%的值,而不是像素
你也可以参考这个链接,这是我过去在这种情况下使用的一个助手函数。我希望jQuery可以为您提供使其正常工作所需的数字!这允许您在rems中设置字体大小(这意味着它基于html字体大小),然后在调整屏幕大小时修改html元素字体。ScreenWidth可以是浏览器窗口的宽度,也可以是包含内容的元素的宽度
function getFontSize(screenWidth) {
"use strict";
var fontSize = 10, // this is the base font size. All other sizes are computed based on this number
maxWidth = 1024, // max size of content on a page
minSize = 5; // smallest base font size allowed
if (screenWidth < maxWidth) {
// font size is computed by the ratio of screenWidth to maxWidth
fontSize = Math.max((screenWidth / maxWidth) * fontSize, minSize);
}
return fontSize; //font-size is then applied to the html element of your page
}
函数getFontSize(屏幕宽度){
“严格使用”;
var fontSize=10,//这是基本字体大小。所有其他大小都基于此数字计算
maxWidth=1024,//页面上内容的最大大小
minSize=5;//允许的最小基本字体大小
if(屏幕宽度<最大宽度){
//字体大小由屏幕宽度与最大宽度之比计算
fontSize=数学最大值((屏幕宽度/最大宽度)*fontSize,最小尺寸);
}
return fontSize;//然后将字体大小应用于页面的html元素
}
您能使用javascript或jQuery来帮助您吗?通过查看这些工具,您实际上没有针对正确的元素。如果您使用开发人员工具,您可以看到字体大小被这个#rot#rot#rot#u ctr1_bod_ctr3_bod_wrp1 h2
@minorcase我可以使用javascript,我可以使用jQuery多达1.11ibelieve@Kiz啊,好吧,我明白了。我进入chrome编辑器,找到了那个类,并取消选中了字体大小:22px。字体变大了很多,但是仍然没有响应。你还看到什么了吗?在我的例子中,我正在使用一个自动编辑器为我创建ID,所以任何带有“rot”的东西。。。是自动创建的。我试着用重要的标签来覆盖它,但这并不总是有效。凯,我一直在努力避免像素字体大小。即使我从我的ec_slideshow类以及上面@Kiz提到的id中删除字体大小,它仍然似乎被某些东西覆盖了。好吧,我可以试一试。我对Jquery/Javascript一点也不熟悉。你们能告诉我输入(屏幕宽度)和输出(字体大小)的具体操作吗?i、 e.如何将我的浏览器宽度或元素宽度设置为输入的“ScreenWidth”,特别是在我的HTML中?ScreenWidth=window.innerWidth
then$(“HTML”).css(“font-size”,getFontSize(ScreenWidth))
如果需要获取元素,请参见此图,它基本上看起来像ScreenWidth=$(“”)。width()
然后像上面那样再次调用该函数。谢谢,我添加了它,但我认为它与我正在使用的不兼容:(不过感谢您的尝试
.ec_slideshow {
width: auto;
max-width: 1200px;
height: auto;
border: 2px solid black;
/*background-color: cyan;*/
text-align: center;
font-size: 20px;
margin: 20px auto 0px auto;
padding-bottom: 0px;
z-index: 1 !important;
}
.ec_slidecontent span {
position: absolute !important;
top: 0px;
left: 30%;
font-family: 'roboto' !important;
font-size: 100% !important;
color: #fff !important;
padding: 3px 10px !important;
width: 40% !important;
line-height: 100% !important;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.7);
}
.ec_slidecontent {
margin: 0px !important;
padding: 0px !important;
.ec_slidecontainer img {
position: relative;
width: 100%; /* for IE 6 */
}
function getFontSize(screenWidth) {
"use strict";
var fontSize = 10, // this is the base font size. All other sizes are computed based on this number
maxWidth = 1024, // max size of content on a page
minSize = 5; // smallest base font size allowed
if (screenWidth < maxWidth) {
// font size is computed by the ratio of screenWidth to maxWidth
fontSize = Math.max((screenWidth / maxWidth) * fontSize, minSize);
}
return fontSize; //font-size is then applied to the html element of your page
}