html - bootstrap - ancho: 100% niño más grande que el padre
flexbox guia (3)
¿Es esto lo que quieres? eliminar margin-top de #mainicons i
Además, eliminé la parte superior: 250 píxeles, solo por mostrar el ejemplo aquí.
#mainicons {
height: 50px;
width: 70px;
position: fixed;
top: 0px;
left: 0px;
text-align: center;
}
#mainicons>a {
position: relative;
margin-top: 20px;
display: flex;
justify-content: center;
align-items: center;
}
#mainicons i {
display: flex;
flex-direction: column;
height: 40px;
width: 50px;
padding: 10px;
color: #fff;
background: #CE9C87;
text-align: center;
font-size: 15px;
line-height: 40px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons i:hover {
-webkit-box-shadow: inset 7px 0px 0px 0px #CE9C87;
-moz-box-shadow: inset 7px 0px 0px 0px #CE9C87;
box-shadow: inset 7px 0px 0px 0px #CE9C87;
color: #CE9C87;
background: #fff;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons span {
color: #CE9C87;
background: #fff;
width: 100%;
height: 100%;
z-index: -1;
font-size: 15px;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
left: -100px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons a:hover>span {
left: 70px;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<body bgcolor="#E6E6FA">
<div id="mainicons">
<a href="/"><i class="fa fa-home"></i><span>Home</span></a>
<a href="/ask"><i class="fa fa-envelope"></i><span>Ask</span></a>
<a href="/submit"><i class="fa fa-pencil "></i><span>Request</span></a>
<a href="/archive"><i class="fa fa-clock-o"></i><span>Archive</span></a>
</div>
Sé que hay muchos hilos como éste, pero parece que no puedo resolver este width:100%
problema. Tengo esta descripción deslizante en un menú y es más grande que el botón. He intentado agregar box-sizing: border-box;
pero no funcionó. No sé cuál es el problema. Probablemente tiene que ver con los márgenes, el relleno y dos códigos CSS diferentes para #mainicons
y #mainicons i
?
Mi código:
#mainicons {
height: 50px;
width: 70px;
position: fixed;
top: 250px;
left: 0px;
text-align: center;
}
#mainicons>a {
position: relative;
margin-top: 20px;
display: flex;
justify-content: center;
align-items: center;
}
#mainicons i {
display: flex;
flex-direction: column;
margin-top: 20px;
height: 40px;
width: 50px;
padding: 10px;
color: #fff;
background: #CE9C87;
text-align: center;
font-size: 15px;
line-height: 40px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons i:hover {
-webkit-box-shadow: inset 7px 0px 0px 0px #CE9C87;
-moz-box-shadow: inset 7px 0px 0px 0px #CE9C87;
box-shadow: inset 7px 0px 0px 0px #CE9C87;
color: #CE9C87;
background: #fff;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons span {
color: #CE9C87;
background: #fff;
width: 100%;
height: 100%;
z-index: -1;
font-size: 15px;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
left: -100px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons a:hover>span {
left: 70px;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<body bgcolor="#E6E6FA">
<div id="mainicons">
<a href="/"><i class="fa fa-home"></i><span>Home</span></a>
<a href="/ask"><i class="fa fa-envelope"></i><span>Ask</span></a>
<a href="/submit"><i class="fa fa-pencil "></i><span>Request</span></a>
<a href="/archive"><i class="fa fa-clock-o"></i><span>Archive</span></a>
</div>
¡Gracias por la ayuda! :)
Retire el margin-top: 20px;
en #mainicons>a
y #mainicons i
puede ser que quieras algo como esto
retirar
margin-top: 20px
desde #mainicons i
#mainicons {
height: 50px;
width: 70px;
position: fixed;
top: 250px;
left: 0px;
text-align: center;
}
#mainicons>a {
position: relative;
margin-top: 20px;
display: flex;
justify-content: center;
align-items: center;
}
#mainicons i {
display: flex;
flex-direction: column;
/*margin-top: 20px;*/
height: 40px;
width: 50px;
padding: 10px;
color: #fff;
background: #CE9C87;
text-align: center;
font-size: 15px;
line-height: 40px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons i:hover {
-webkit-box-shadow: inset 7px 0px 0px 0px #CE9C87;
-moz-box-shadow: inset 7px 0px 0px 0px #CE9C87;
box-shadow: inset 7px 0px 0px 0px #CE9C87;
color: #CE9C87;
background: #fff;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons span {
color: #CE9C87;
background: #fff;
width: 100%;
height: 100%;
z-index: -1;
font-size: 15px;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
left: -100px;
-webkit-transition: all .5s ease;
-moz-transition: all .5s ease;
-o-transition: all .5s ease;
transition: all .5s ease;
}
#mainicons a:hover>span {
left: 70px;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<body bgcolor="#E6E6FA">
<div id="mainicons">
<a href="/"><i class="fa fa-home"></i><span>Home</span></a>
<a href="/ask"><i class="fa fa-envelope"></i><span>Ask</span></a>
<a href="/submit"><i class="fa fa-pencil "></i><span>Request</span></a>
<a href="/archive"><i class="fa fa-clock-o"></i><span>Archive</span></a>
</div>