html - 使用 inline 可以达到相同的结果吗?

标签 html css inline

我想知道是否可以使用 inlineinline-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>

最佳答案

即使是这样,inlineinline-block 属性也不打算这样做。这些值表示显示属性,即该元素应放置在文本流中,并在其中表现得与此文本相同,或者保持一些 block 状属性,同时仍与文本对齐。不应该肯定用于构造像这样的布局。

关于html - 使用 inline 可以达到相同的结果吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40143179/

相关文章:

javascript - 在单个页面中使用 JavaScript 绘制一些图像 map

html - 如何防止内联列表元素的两侧在 HTML 中被截断?

c++ - 静态内联函数中的局部函数静态对象不共享

c++ - 如何将返回类型推导、模板实例化与头文件结合起来?

javascript - 如何将 ID 值添加到 div 追加

javascript - 在浏览器调整大小后更改 div 的高度取决于文本的长度和字体的大小是个好主意吗?

html - 使用 CSS 操作 html 输入表单?

css 错误 - 添加横幅会弄乱页面的滚动条

html - bgcolor 属性不适用于 Bootstrap

html - 为什么第二个元素有边距?