两个div并排,右边的div需要铺满剩余空间?该如何定义CSS
<%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title></title> <%--<link rel="stylesheet" type="text/css" href="css/main.css">--%> <style type="text/css"> .div1 { background-color: lightseagreen; width: 15%; height: 100%; float: left; } .div2 { background-color: chocolate; height: 100%; float: left; } </style></head><body> <div class="div1"> DIV1 </div> <div class="div2"> DIV2 </div></body></html>
你试试看div2右浮动,然后给两个div设置固定宽度,
div2 width: 85%;
你试试看div2右浮动,然后给两个div设置固定宽度,
div2 width: 85%;
第一种,都向左浮动, width 各占相应百分比(注意div1 ,div2 有padding margin 等属性会影响宽度 )
两div高度可以不一样,
div1 15% + div1 85% = 100% 宽
第二种 仅div1 左浮动,div2 100%宽(不浮动), div1 自然覆盖在div2上,再对div2做相应处理。
这种适合左边的高度 大于或等于右边的高度。
.div1 {
float: left; width: 15%;
background-color: lightseagreen;
}
.div2 {
width: 100%;
background-color: chocolate;
}
.div2增加属性
width: 85%;
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号