我想知道是否可以使用 inline
或 inline-block
而不是 float
来获得完全相同的结果,如果可以的话,如何实现?
请参阅以下代码(取自 http://www.w3schools.com/html/tryit.asp?filename=tryhtml_layout_float ):
<!DOCTYPE html>
<html>
<head>
<style>
div.container {
width: 100%;
border: 1px solid gray;
}
header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
}
nav {
float: left;
max-width: 160px;
margin: 0;
padding: 1em;
}
nav ul {
list-style-type: none;
padding: 0;
}
nav ul a {
text-decoration: none;
}
article {
margin-left: 170px;
border-left: 1px solid gray;
padding: 1em;
overflow: hidden;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>City Gallery</h1>
</header>
<nav>
<ul>
<li><a href="#">London</a></li>
<li><a href="#">Paris</a></li>
<li><a href="#">Tokyo</a></li>
</ul>
</nav>
<article>
<h1>London</h1>
<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
<p>Standing on the River Thames, London has been a major settlement for two millennia, its history going back to its founding by the Romans, who named it Londinium.</p>
</article>
<footer>Copyright © W3Schools.com</footer>
</div>
</body>
</html>
最佳答案
即使是这样,inline
和 inline-block
属性也不打算这样做。这些值表示显示属性,即该元素应放置在文本流中,并在其中表现得与此文本相同,或者保持一些 block 状属性,同时仍与文本对齐。不应该肯定用于构造像这样的布局。
关于html - 使用 inline 可以达到相同的结果吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40143179/