2 回答

TA貢獻1851條經驗 獲得超5個贊
我對 CAS 沒有任何想法,但您可以使用以下方式對齊您的表格,看看它是否適合您
將類添加form-container到表單的父 div 和
.form-container{
width: 300px;
margin: 0 auto;
float: none;
}
.form-container{
width: 300px;
margin: 0 auto;
float: none;
}
<!DOCTYPE html>
<html>
<head>
<title>Form Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="form-container">
<h3>Vertical (basic) form</h3>
<form action="/action_page.php">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox" name="remember"> Remember me</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
</body>
</html>

TA貢獻1883條經驗 獲得超3個贊
看起來您使用的 Thymeleaf 模板包括 Bootstrap 4。對嗎?
由于沒有可查看的實時代碼示例,因此很難確切地弄清楚如何產生您想要的結果。
也就是說,我會嘗試將您的元素的直接子.row元素(在登錄片段文件中)放入一個 flex 容器本身,并使用 Bootstrap 4 的 flexbox 實用程序之一將其居中;具體來說,您應該添加d-flex justify-content-center(分別是 CSS 本機display: flex和的 Bootstrap 的別名justify-content: center。
所以:
<main role="main" class="container mt-3 mb-3">
<div class="row">
<div class="col-md d-flex justify-content-center">
<div class="my-content">
MY CONTENT
</div>
</div>
</div>
</main>
在此處查看 Codepen
添加回答
舉報