如何将文本与屏幕中心对齐,并使链接的背景为蓝色。而无需更改HTML代码和仅更改CSS代码。我正在使用内联显示和对齐文本:居中,但它不工作。在链接部分,我想将它对齐到中心顶部,并且应该是固定的。
https://notepad.pw/css1234 (用于css文件)
https://notepad.pw/html1234 (用于html文件)
发布于 2018-04-03 12:55:21
你想要什么
修改
在body{}
width: 100%;中添加
text-align: center;解释
bodywidth: 100%,背景颜色将只适合内容(本例中的链接)。请运行下面的代码,看看这是否是您所要求的。
/* This is a partial blocks.css, you need to add more rules
to this file to complete the assignment. Do not add any CSS
styling to the original index.htm / start.htm */
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: center;
}
/* Here is one of many CSS rules you will need... */
#three{
position: fixed;
border: 5px solid #fea405;
margin: 5px;
padding: 5px;
width: 25%;
top: 0;
}
#two{
position: fixed;
border: 5px solid #048103;
margin: 5px;
padding: 5px;
width: 25%;
top: 0;
right: 0;
}
#four{
position: fixed;
border: 5px solid #ffff00;
margin: 5px;
padding: 5px;
width: 25%;
bottom: 0;
}
#one{
position: fixed;
border: 5px solid #0201ff;
margin: 5px;
padding: 5px;
width: 25%;
bottom: 0;
right: 0;
}
#link
{
text-align: center;
color: white;
background-color:#0201ff;
display: inline;
}<!DOCTYPE html>
<html>
<head>
<title>Blocks</title>
<!-- Do not change this file - add your CSS styling
rules to the blocks.css file included below -->
<link type="text/css" rel="stylesheet" href="style.css">
</head>
<body>
<div id="one">
Turns out you have a really fun time if you
go to work every day and focus on being
silly and funny and happy! - Hannah Murray
</div>
<div id="two">
All you need in this life is ignorance and confidence,
and then success is sure. - Mark Twain
</div>
<div id="three">
Well, if crime fighters fight crime and fire fighters
fight fire, what do freedom fighters fight? They never
mention that part to us, do they? - George Carlin
</div>
<div id="four">
Great minds discuss ideas; average minds discuss events;
small minds discuss people. - Eleanor Roosevelt
</div>
<p id="link">
<a href="https://www.brainyquote.com/" target="_blank">
Brainy Quote
</a>
</p>
</body>
</html>
发布于 2018-04-03 03:20:45
css:
<style>
div
{
text-align:center;
background-color:red;
}
.linkFrame
{
margin: 0 auto;
background-color: blue;
width:20%;
height: 100%;
}
.linkFrame a
{
color: white;
}
</style>html:
<div><div class="linkFrame"><a href="#">YourText</a></div></div>Tryit编辑器链接:https://www.w3schools.com/code/tryit.asp?filename=FPYX1DG3O9GQ
发布于 2018-04-03 14:11:32
你必须用下面的代码替换你为#link编写的小css代码:
#link{
text-align: center;
}
#link a{
background-color:#0201ff;
color: white;
}https://stackoverflow.com/questions/49617163
复制相似问题