javascript - Adding ng-href to a button in angularjs changes the position of the text inside the button -
i'm starting learn angularjs (using angular-material), , have little problem using ng-href. made toolbar @ top of web page, add "ng-href" attribute button, text inside button isn't centered anymore:
the first 2 buttons have ng-href tag added. third 1 hasn't. otherwise, same.
angular.module('angular2',['ngroute','ngmaterial','ngmessages']) .config(function ($mdthemingprovider,$routeprovider) { $mdthemingprovider.theme('default') .primarypalette('blue') .accentpalette('blue'); $routeprovider .when("/", { templateurl : "main.html" }) .when("/test1", { templateurl : "test1.html" }) .when("/test2", { templateurl : "test2.html" }) }) .controller('mainctrl',function ($scope, $http, $mddialog) { }) ;
.navbutton{ font-weight: bold; margin: 0px; height: inherit; width: 150px; border-radius: 0px; text-transform: none; border: solid; }
<!doctype html> <html lang="en" ng-app="angular2"> <head> <meta charset="utf-8"> <title>angular 2</title> <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=roboto:300,400,500,700,400italic"> <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=material+icons"> <link rel="stylesheet" href="app.css"> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.js"></script> <script src="app.js"></script> </head> <body ng-controller="mainctrl"> <div layout="column"> <md-toolbar class="md-menu-toolbar" style="height: 64px"> <div layout="row" style="height: inherit"> <md-toolbar-filler flex="5" style="height: inherit" layout layout-align="center center"> <md-icon class="material-icons md" style="font-size: 48px; height: 48px; width: 48px">mail_outline </md-icon> </md-toolbar-filler> <div flex layout="row" layout-align="start center" style="height: inherit"> <md-button class="md-primary navbutton" ng-href="#/">main</md-button> <md-button class="md-primary navbutton" ng-href="#/test1">test 1</md-button> <md-button class="md-primary navbutton">test 2</md-button> </div> </div> </md-toolbar> <div ng-view></div> </div> </body> </html>
somehow couldn't manage center text inside buttons after added ng-href attribute.
i couldn't fiddle recreate this. played md-button directive , works fine this. there potentially in app.css conflicting.
when md-button sees href or ng-href, create <a>
tag , put button content <span>
.
<md-button class="md-primary navbutton" ng-href="#/test1">test 1</md-button>
becomes
<a class="md-primary navbutton md-button md-ink-ripple" ng-transclude="" ng-href="#/test1" href="#/test1"> <span class="ng-scope">test 1</span> </a>
angular-material.css gives <a>
tag text-align:center, check css changing attributes of <span>
when it's within <a>
.
here's fiddle working isn't same yours: https://jsfiddle.net/phanxo14/
Comments
Post a Comment