I'm having trouble with centering Bootstrap button in panel. Margin right and left auto doesn't work. Is there a way to properly center the button? The Button needs to be centered because of the mobile scale.
Code:
<div class="n_monitor">
<div class="panel panel-default">
<div class="panel-body">
<div class="btn-group">
<button type="button" class="btn btn-default">Server 1</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
</ul>
</div>
</div>
</div>
</div>
CSS:
.n_monitor .panel {
width: 628px;
border: solid 1px #ebebeb;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
height: 94px;
box-shadow: none;
margin: 0;
background-color: #f4f4f4;
margin-left: auto;
margin-right: auto;
}
.n_monitor .btn {
width: 126px;
height: 54px;
background-color: #3baed8;
border: none;
color: #fff;
font-size: 14px;
border-radius: 3px;
}
答案 0 :(得分:4)
将Bootstrap的Alignment Class "use strict";
var gulp = require('gulp'),
connect = require('gulp-connect'),
open = require('gulp-open'),
browserify = require('browserify'),
reactify = require('reactify'),
source = require('vinyl-source-stream'),
eslint = require('gulp-eslint'),
http = require('http'),
concat = require('gulp-concat');
var config = {
port: process.env.PORT || 1991,
devBaseUrl: 'http://localhost',
paths: {
html: './src/*.html',
js: './src/**/*.jsx',
css: './public/stylesheets/**/*.css',
dist: './dist',
mainJs: './src/main.jsx'
}
};
//start a local dev server
gulp.task('connect', function() {
connect.server({
root: ['dist'],
port: config.port,
base: config.devBaseUrl,
livereload: true
});
});
gulp.task('open', ['connect'], function() {
gulp.src('dist/index.html')
.pipe(open({uri: config.devBaseUrl + ':' + config.port + '/'}));
});
gulp.task('html', function() {
gulp.src(config.paths.html)
.pipe(gulp.dest(config.paths.dist))
.pipe(connect.reload());
});
gulp.task('js', function() {
browserify(config.paths.mainJs)
.transform(reactify)
.bundle()
.on('error', console.error.bind(console))
.pipe(source('bundle.js'))
.pipe(gulp.dest(config.paths.dist + '/scripts'))
.pipe(connect.reload());
});
gulp.task('css', function() {
gulp.src(config.paths.css)
.pipe(concat('bundle.css'))
.pipe(gulp.dest(config.paths.dist + '/css'))
.pipe(connect.reload());
});
gulp.task('lint', function() {
return gulp.src(config.paths.js)
.pipe(eslint({configFile: 'eslint.config.json'}))
.pipe(eslint.format());
});
gulp.task('watch', function() {
console.log('Files have been changed... Reloading...');
gulp.watch(config.paths.html, ['html']);
gulp.watch(config.paths.css, ['css']);
gulp.watch(config.paths.js, ['js']);
});
gulp.task('default', ['html', 'js', 'css','lint', 'open', 'watch']);
添加到text-center
。
.panel-body
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.n_monitor .panel {
width: 100%;
border: solid 1px #ebebeb;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
height: 94px;
box-shadow: none;
margin: 0;
background-color: #f4f4f4;
margin-left: auto;
margin-right: auto;
}
.n_monitor .btn {
width: 126px;
height: 54px;
background-color: #3baed8;
border: none;
color: #fff;
font-size: 14px;
border-radius: 3px;
}
答案 1 :(得分:2)
您只需添加&#34; center-block&#34;类按钮。
e.g。
<button class = "center-block">Test</button>
答案 2 :(得分:0)
这对我来说总是最好的。使用Bootstrap时的特殊性非常有效。
#button{
display: table; margin: 0 auto;
}
答案 3 :(得分:0)
将文本居中于按钮的父级(.n_monitor .panel-body)
xxx123