英文:
How to place two blocks in the center of the page dividing it in half between them?
问题
以下是您要翻译的内容:
I have a central part of the page.
我有一个页面的中央部分。
I want it to be like in the picture. However, I can't set 2 blocks so that they divide the page in half between them.
我希望它像图片中一样。但是,我无法设置两个块,使它们在页面之间均匀分割。
In place of this, the text cuts off the image.
而代之的是,文本截断了图像。
.wrapper {
display: inline-flex;
flex: 1;
}
.text__main {
padding: 10px;
min-width: 10%;
}
.img__central {
height: 800px;
width: auto;
}
img {
width: 100%;
/* 图像宽度 /
height: 100%;
/ 图像高度 /
object-fit: cover;
/ 适应图像 */
}
h1 {
font-size: 56px;
}
span {
font-size: 30px;
}
button {
width: 100%;
font-size: 30px;
border-radius: 20px;
background-color: blue;
}
Умное образование
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Non dolorem, autem reiciendis quibusdam mollitia consequatur similique sapiente quia nisi eos optio voluptatibus rem ut voluptates quaerat ad eaque in labore?
英文:
I have a central part of the page.
I want it to be like in the picture. However, I can't set 2 blocks so that they divide the page in half between them.
In place of this, the text cuts off the image.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.wrapper {
display: inline-flex;
flex: 1;
}
.text__main {
padding: 10px;
min-width: 10%;
}
.img__central {
height: 800px;
width: auto;
}
img {
width: 100%;
/* Ширина изображений */
height: 100%;
/* Высота изображении */
object-fit: cover;
/* Вписываем фотографию в область */
}
h1 {
font-size: 56px;
}
span {
font-size: 30px;
}
button {
width: 100%;
font-size: 30px;
border-radius: 20px;
background-color: blue;
}
<!-- language: lang-html -->
<div>
<div class="wrapper">
<div class="text__main">
<h1>Умное образование</h1>
<span>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Non dolorem, autem reiciendis quibusdam mollitia consequatur similique sapiente quia nisi eos optio voluptatibus rem ut voluptates quaerat ad eaque in labore?
</span>
<button><a href="">НАчать обучение</a></button>
</div>
<div class="img__central ">
<img src="/assets/img/mainslider/02.jpg" alt="">
</div>
</div>
</div>
<!-- end snippet -->
答案1
得分: 1
你可以使用 flex-grow
,它将为具有相同值的两个元素提供相同的空间。flex-grow
有一个快捷方式:flex: <flex-grow> <flex-shrink> <flex-basis>;
。详细信息请参考:https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow
.text__main {
padding: 10px;
min-width: 10%;
flex: 1;
}
.img__central {
height: 800px;
width: auto;
flex: 1;
}
英文:
You can use flex-grow
which will give two elements with the same value the same space. There is shortcut for flex-grow: flex: <flex-grow> <flex-shrink> <flex-basis>;
<br><https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow>
.text__main {
padding: 10px;
min-width: 10%;
flex: 1;
}
.img__central {
height: 800px;
width: auto;
flex: 1;
}
答案2
得分: 1
使用弹性盒子布局(flexbox)。根据您的需要调整边距/填充。
.wrapper {
display: flex;
justify-content: space-between;
}
.text__main {
padding: 10px;
width: 50%;
}
.img__central {
width: 50%;
}
img {
width: 100%;
/* 图片宽度 */
height: 100%;
/* 图片高度 */
object-fit: cover;
/* 将图像适应到容器 */
}
h1 {
font-size: 56px;
}
span {
font-size: 30px;
width: 50;
}
button {
width: 100%;
font-size: 30px;
border-radius: 20px;
background-color: blue;
}
<div>
<div class="wrapper">
<div class="text__main">
<h1>Умное образование</h1>
<span>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Non dolorem, autem reiciendis quibusdam mollitia consequatur similique sapiente quia nisi eos optio voluptatibus rem ut voluptates quaerat ad eaque in labore?
</span>
<button><a href="">НАчать обучение</a></button>
</div>
<div class="img__central">
<img src="/assets/img/mainslider/02.jpg" alt="">
</div>
</div>
</div>
英文:
Use a flexbox. Adjust margins/padding as it fits you.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.wrapper {
display: flex;
justify-content: space-between;
}
.text__main {
padding: 10px;
width: 50%;
}
.img__central {
width: 50%;
}
img {
width: 100%;
/* Ширина изображений */
height: 100%;
/* Высота изображении */
object-fit: cover;
/* Вписываем фотографию в область */
}
h1 {
font-size: 56px;
}
span {
font-size: 30px;
width: 50;
}
button {
width: 100%;
font-size: 30px;
border-radius: 20px;
background-color: blue;
}
<!-- language: lang-html -->
<div>
<div class="wrapper">
<div class="text__main">
<h1>Умное образование</h1>
<span>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Non dolorem, autem reiciendis quibusdam mollitia consequatur similique sapiente quia nisi eos optio voluptatibus rem ut voluptates quaerat ad eaque in labore?
</span>
<button><a href="">НАчать обучение</a></button>
</div>
<div class="img__central ">
<img src="/assets/img/mainslider/02.jpg" alt="">
</div>
</div>
</div>
<!-- end snippet -->
答案3
得分: 1
使用Bootstrap框架。
在下面的示例中,如果您希望实现响应式布局,即如果屏幕宽度小于576px,则列的宽度将为100%,如果屏幕宽度大于576px,则行将包含两列,每列宽度为50%,则可以使用以下代码:
<div class="col-sm-12 col-md-6">
下面是一些CSS样式的代码:
.text__main {
padding: 10px;
min-width: 10%;
}
.img__central {
height: 800px;
width: auto;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
}
h1 {
font-size: 56px;
}
span {
font-size: 30px;
}
button {
width: 100%;
font-size: 30px;
border-radius: 20px;
background-color: blue;
}
以及HTML代码中引用了Bootstrap和展示了HELLO WORLD的内容:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<div class="container-fluid">
<div class="row">
<h2>HELLO WORLD</h2>
<div class="col-sm-6">
<span>
Install Bootstrap’s source Sass and JavaScript files via npm, RubyGems, Composer, or Meteor. Package managed installs don’t include documentation or our full build scripts. You can also use our npm template repo to quickly generate a Bootstrap project via npm.
</span>
</div>
<div class="col-sm-6">
<img/>
</div>
</div>
</div>
英文:
Bootstrap framework is used.
In the below example If you want that responsiveness that if width of screen is below 576px the column width will be of 100% and if screen width is greater the 576px the row will have two columns 50%(1st column) and %50(2nd column) the use :
<br>
div class="col-sm-12 col-md-6"
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.text__main {
padding: 10px;
min-width: 10%;
}
.img__central {
height: 800px;
width: auto;
}
img {
width: 100%;
/* Ширина изображений */
height: 100%;
/* Высота изображении */
object-fit: cover;
/* Вписываем фотографию в область */
}
h1 {
font-size: 56px;
}
span {
font-size: 30px;
}
button {
width: 100%;
font-size: 30px;
border-radius: 20px;
background-color: blue;
}
<!-- language: lang-html -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<div class="container-fluid">
<div class="row">
<h2>HELLO WORLD</h2>
<div class="col-sm-6">
<span>
Install Bootstrap’s source Sass and JavaScript files via npm, RubyGems, Composer, or Meteor. Package managed installs don’t include documentation or our full build scripts. You can also use our npm template repo to quickly generate a Bootstrap project via npm.
</span>
</div>
<div class="col-sm-6">
<img/>
</div>
</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论