如何将两个块放在页面中间,将页面分成两半?

huangapple go评论68阅读模式
英文:

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 -->

&lt;div&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
    &lt;div class=&quot;text__main&quot;&gt;
      &lt;h1&gt;Умное образование&lt;/h1&gt;
      &lt;span&gt;
                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?
            &lt;/span&gt;
      &lt;button&gt;&lt;a href=&quot;&quot;&gt;НАчать обучение&lt;/a&gt;&lt;/button&gt;
    &lt;/div&gt;
    &lt;div class=&quot;img__central &quot;&gt;
      &lt;img src=&quot;/assets/img/mainslider/02.jpg&quot; alt=&quot;&quot;&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- 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: &lt;flex-grow&gt; &lt;flex-shrink&gt; &lt;flex-basis&gt;; <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 -->

&lt;div&gt;
  &lt;div class=&quot;wrapper&quot;&gt;
    &lt;div class=&quot;text__main&quot;&gt;
      &lt;h1&gt;Умное образование&lt;/h1&gt;
      &lt;span&gt;
                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?
            &lt;/span&gt;
      &lt;button&gt;&lt;a href=&quot;&quot;&gt;НАчать обучение&lt;/a&gt;&lt;/button&gt;
    &lt;/div&gt;
    &lt;div class=&quot;img__central &quot;&gt;
      &lt;img src=&quot;/assets/img/mainslider/02.jpg&quot; alt=&quot;&quot;&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- 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 -->

&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;/&gt;

&lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;

&lt;div class=&quot;container-fluid&quot;&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;h2&gt;HELLO WORLD&lt;/h2&gt;
    &lt;div class=&quot;col-sm-6&quot;&gt;
      &lt;span&gt;
        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.
      &lt;/span&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col-sm-6&quot;&gt;
      &lt;img/&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月4日 06:00:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75632233.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定