Reputation: 3819
I am experimenting with Material Design Web 1.0 from March 2019.
When using a card and a button with in it, while the button has been set to be mdc-card__actions--full-bleed
I found no way to center the button text. So my question is:
How to correctly center the button text in this example?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://fonts.gstatic.com; script-src 'unsafe-inline' https://unpkg.com; style-src 'unsafe-inline' https://unpkg.com https://fonts.googleapis.com"/>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test</title>
<link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.css" rel="stylesheet"/>
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/>
<style>
.my-card-content
{
padding: 16px;
}
</style>
</head>
<body>
<div class="mdc-card my-card-content">
<div class="mdc-card__actions mdc-card__actions--full-bleed">
<button class="mdc-button mdc-button--raised mdc-card__action mdc-card__action--button" tabindex="0">
<span class="mdc-button__label">Login</span>
</button>
</div>
</div>
</body>
</html>
Upvotes: 1
Views: 320
Reputation: 1119
You can try this way:
.mdc-button {
justify-content: center !important;
}
.my-card-content {
padding: 16px;
}
.mdc-button {
justify-content: center !important;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://fonts.gstatic.com; script-src 'unsafe-inline' https://unpkg.com; style-src 'unsafe-inline' https://unpkg.com https://fonts.googleapis.com"/>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TMS Archiv login</title>
<link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.css" rel="stylesheet"/>
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/>
</head>
<body>
<div class="mdc-card my-card-content">
<div class="mdc-card__actions mdc-card__actions--full-bleed">
<button class="mdc-button mdc-button--raised mdc-card__action mdc-card__action--button" tabindex="0">
<span class="mdc-button__label">Login</span>
</button>
</div>
</div>
</body>
</html>
Upvotes: 1
Reputation: 1987
This is because of .mdc-card__action--button class has justify-content: space-between;
property and value therefore if you want to center that text you should override this property with following code:
.mdc-card__action--button {
justify-content: center !important;
}
Upvotes: 0