当内联和浮点数应用于元素时会发生什么

时间:2017-05-31 15:52:48

标签: html

我们不能将width和height属性设置为内联元素,我同意。但是如果我添加了float属性,则使用内联元素。内联元素的宽度和高度被接受。这怎么可能?

<!DOCTYPE html>
<html lang="en-us">
<head>

<style>
.city {
border-style: solid;
border-color: black;
color: black;
max-width: 300px;
background-color: aqua;
display: inline;
float: left;
</style>

</head>
<body>

<h1>Responsive <b>Web Design</b> Demo</h1>
<div class="city test">
 <p>It is the center of the Greater Tokyo Area,  and the most populous metropolitan area in the world.</p>
</div>

<div class="city test">
  <p>New York is an important center for international diplomacy and has ncial capital of the world.</p>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

首先,你的浮动声明在显示声明之后,因此float优先。第二,显示:内联声明是多余的,因为浮动div会将它们排成直线。