width:100%和width:auto的区别

width:auto比较聪明,如果margin已经左右占去10px的空间,那么width给的值就是580px。

<style>
div{
width:600px;
overflow:auto;
background:#ccc;
} p{
width:auto;
margin:10px;
background:red;
}
</style>
</head>
<body> <div>
<p>123</p>
</div> </body>
</html>

如果是width:100%,则说明p的width会得到600px就已经充满div区域,然后自己又有margin,所以会出现滚动条。

div{
width:600px;
overflow:auto;
background:#ccc;
} p{
width:100%;
margin:10px;
background:red;
}
</style>
</head>
<body> <div>
<p>123</p>
</div>

都是以父元素的宽度为参照。

CSS width:100%和width:auto的区别的更多相关文章

  1. css height:100%和height:auto的区别

    css height:100%和height:auto的区别 height:auto,是指根据块内内容自动调节高度.height:100%,是指其相对父块高度而定义的高度,也就是按照离它最近且有定义高 ...

  2. CSS的width:100%和width:auto区别

    CSS的width:100%和width:auto区别 一.   问题 前段时间在调整树结构的时候,发现如果树的节点名称比较长的话在IE6下则不会撑开外面的元素,导致节点的名称只显示了一半,同时图标和 ...

  3. height:100%和height:auto的区别

    一直不明白height:100%和height:auto的区别,最近在制作前端页面时都用了height:100%;overflow:hidden; ,可是有些浏览器出现莫名的奇妙的问题,但换成heig ...

  4. width:100%;与width:auto;的区别

    <div> <p>1111</p> </div> div{ width:980px; background-color: #ccc; height:30 ...

  5. css width="100" style ="width:100px" 区别

    1. width="100"是正确的,而 width="100px"是错误的, style = "width:100px"是正确的 2. s ...

  6. width:100%和width:auto区别

    在div父元素是body时 1.先看没有width限制的div <div style="border:1px solid red; margin-left:50px; margin-r ...

  7. width:100%和width:inherit

    前几天遇到过这么一个问题.我想让子盒子的宽度等于父盒子的宽度.父盒子宽度为一个具体值比如说200px.我将子盒子宽度设为了100%.按道理说应该是可以等于父盒子的宽度的,但结果并没有,而是通栏了.然后 ...

  8. css中width:auto和width:100%的区别是什么

    width的值一般是这样设置的: 1,width:50px://宽度设为50px 2,width:50%://宽度设为父类宽度的50% 3,还有一个值是auto(默认值),宽度是自动的,随着内容的增加 ...

  9. width:auto 和 width:100%有什么区别

    width:auto 和 width:100%有什么区别 宽度计算不同 <div class="parent"> <span class="child& ...

随机推荐

  1. USACO Section 2.3: Controlling Companies

    这题的dp里的check里的函数要考虑k control i control j和i control j control k的情况 /* ID: yingzho1 LANG: C++ TASK: co ...

  2. USACO Section 2.2: Preface Numbering

    搬了leetcode的代码 /* ID: yingzho1 LANG: C++ TASK: preface */ #include <iostream> #include <fstr ...

  3. 可辨别iPhone真假的网址

    在如下的网址中输入iPhone的序列号,可知道该iPhone的型号,生产日期,激活状态等. 1.http://www.app111.org/ 2.http://act.weiphone.com/wet ...

  4. 两个学生OJ差集

    这个程序非常简单,因为用了最笨的办法,不过运行一点儿也不慢... 在我们学校OJ平台每个人的个人信息中都有Solved Problems List,我们可以用这个简单的程序输入两个人解决问题的所有题号 ...

  5. Android内存管理(2)HUNTING YOUR LEAKS: MEMORY MANAGEMENT IN ANDROID PART 2

    from: http://www.raizlabs.com/dev/2014/04/hunting-your-leaks-memory-management-in-android-part-2-of- ...

  6. JAVA设计模式之【抽象工厂模式】

    1.产品接口,电视和空调 public interface Television // 电视接口 { public void play(); } public interface AirConditi ...

  7. ERROR 1442 (HY000):because it is already used by statement which invoked this stored function/tr

    看到mysql的触发器,随手写了一个: mysql> create trigger t_ai_test -> after insert on test -> for each row ...

  8. in command-line: path> mvn eclipse:clean path> mvn -Dwtpversion=1.5 eclipse:eclipse path> mvn eclipse:eclipse in eclipse: Project / clean...

    原因:tomcat已经启动了 2007-10-9 12:26:16 org.apache.coyote.http11.Http11AprProtocol init严重: Error initializ ...

  9. Qt之模型/视图(自定义进度条)

    简述 在之前的章节中分享过关于QHeaderView表头排序.添加复选框等内容,相信大家模型/视图.自定义风格有了一定的了解,下面我们来分享一个更常用的内容-自定义进度条. 实现方式: 从QAbstr ...

  10. 【转】DB2 常用命令

    1. 打开命令行窗口  #db2cmd 2. 打开控制中心  # db2cmd db2cc 3. 打开命令编辑器  db2cmd db2ce =====操作数据库命令===== 4. 启动数据库实例  ...