字体大小与元素宽度相同
font-size same as element width
示例:http://www.jpeg.cz/images/2016/05/04/uEf8S.jpg
您好,是否可以使 font-size
与元素相同 width
并使其具有响应性或必须在每个分辨率上固定?
HTML:
<h1>Lorem ipsum dolor!</h1>
<div id="form-wrapper">
<form action="#" method="post">
<input type="text" name="fullname" placeholder="Jméno a příjmení" />
<input type="email" name="email" placeholder="E-mail" />
<input type="tel" name="tel" placeholder="Telefon" />
<input type="submit" value="ODESLAT" />
</form>
</div>
CSS:
@media only screen and (max-width: 767px) {
section h1 {
font-size: xx;
}
#form-wrapper {
width: 320px;
}
}
@media (min-width: 768px) {
section h1 {
font-size: xx;
}
#form-wrapper {
max-width: 425px;
}
}
@media (min-width: 1200px) {
section h1 {
font-size: 50px;
font-size: 3.125rem;
}
/* form */
#form-wrapper {
max-width: 590px;
}
}
与包含元素无关,但您可以给视口相对单位 look/try vw
、vh
、vmin
、vmax
.
文档:https://developer.mozilla.org/en/docs/Web/CSS/length#Viewport-percentage_lengths
浏览器支持:http://caniuse.com/#feat=viewport-units
Fiddle Demo
h1{
text-transform:uppercase;
margin: 0px 0px;
font-size: 18px;
text-align:center;
letter-spacing:.8px;
font-size:6.4vw; }
文档来源Here
示例:
您好,是否可以使 font-size
与元素相同 width
并使其具有响应性或必须在每个分辨率上固定?
HTML:
<h1>Lorem ipsum dolor!</h1>
<div id="form-wrapper">
<form action="#" method="post">
<input type="text" name="fullname" placeholder="Jméno a příjmení" />
<input type="email" name="email" placeholder="E-mail" />
<input type="tel" name="tel" placeholder="Telefon" />
<input type="submit" value="ODESLAT" />
</form>
</div>
CSS:
@media only screen and (max-width: 767px) {
section h1 {
font-size: xx;
}
#form-wrapper {
width: 320px;
}
}
@media (min-width: 768px) {
section h1 {
font-size: xx;
}
#form-wrapper {
max-width: 425px;
}
}
@media (min-width: 1200px) {
section h1 {
font-size: 50px;
font-size: 3.125rem;
}
/* form */
#form-wrapper {
max-width: 590px;
}
}
与包含元素无关,但您可以给视口相对单位 look/try vw
、vh
、vmin
、vmax
.
文档:https://developer.mozilla.org/en/docs/Web/CSS/length#Viewport-percentage_lengths
浏览器支持:http://caniuse.com/#feat=viewport-units
Fiddle Demo
h1{
text-transform:uppercase;
margin: 0px 0px;
font-size: 18px;
text-align:center;
letter-spacing:.8px;
font-size:6.4vw; }
文档来源Here