为什么我的HTML h1元素跨越两行,当它有足够的空间使用一个? [英] Why is my HTML h1 element spanning two lines when it has plenty of space to use one?

查看:90
本文介绍了为什么我的HTML h1元素跨越两行,当它有足够的空间使用一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上工作,标题( h1 )正在占用两行,它有空间,但不应该,因为它有很多空间只占一条线。我想要它只跨越一条线,我想知道为什么它不这样做?谢谢!

I'm working on my website and the heading (h1) text is taking up two lines, which it has space for but shouldn't as it has plenty of space to just take up one line. I want it to only span one line, and I'm wondering why it isn't doing that? Thanks!

我正在处理的文本是< h1> id =welcome,content 欢迎来到我的网站!

The text I'm taking about is the <h1>, id="welcome", content Welcome to my website!.

PS

这里是我的代码:

Here's my Code:

li {
	display: inline-block;
}

ul {
	float: right;
	margin: 0px;
	padding: 0px;
	position: relative;
	top: -45px;
}

nav li a:link {
	font-weight: bold;
	display: inline-block;
	text-decoration: none;
	font-family: times;
	font-size: 24px;
	list-style: none;
	padding: 5px;
	margin: 3px;
	margin-top: 0px;
	border: 2px solid black;
	border-radius: 5px;
	color: black;
}

nav li a:visited {
	color: rgba(0,0,0,0.7);
}

nav li a:hover {
	background-color: rgba(0,0,0,0.6);
	color: white;
}

nav li a:active {
	color: black;
	border-color: black;
}

nav {
	width: 1000px;
	height: 130px;
	background-color: rgba(255,255,255,0.7);
	padding: 10px;
	margin: 0px auto;
	border-bottom-left-radius: 10px;
	border-bottom-right-radius: 10px;
}

input[type=search] {
	font-size: 16px;
}

#searchbox {
	float: right;
}

#logo {
	width: 200px;
	font-family: arial;
	margin: 0px;
	padding: 0px;
	font-size: 26px;
}

#logo_jeff, #logo_arries, #logo_website {
	margin: 0px;
}

#logo_jeff {
	letter-spacing: 35.5px;
}

#logo_arries {
	letter-spacing: 11px;
}

#logo_website {
	letter-spacing: 4px;
}










body {
    background-image: url("../pictures/jeff_skiing.jpg");
    background: red;
	min-height: 500px;
	background-attachment: fixed;
	background-position: center;
	background-repeat: no-repeat;
	background-size: cover;
	margin: 0px;
	padding: 0px;
}

aside {
	position: absolute;
	right: 0px;
	background-color: rgba(255,255,255,0.9);
	width: 170px;
	height: 600px;
	margin: 0;
	border-top-left-radius: 10px;
	border-bottom-left-radius: 10px;
	padding: 10px;
}









#main_content {
	width: 1000px;
	min-height: 600px;
	display: block;
	background-color: rgba(255,255,255,0.7);
	margin: 0 auto;
	border-top-left-radius: 10px;
	border-top-right-radius: 10px;
	position: relative; top: 0px;
	padding: 10px;
}

#here_you_can_learn {
	font-size: 47px;
	color: gray;
	margin: 0 auto;
	margin-bottom: 10px;
	text-align: center;
}

#welcome {
	border: 1px solid #999;
	color: rgb(0, 0, 110);
	font-size: 100px;
	margin: 10px;
	margin-top: 20px;
	margin-bottom: 130px;
	padding: 0px;
}

#down_arrow {
	height: 50px;
	margin: auto;
	display: block;
	padding: 10px;
}

#most_frequent {
	width: 600px;
	vertical-align: top;
	display: inline-block;
	background-color: rgba(0,0,0,0.1);
	border-radius: 3px;
}

#m_f_heading {
	font-size: 30px;
	margin: 10px;
	padding: 5px;
	text-align: center;
	background-color: rgba(0,0,0,0.2);
	border-radius: 5px;
}



#m_f_show_more {
	font-size: 20px;
	margin: 10px;
	padding: 5px;
	text-align: center;
	background-color: rgba(0,0,0,0.2);
	border-radius: 5px;
}


#recent_activity {
	width: 375px;
	display: inline-block;
	background-color: rgba(0,0,0,0.1);
	border-radius: 3px;
}

#r_a_heading {
	font-size: 30px;
	margin: 10px;
	padding: 5px;
	text-align: center;
	background-color: rgba(0,0,0,0.2);
	border-radius: 5px;
}

#r_a_body {
	font-size: 15px;
	margin: 10px;
	padding: 5px;
	text-align: center;
	background-color: rgba(0,0,0,0.2);
	border-radius: 5px;
}

#r_a_show_more {
	font-size: 20px;
	margin: 10px;
	padding: 5px;
	text-align: center;
	background-color: rgba(0,0,0,0.2);
	border-radius: 5px;
}

#r_a_show_more_link:visited {
 color: black;
}

#r_a_show_more_link:hover {
  color: gray;
  background-color: rgba(0,0,0,0.9);
}

#r_a_show_more_link:active {
  color: black;
}

<!DOCTYPE html>

<head>
<title>Home | Jeff's Website</title>

<link href="styles/main_navigation.css" type="text/css" rel="stylesheet" />
<link href="styles/body.css" type="text/css" rel="stylesheet" />
<link href="styles/main_content.css" type="text/css" rel="stylesheet" />

</head>


<body>

<!--Main Nav-->
<header>
	<nav>
		
			<form action="" id="searchbox">
			<input id="search_input" type="search" name="searchmysite" placeholder="Search my Site!">
			<input type="submit" value="Search!">
		</form>
		
		<div id="logo">
			<h1 id="logo_jeff">JEFF</h1>
			<h1 id="logo_arries">ARRIES</h1>
			<h1 id="logo_website">WEBSITE</h1>
		</div>

		<ul>
			<li><a href="">Home</a></li>
			<li><a href="">Blog</a></li>
			<li><a href="">Trips</a></li>
			<li><a href="">Politics</a></li>
			<li><a href="">Pictures</a></li>
			<li><a href="">Videos</a></li>
			<li><a href="">Computer</a></li>
			<li><a href="">Misc</a></li>
		</ul>
	</nav>
</header>


<!--Welcome to jeff's website-->

<div>
	<h1 id="welcome">Welcome to my Website!</h1>
	
	<p id="space_filler"></p>
	
	<a href="#here_you_can_learn">
	<img src="pictures/down_arrow.png" id="down_arrow"/>
	</a>
</div>

<!--right side nav-->

<aside>
	<p>this is aside</p>

</aside>


<!--Main Content-->

<div id="main_content">
	<h2 id="here_you_can_learn">Here you can learn about me and my adventures!</h2>

<!--Most Frequently visited pages: on left side of page-->
	<div id="most_frequent">
		<p id="m_f_heading">Most frequently visted pages!</p>
		
		
		
		<a href=""><p id="m_f_show_more">Show More</p></a>
	
	</div>
	
<!--Recent Activity: on the right side of page-->
	<div id="recent_activity">
		<p id="r_a_heading">Recent Activity</p>
		
		
		<p id="r_a_body">test</p>
		
		
		<a href="" id="r_a_show_more_link"><p id="r_a_show_more">Show More</p></a>
	</div>

</div>

</body>

推荐答案

这是由您的搜索框和您的 ul 菜单上的浮动引起的。如果你要使用浮动,你应该清除它们,虽然一般来说,浮动的东西只会导致更多的问题,而不是修复。

It's being caused by the floats on your search-box and on your ul menu. If you're going to use floats you should clear them, although in general, floating things just causes more problems than it fixes.

标题添加清除修正:

header::after {
   clear: both;
   content: '';
   display: table;
}

CodePen

这篇关于为什么我的HTML h1元素跨越两行,当它有足够的空间使用一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆