左侧文字
我在这里尝试做的是将文本“Typerore”与左上角对齐,但文本位于左侧中心。
我尝试在 CSS 中使用“left:”标签,但这不起作用,我也尝试使用“float:left”,但这也不起作用。
我想知道我需要使用什么标签来将 div“标题”对齐到左上角。
* {
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: coral;
}
body,
.quote-input {
font-family: 'Fredoka', sans-serif;
}
.container {
background-color: lightgrey;
padding: 1rem;
border-radius: .5rem;
width: 700px;
max-width: 90%;
}
.timer {
position: absolute;
top: 2rem;
font-size: 3rem;
color: grey;
font-weight: bold;
}
.quote-display {
margin-bottom: 1rem;
margin-left: calc(1rem + 2px);
margin-right: calc(1rem + 2px);
}
.quote-input {
background-color: transparent;
border: 2px solid #A1922E;
outline: none;
width: 100%;
height: 8rem;
margin: auto;
resize: none;
padding: .5rem 1rem;
font-size: 1rem;
border-radius: .5rem;
}
.quote-input:focus {
border-color: black;
}
.correct {
color: green;
}
.incorrect {
color: red;
text-decoration: underline;
}
/* Background Styles Only */
* {
font-family: 'Fredoka', sans-serif;
}
.side-links {
position: absolute;
top: 15px;
right: 15px;
}
.side-link {
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
margin-bottom: 10px;
color: white;
width: 180px;
padding: 10px 0;
border-radius: 10px;
}
.side-link-text {
margin-left: 10px;
font-size: 18px;
}
.side-link-icon {
color: white;
font-size: 30px;
}
.title {
left: 3rem;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fredoka&display=swap" rel="stylesheet">
<div id="title">
<h1>Typerore</h1>
</div>
<div class="timer" id="timer"></div>
<div class="container">
<div class="quote-display" id="quoteDisplay"></div>
<textarea id="quoteInput" class="quote-input" autofocus></textarea>
<script src="script.js"></script>
</div>
What I am trying to do here is to align the text "Typerore" to the top left corner, but the text is positioned in the left center.
I tried using the "left:" tag in CSS, but that did not work, I also tried using "float:left" but that did not work either.
I was wondering what tag do I need to use to align the div "title" to the top left.
* {
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: coral;
}
body,
.quote-input {
font-family: 'Fredoka', sans-serif;
}
.container {
background-color: lightgrey;
padding: 1rem;
border-radius: .5rem;
width: 700px;
max-width: 90%;
}
.timer {
position: absolute;
top: 2rem;
font-size: 3rem;
color: grey;
font-weight: bold;
}
.quote-display {
margin-bottom: 1rem;
margin-left: calc(1rem + 2px);
margin-right: calc(1rem + 2px);
}
.quote-input {
background-color: transparent;
border: 2px solid #A1922E;
outline: none;
width: 100%;
height: 8rem;
margin: auto;
resize: none;
padding: .5rem 1rem;
font-size: 1rem;
border-radius: .5rem;
}
.quote-input:focus {
border-color: black;
}
.correct {
color: green;
}
.incorrect {
color: red;
text-decoration: underline;
}
/* Background Styles Only */
* {
font-family: 'Fredoka', sans-serif;
}
.side-links {
position: absolute;
top: 15px;
right: 15px;
}
.side-link {
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
margin-bottom: 10px;
color: white;
width: 180px;
padding: 10px 0;
border-radius: 10px;
}
.side-link-text {
margin-left: 10px;
font-size: 18px;
}
.side-link-icon {
color: white;
font-size: 30px;
}
.title {
left: 3rem;
}
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fredoka&display=swap" rel="stylesheet">
<div id="title">
<h1>Typerore</h1>
</div>
<div class="timer" id="timer"></div>
<div class="container">
<div class="quote-display" id="quoteDisplay"></div>
<textarea id="quoteInput" class="quote-input" autofocus></textarea>
<script src="script.js"></script>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以添加边距
也可以使用div而不是使整个主体弯曲
最后您在CSS中使用.title而不是#title
You can add a margin
Also do use divs instead of making the whole body flex
Lastly you had .title instead of #title in the CSS
将
#title
的高度设置为container
的渲染高度。然后,要在最顶角获取文本,您必须删除h1
上的默认边距。Set height of
#title
to rendered height ofcontainer
. Then to get the text at the very top corner you will have to remove the default margin onh1
.:D
我为你做了一个快速解决方案(也许不是最好的,但效果很好),
我将“id=title”更改为“class=title”,因为您在 css 文件中使用了点(.title)。
:D
I Made a Quick solve for you (maybe no the best, but works fine),
i changed "id=title" to "class=title" because you use the dot (.title) in css file.