CSS div超出页面限制,添加了水平滚动条

时间:2018-10-20 15:59:56

标签: html css width scrollbar

我目前正在上一个班级项目,但由于未知原因,我的div超出了页面限制,因此遇到了问题。这就是我的意思: You can see that the div extends and adds a white space

我不确定为什么会这样。这是我到目前为止编写的代码:

    body{
        margin: 0;
        padding: 0;
    	background-image: url();
    }
    .logo{
    	max-width: 100%;
        max-height: 100%;
    	float:left;
    }
    .banner{
    	width: 100%;
    	height: 10%;
    	background-color: #325999;
    	}
    .bar_nav{
    	background-color: rgb(66, 117, 201, 0.9);
    	width: stretch;
    	height: 30px;
    	/*top y left son necesarios para que la barra se desplace*/
    	left: 0px;
    	top:0px;
    	padding: 5px;
    	z-index:100;
    	position: sticky;
    	margin: 0;
    }
    .boton_top{
    	float: left;
    	padding: 5px;
    	margin-right: 5px;
    	font-weight: bold;
    	font-size: 20px;
    	font-family: verdana;
    	vertical-align: middle;
    	left: 0px;
    	bottom: 2px;
    	bottom: 18px;
    	display: block;
    	text-decoration: none;
    	background-color: #84b3ff;
    	color: white;
    	position: relative;
    	float:left;
    }
    .boton_top:after{
    	content: '';
    	position: absolute;
    	top: 0;
    	left: 0;
    	width: 0;
    	height: 100%;
    	background-color: rgba(255,255,255,0.4);
    }
    
    .boton_top:hover:after{
    	width: 120%;
    	background-color: rgba(255,255,255,0);
    	transition: all 0.4s ease-in-out;
    }
    .boton_top:hover{
    	background-color: #0099ff;
    }
    
    .boton_banner{
    	float: right;	
    	padding: 5px;
    	font-weight: bold;
    	font-size: 13px;
    	font-family: verdana;
    	text-decoration: none;
    	color: white;
    	background-color: #4e994e;
    	/*border: 1px solid white;*/
    	position:relative;
    	display:block;
    	margin: auto;
    }
    
    .boton_banner:hover{
    	/*border: 3px solid white;*/
    	font-size: 14px;
    	background-color: #79bb79;
    	transition: 0.2s;
    }
    
    .contenido{
    	padding: 5px;
    	background-color: rgba(255,255,255,0.4);
    	margin-left: 10%;
    	margin-right:10%;
    	width:80%;
    	position:relative;
    	display:inline-block;
    }
 <html>
    <head>
    	<title> Eco Coelum </title>
    	<link rel="stylesheet" type="text/css" href="style.css">
    </head>
    
    <body >
    
    
    
    <div class="banner">
    	<img src="img/logo.png" class="logo"/>
    	<p><a href="regis.html" class="boton_banner">Registrate</a></p>
    	<p><a href="login.html" class="boton_banner">Iniciar Sesión</a></p>
    	<p><a href="asistencia.html" class="boton_banner">Asistencia</a></p>
    </div>
    <div class="bar_nav">
    	<p><a href="index.html" class="boton_top" >Home</a></p>
    	<p><a href="productos.html" class="boton_top" >Productos</a></p>
    	<p><a href="servicios.html" class="boton_top" >Servicios</a></p>
    	<p><a class="boton_top" >Area Empleados</a></p>
    </div>
    	<div class="contenido">
    	<p>Texto</p>
    	
    	<p>BLABLABLABLABLABLABLABALBLABLA</p>
    	<p>BLABLABLABLABLABLABLABALBLABLA</p>
    	<p>BLABLABLABLABLABLABLABALBLABLA</p>
    	<p>BLABLABLABLABLABLABLABALBLABLA</p>
    	<p>BLABLABLABLABLABLABLABALBLABLA</p>
    	</div>
    
    </body>
    
    
    </html>

谢谢!

1 个答案:

答案 0 :(得分:1)

添加     -moz-box-sizing:边框框;      框大小:border-box;

到.contenido {}

您可以在此处阅读有关框大小的更多信息:

https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing