【发布时间】:2020-12-14 15:04:11
【问题描述】:
我正在学习前端开发。
我想在容器中间对齐矩阵和右侧列。我该怎么做?
我创建了以下内容(它是在 react 中制作的,但这是原始 html):
我想有一种方法可以使用 HTML 和 CSS 来做到这一点,但我不知道如何去做。我尝试将事物居中,但似乎不起作用。
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="/manifest.json" />
<!--
Notice the use of in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<style type="text/css">
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
"Helvetica Neue", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
</style>
<style type="text/css">
.App {
text-align: center;
width: 500px;
margin: auto;
}
.matrix {
float: left;
display: grid;
/* grid-template-columns: auto auto auto; */
/* background-color: #2196f3; */
padding: 10px;
}
.matrix-component {
border-width: thin;
border-style: solid;
border-color: black;
width: 50px;
height: 50px;
}
.rhs {
display: grid;
padding: 10px;
/* float: right; */
}
.content {
background: grey;
}
</style>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">
<div class="App">
<div class="content">
<div>rows: <input />cols: <input /></div>
<div class="matrix">
<div>
<input class="matrix-component" id="0" value="" /><input
class="matrix-component"
id="1"
value=""
/><input class="matrix-component" id="2" value="" />
</div>
<div>
<input class="matrix-component" id="3" value="" /><input
class="matrix-component"
id="4"
value=""
/><input class="matrix-component" id="5" value="" />
</div>
<div>
<input class="matrix-component" id="6" value="" /><input
class="matrix-component"
id="7"
value=""
/><input class="matrix-component" id="8" value="" />
</div>
</div>
<div class="rhs">
<input class="matrix-component" id="rhs0" value="" /><input
class="matrix-component"
id="rhs1"
value=""
/><input class="matrix-component" id="rhs2" value="" />
</div>
</div>
</div>
</div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<script src="/static/js/bundle.js"></script>
<script src="/static/js/0.chunk.js"></script>
<script src="/static/js/main.chunk.js"></script>
<script src="/main.65e0a7c3d67e68d31704.hot-update.js"></script>
</body>
</html>
非常感谢任何帮助!
【问题讨论】: