CSS div宽度自适应

WBOY
Release: 2016-06-01 09:53:20
Original
1058 people have browsed it

代码实例如下:

<code class="language-html">


<meta charset="utf-8">
<meta name="author" content="http://www.manongjc.com/">
<title>码农教程</title>
<style type="text/css">
.parent{
  width:400px;
  height:400px;
  border:1px solid red;
}
.children{
  border:1px solid blue;
  height:50px;
}
</style>


<div class="parent">
  <div class="children">码农教程欢迎你</div>
</div>

</code>
Copy after login

以上代码可以看出,默认状态下,并不能够实现我们想要的效果。下面对以上代码进行修改如下:

<code class="language-html">


<meta charset="utf-8">
<meta name="author" content="http://www.manongjc.com/">
<title>码农教程</title>
<style type="text/css">
.parent{
  width:400px;
  height:400px;
  border:1px solid red;
}
.children{
  border:1px solid blue;
  height:50px;
  display:inline-block;
  *display:inline;
  *zoom:1;
}
</style>


<div class="parent">
  <div class="children">码农教程欢迎你</div>
</div>

</code>
Copy after login

以上代码实现我们想要的效果,并且各浏览器兼容性良好,主要是添加如下核心代码:

<code class="language-css">display:inline-block; 
*display:inline; 
*zoom:1;</code>
Copy after login

大家可以把上面实例代码复制到这里运行一下,查看一下效果。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!