如何让按钮停留在同一个盒子里?

时间:2017-10-12 20:15:31

标签: css

我创建了一个按钮,但每当我将窗口缩小时,按钮就不在我的框中了。它看起来不太好看。我想知道如何让我的按钮留在盒子里。查看图片以便更好地理解。 我提供了我的按钮的CSS。我不确定如何为这个问题实现一个好的和有效的解决方案。 我能够通过将宽度更改为100%来解决我的问题。现在我的信已经从我的按钮上切断了。请看图片!

Full Screen

Half size of screen

Letter are getting cut off

.button {
	display: inline-block;
	position: relative;
	cursor: pointer;
	outline: none;
	white-space: nowrap;
//	margin: 5px;
	padding: 0 22px;
	font-size: 14px;
	font-family: 'Roboto', sans-serif, 'Lato';
	height: 40px;
  width: 220px;
	line-height: 40px;
	background-color: #428bca;
	color: #FFF;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 1px;
	border: none;
	text-shadow: 1px 1px 1px rgba(0,0,0,0.2);
   margin: 0 auto;
   text-align: center;

}
.panel-title {
    margin-top: 0;
    margin-bottom: 0;
    font-size: 16px;
    color: #ffffff;
}

.panel-heading {

    color: #428bca;
    background-color: #428bca;
    border-top: 1px solid #dddddd;
  	border-left: 1px solid #dddddd;
    border-right: 1px solid #dddddd;  
    //border-top-right-radius: 3px;
    //border-top-left-radius: 3px;
}

.panel-body {
    padding: 15px;
    border: 1px solid #dddddd;
}
.nobottommargin {
    margin-bottom: 0 !important;
}
.leftmargin-sm {
    margin-left: 30px !important;
}

.button.button-rounded {
	border-radius: 3px;
}

.button.button-reveal {
	padding: 0 28px;
	overflow: hidden;
}

.button.button-large {
	padding: 0 26px;
	font-size: 16px;
	height: 46px;
	line-height: 46px;
}

.button-teal {
	background-color: #428bca;
}

/*code for the icon */
.button-reveal i {
  position: absolute;
  width: 2em;
  height: 100%;
  line-height: 45px;
  background-color: rgba(0, 0, 0, .2);
  text-align: center;
  left: -100%;
  transition: left 0.25s ease;
}
.button-reveal:hover i {
  left: 0;
}
/* code for the letters*/
.button-reveal span {
  display: inline-block;
  margin: 0 2em;
  transition: margin 0.35s ease;
}
.button-reveal:hover span {
  margin: 0 1em 0 3em;
}
<div class="panel-heading">
								<h2 class="panel-title">Access This Service</h2>
							</div>

<div class="panel-body">
  <!-- angular -->
 		
  <div ng-if="c.html" ng-bind-html="c.html"></div>

 <a href="http://zoom.us" class="button button-rounded button-reveal button-large button-teal"><i class="fa fa-forward" aria-hidden="true"></i>
   <span>Go there now!</span></a><br>

Note: If you haven’t accessed Zoom before, create a new account at <a href="http://zoom.us">zoom.us</a>.
</div>

2 个答案:

答案 0 :(得分:1)

.button {
    box-sizing: border-box; /* Include padding within the button's width */
    width: 100%; /* Made the button the full width of its parent */
    padding: 0 22px; /* Add 22 pixels of padding to the left and right of the button */
}

你可能不需要填充,所以你可以这样做:

button {
    width: 100%;
    padding: 0;
}

答案 1 :(得分:0)

填充正在将文本推向右侧和白色空间:nowrap&#39;防止文本换行到第二行。当你使div缩小时,你的文字对于空间来说太宽了,所以它必须去某个地方。如果允许它换行,当宽度太窄时会占据两行。设置最小高度&#39;而不是&#39;身高&#39;所以按钮可以扩展。

button {
    width: 100%;
    padding: 0 5px;
    //height: 40px; 
    min-height: 40px;
    white-space: normal;

}