【问题标题】:CSS div extending beyond page limits, adds horizontal scrolling barCSS div 超出页面限制,添加水平滚动条
【发布时间】:2018-10-21 01:18:03
【问题描述】:

我目前正在处理一个课程项目,但我遇到了一些问题,我的 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>

提前致谢!

【问题讨论】:

    标签: html css width scrollbar


    【解决方案1】:

    添加 -moz-box-sizing:边框框; box-sizing: 边框;

    到 .contenido{}

    您可以在此处阅读有关 box-sizing 的更多信息:

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

    【讨论】:

    • 工作完美。非常感谢您的快速回答,有时间我会读一读!你是救生员。
    猜你喜欢
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多