html - 内部 HTML 样式不适用于元素?(HTML/CSS)
问题描述
我想使用内部样式表而不是外部样式表,但由于某种原因,这些样式不适用于我的 HTML?
如何在不制作外部 CSS 表或使用内联样式的情况下将我的样式应用于我的 HTML?
<!DOCTYPE html>
<html lang="en">
<head>
<title>Contact Us</title>
<style type=”text/css”>
form{
height: 350px;
width: 200px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: red;
}
</style>
</head>
<body>
<header>
<h1>Contact</h1>
</header>
<nav></nav>
<main>
<h2>Send us feedback</h2>
<form action="" method="post" autocomplete="on">
<label for="fName">First name</label>
<input type="text" name="fName" placeholder="First name">
<label for="lName">Last name</label>
<input type="text" name="lName" placeholder="Last name">
<label for="email">Email</label>
<input type="email" name="email" autocomplete="off" placeholder="Email">
<label for="pNumber">Phone number</label>
<input type="number" name="pNumber" placeholder="Phone number">
<label for="comments">Comments</label>
<textarea name="comments" cols="" rows="" placeholder="Comments"></textarea>
<input name="submit" type="submit">
</form>
</main>
<footer></footer>
</body>
</html>
解决方案
从您的样式标签中删除type="text/css"
,仅在导入带有<link />
标签的样式表时需要
<!DOCTYPE html>
<html lang="en">
<head>
<title>Contact Us</title>
<style>
form {
height: 350px;
width: 200px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: red;
}
</style>
</head>
<body>
<header>
<h1>Contact</h1>
</header>
<nav></nav>
<main>
<h2>Send us feedback</h2>
<form action="" method="post" autocomplete="on">
<label for="fName">First name</label>
<input type="text" name="fName" placeholder="First name">
<label for="lName">Last name</label>
<input type="text" name="lName" placeholder="Last name">
<label for="email">Email</label>
<input type="email" name="email" autocomplete="off" placeholder="Email">
<label for="pNumber">Phone number</label>
<input type="number" name="pNumber" placeholder="Phone number">
<label for="comments">Comments</label>
<textarea name="comments" cols="" rows="" placeholder="Comments"></textarea>
<input name="submit" type="submit">
</form>
</main>
<footer></footer>
</body>
</html>
推荐阅读
- android - 将类保存到 android/kotlin 上的内部存储
- mongodb - 是否可以在 MongoDB 中启用身份验证并为匿名(非身份验证)帐户配置权限?
- nlp - 使用 Spacy 查找俄语的引理(那些没有模型的语言)
- python - 如何获得情绪分数?
- python - 并非 win32com.client 从 Outlook 2016 读取的所有消息
- java - 绑定到 c# 一些使用 .so 库的 java 代码
- javascript - 如何让 JS 函数在每次垃圾邮件调用时只运行一次
- html - 如果该过程完成,则在进度条中绘制一个刻度线
- java - 是否可以在双向关系中创建两列?
- android - Canvas.drawText 为小文本尺寸(1px)添加额外的字母空间