直到div结尾的底部边界线,即使文本没有继续

时间:2016-10-06 17:53:11

标签: html css

我正在为我的网站制作一个小的“新闻”标签,但是我希望在div结束之前有一条边界线,即使这意味着它超过了我放的文本,这对每一条新闻都会发生线,目前我已经尝试过这个

.news {
width: 50%;
height: 40%;
background-color: #FFF;
float: right;
margin-top: 50px;
margin-right: 60px;
}

.news a {
text-decoration: none;
color: #000;
font-size: 21px;
}

.news p a {
content: "";
padding-bottom: 1%;
border-bottom: 2px solid #000;
}

.news image {
/* Nothing */
}

我已经定义的边界底部应该一直到div的结尾但是我还没有找到完成这个,所以我想知道这是否可能做到

* {
  margin: 0;
  padding: 0;
  min-width: 1px;
  min-height: 1px;
}
html,
body {
  width: 100%;
  height: 115%;
  overflow-x: hidden;
  background-image: url('../img/bg.jpg');
}
header {
  margin-top: 2%;
  background-color: #FF0000;
  margin-left: 12.1%;
  width: 75%;
  height: 180px;
}
header p {
  font-size: 64px;
  margin-left: 40%;
  padding-top: 4.5%;
}
#nav {
  margin-left: 12.1%;
  width: 75%;
  height: 50px;
  background-color: #FF0000;
  border-bottom: 1px solid #FFFFFF;
}
#nav ul li a {
  display: inline-block;
  text-align: center;
  padding: 11px 14px;
  text-decoration: none;
  font-size: 24px;
}
#content {
  margin-left: 12.1%;
  width: 75%;
  height: 73.9%;
  background-color: #FF0000;
}
.news {
  width: 50%;
  height: 40%;
  background-color: #FFF;
  float: right;
  margin-top: 50px;
  margin-right: 60px;
}
.news a {
  text-decoration: none;
  color: #000;
  font-size: 21px;
}
.news p a {
  content: "";
  padding-bottom: 1%;
  border-bottom: 2px solid #000;
}
.news image {
  /* I am not sure what to do here just yet */
}
#form {
  padding-top: 10%;
  width: 100%;
  text-align: center;
  display: block;
}
#form label {
  font-size: 25px;
  border: none;
}
#form input {
  width: 30%;
  height: 30px;
  margin-bottom: 2%;
}
#form input[type=text],
input[type=password] {
  border: 1px solid #FFFFFF;
  border-radius: 2%;
}
#form input[type=text],
input[type=password] {
  outline: none;
}
#form input[type=submit] {
  background-color: #006099;
  border: 1px solid #006099;
}
#form input[type=submit]:focus {
  background-color: #005099;
  outline: none;
}
#form label p {
  color: #11FF00;
}
.downloadable {
  text-align: center;
  padding-top: 80px;
}
.downloadable a {} .downloadable a img {
  width: 40%;
}
.downloadable a img:hover {
  -webkit-filter: blur(1px);
  -moz-filter: blur(1px);
  -o-filter: blur(1px);
  -ms-filter: blur(1px);
  filter: blur(1px);
}
footer {
  text-align: center;
  background-color: #FF9900;
  width: 75%;
  margin-left: 12.1%;
}
#nav #right {
  float: right;
}
#nav ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: 100%;
  border-top: 1px solid #FFFFFF;
}
#nav ul li {
  float: left;
}
#nav ul a:hover {
  transition: 0.5s;
  background-color: #FFFF0F;
}
#login {
  display: none;
  float: right;
  margin-top: 2%;
  margin-right: 5%;
  width: 25%;
  height: 20%;
  border: 1px solid #444444;
  background-color: #FFFFFF;
}
#login form {
  margin-left: 15%;
  margin-top: 8%;
}
<!DOCTYPE html>
<html>

<head>
  <title>Website</title>
  <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>

<body>
  <header>
    <p>Lost Story</p>
  </header>
  <div id="nav">
    <ul>
      <li><a href="index.php">Home</a>
      </li>
      <?php if(!isset($_COOKIE[ 'LoggedIn'])) { echo "<li><a href=\"register.php\ ">Register</a></li>"; } ?>
      <li><a href="downloads.php">Downloads</a>
      </li>
      <li><a href="forums.php">Forums</a>
      </li>
      <li><a href="donate.php">Donate</a>
      </li>
      <li><a href="vote.php">Vote</a>
      </li>
      <div id="right">
        <?php if(isset($_COOKIE[ 'LoggedIn']) && !empty($_COOKIE[ 'LoggedIn'])) { echo "<li><a href=\"php/logout.php\ ">Log Out</a></li>"; } else { echo "<li><a href=\"login.php\ ">Log in</a></li>"; } ?>
      </div>
    </ul>
  </div>
  <div id="content">
    <div class="news">
      <p><a href="location-to-news.php">This is a test</a>
      </p>

    </div>
  </div>
  <footer>Website made by Lucas Ouwens</footer>
</body>

</html>

3 个答案:

答案 0 :(得分:1)

将您的.news p a部分改为:

.news p a {
   content: "";
   padding-bottom: 1%;
   border-bottom: 2px solid #000;
   display: block;
   width: 100%;
}

<a>这样的内联元素只会与其内容一样宽。通过将<a>更改为display: block;,您可以根据自己的喜好更改其宽度。在这种情况下,我相信你想要width: 100%;

答案 1 :(得分:0)

border-bottom直到最后,因为您应用它的a元素显示inline(默认display)并获取内容的宽度

display: block添加到.news p a,它将扩展到整个宽度。

干杯!

以下代码段:

&#13;
&#13;
* {
  margin: 0;
  padding: 0;
  min-width: 1px;
  min-height: 1px;
}
html,
body {
  width: 100%;
  height: 115%;
  overflow-x: hidden;
  background-image: url('../img/bg.jpg');
}
header {
  margin-top: 2%;
  background-color: #FF0000;
  margin-left: 12.1%;
  width: 75%;
  height: 180px;
}
header p {
  font-size: 64px;
  margin-left: 40%;
  padding-top: 4.5%;
}
#nav {
  margin-left: 12.1%;
  width: 75%;
  height: 50px;
  background-color: #FF0000;
  border-bottom: 1px solid #FFFFFF;
}
#nav ul li a {
  display: inline-block;
  text-align: center;
  padding: 11px 14px;
  text-decoration: none;
  font-size: 24px;
}
#content {
  margin-left: 12.1%;
  width: 75%;
  height: 73.9%;
  background-color: #FF0000;
}
.news {
  width: 50%;
  height: 40%;
  background-color: #FFF;
  float: right;
  margin-top: 50px;
  margin-right: 60px;
}
.news a {
  text-decoration: none;
  color: #000;
  font-size: 21px;
}
.news p a {
  content: "";
  padding-bottom: 1%;
  border-bottom: 2px solid #000;
  display: block;
}
.news image {
  /* I am not sure what to do here just yet */
}
#form {
  padding-top: 10%;
  width: 100%;
  text-align: center;
  display: block;
}
#form label {
  font-size: 25px;
  border: none;
}
#form input {
  width: 30%;
  height: 30px;
  margin-bottom: 2%;
}
#form input[type=text],
input[type=password] {
  border: 1px solid #FFFFFF;
  border-radius: 2%;
}
#form input[type=text],
input[type=password] {
  outline: none;
}
#form input[type=submit] {
  background-color: #006099;
  border: 1px solid #006099;
}
#form input[type=submit]:focus {
  background-color: #005099;
  outline: none;
}
#form label p {
  color: #11FF00;
}
.downloadable {
  text-align: center;
  padding-top: 80px;
}
.downloadable a {} .downloadable a img {
  width: 40%;
}
.downloadable a img:hover {
  -webkit-filter: blur(1px);
  -moz-filter: blur(1px);
  -o-filter: blur(1px);
  -ms-filter: blur(1px);
  filter: blur(1px);
}
footer {
  text-align: center;
  background-color: #FF9900;
  width: 75%;
  margin-left: 12.1%;
}
#nav #right {
  float: right;
}
#nav ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: 100%;
  border-top: 1px solid #FFFFFF;
}
#nav ul li {
  float: left;
}
#nav ul a:hover {
  transition: 0.5s;
  background-color: #FFFF0F;
}
#login {
  display: none;
  float: right;
  margin-top: 2%;
  margin-right: 5%;
  width: 25%;
  height: 20%;
  border: 1px solid #444444;
  background-color: #FFFFFF;
}
#login form {
  margin-left: 15%;
  margin-top: 8%;
}
&#13;
<!DOCTYPE html>
<html>

<head>
  <title>Website</title>
  <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>

<body>
  <header>
    <p>Lost Story</p>
  </header>
  <div id="nav">
    <ul>
      <li><a href="index.php">Home</a>
      </li>
      <?php if(!isset($_COOKIE[ 'LoggedIn'])) { echo "<li><a href=\"register.php\ ">Register</a></li>"; } ?>
      <li><a href="downloads.php">Downloads</a>
      </li>
      <li><a href="forums.php">Forums</a>
      </li>
      <li><a href="donate.php">Donate</a>
      </li>
      <li><a href="vote.php">Vote</a>
      </li>
      <div id="right">
        <?php if(isset($_COOKIE[ 'LoggedIn']) && !empty($_COOKIE[ 'LoggedIn'])) { echo "<li><a href=\"php/logout.php\ ">Log Out</a></li>"; } else { echo "<li><a href=\"login.php\ ">Log in</a></li>"; } ?>
      </div>
    </ul>
  </div>
  <div id="content">
    <div class="news">
      <p><a href="location-to-news.php">This is a test</a>
      </p>

    </div>
  </div>
  <footer>Website made by Lucas Ouwens</footer>
</body>

</html>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

也许您可以使用 hr 标记并设置样式吗?见下文(红线),这一行:

<hr style="border-top: 2px solid; background-color: #ff0000; color:#ff0000">

&#13;
&#13;
* {
	margin: 0;
	padding: 0;
	min-width: 1px;
	min-height: 1px;
	}

html,body {
	width: 100%;
	height: 115%;
	overflow-x: hidden;
	background-image: url('../img/bg.jpg');
	}



header {
	margin-top: 2%;
	background-color: #FF0000;
	margin-left: 12.1%;
	width: 75%;
	height: 180px;
}

header p {
	font-size: 64px;
	margin-left: 40%;
	padding-top: 4.5%;
}

#nav {
	margin-left: 12.1%;
	width: 75%;
	height: 50px;
	background-color: #FF0000;
	border-bottom: 1px solid #FFFFFF;
}

#nav ul li a {
	display: inline-block;
	text-align: center;
	padding: 11px 14px;
	text-decoration: none;
	font-size: 24px;
	}
	
#content {
	margin-left: 12.1%;
	width: 75%;
	height: 73.9%;
	background-color: #FF0000;
}

.news {
	width: 50%;
	height: 40%;
	background-color: #FFF;
	float: right;
	margin-top: 50px;
	margin-right: 60px;
}

.news a {
	text-decoration: none;
	color: #000;
	font-size: 21px;
}

.news p a {
	content: "";
	padding-bottom: 1%;
	border-bottom: 2px solid #000;
}

.news image {
	/* I am not sure what to do here just yet */
}


#form {
	padding-top: 10%;
	width: 100%;
	text-align: center;
	display: block;
	
}

#form label {
	font-size: 25px;
	border: none;
	}

#form input {
	width: 30%;
	height: 30px;	
	margin-bottom: 2%;
}

#form input[type=text], input[type=password] {
	border: 1px solid #FFFFFF;
	border-radius: 2%;
}

#form input[type=text], input[type=password] {
	outline: none;
}

#form input[type=submit] {
	background-color: #006099;
	border: 1px solid #006099;
}

#form input[type=submit]:focus {
	background-color: #005099;
	outline: none;
}

#form label p {
	color: #11FF00;
}

.downloadable {
	text-align: center;
	padding-top: 80px;

}

.downloadable a {

}

.downloadable a img {
	width: 40%;
}

.downloadable a img:hover {
-webkit-filter: blur(1px);
-moz-filter: blur(1px);
-o-filter: blur(1px);
-ms-filter: blur(1px);
filter: blur(1px);

}

footer {
	text-align: center;
	background-color: #FF9900;
	width: 75%;
	margin-left: 12.1%;
}

#nav #right {
	float: right;
}

#nav ul {
	list-style-type: none;
	margin: 0;
	padding: 0;
	width: 100%;
	border-top: 1px solid #FFFFFF;
	
}

#nav ul li {
	float: left;
}

#nav ul a:hover {
	transition: 0.5s;
	background-color: #FFFF0F;
}

#login {
	display: none;
	float: right;
	margin-top: 2%;
	margin-right: 5%;
	width: 25%;
	height: 20%;
	border: 1px solid #444444;
	background-color: #FFFFFF;
}

#login form {
	margin-left: 15%;
	margin-top: 8%;
}
&#13;
<!DOCTYPE html>
<html>
	<head>
		<title>Website</title>
		<link rel="stylesheet" type="text/css" href="css/style.css"/>
	</head>
	<body>
		<header><p> Lost Story </p></header>
				<div id="nav">
			<ul>
				<li><a href="index.php">Home</a></li>
				<?php
				if(!isset($_COOKIE['LoggedIn'])) {
				echo "<li><a href=\"register.php\">Register</a></li>";
				}
				?>
				<li><a href="downloads.php">Downloads</a></li>
				<li><a href="forums.php">Forums</a></li>
				<li><a href="donate.php">Donate</a></li>
				<li><a href="vote.php">Vote</a></li>
					<div id="right">
					<?php
						if(isset($_COOKIE['LoggedIn']) && !empty($_COOKIE['LoggedIn'])) {
						echo "<li><a href=\"php/logout.php\">Log Out</a></li>";
						} else {
							echo "<li><a href=\"login.php\">Log in</a></li>";
						}
					?>
					</div>
			</ul>
		</div>
		<div id="content">
			<div class="news">
                <p>
                    <a href="location-to-news.php">This is a test</a>
                    <hr style="border-top: 2px solid; background-color: #ff0000; color: #ff0000">
                </p>
			</div>
		</div>
	  <footer> Website made by Lucas Ouwens </footer>
	</body>
</html>
&#13;
&#13;
&#13;