Как сделать фон подгонки текста в 2 колонки - PullRequest
1 голос
/ 26 марта 2020

Этот пример ниже создает серый фон, который заполняет всю ширину страницы, но я хочу, чтобы этот фон покрывал только текст и ничего больше. Как я могу это сделать? Код взят с этой страницы: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_two_columns

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

/* Create two equal columns that floats next to each other */
.column {
  float: left;
  width: 50%;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}
</style>
</head>
<body>

<h2>Two Equal Columns</h2>

<div class="row">
  <div class="column" style="background-color:#aaa;">
    <h2>Column 1</h2>
  </div>
  <div class="column" style="background-color:#bbb;">
    <h2>Column 2</h2>
  </div>
</div>

</body>
</html>

Вот как это выглядит сейчас

Ответы [ 2 ]

1 голос
/ 26 марта 2020

После вашего кода, теперь, может быть, это то, что вы хотите:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

/* Create two equal columns that floats next to each other */
.column {
  float: left;
  width: 50%;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}
</style>
</head>
<body>

<h2>Two Equal Columns</h2>

<div class="row">
  <div class="column" >
    <h2 style="background-color:#aaa;display:inline-block;">Column 1</h2>
  </div>
  <div class="column">
    <h2 style="background-color:#bbb;display:inline-block;">Column 2</h2>
  </div>
</div>

</body>
</html>

Теперь это: enter image description here

1 голос
/ 26 марта 2020

Надеюсь, ваш запрос разрешен.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

/* Create two equal columns that floats next to each other */
.column {
  float: left;
  width: 50%;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}
</style>
</head>
<body>

<h2>Two Equal Columns</h2>

<div class="row">
  <div class="column" >
    <span style="background-color:#aaa;">Column 1</span>
  </div>
  <div class="column">
    <span style="background-color:#bbb;">Column 2</span>
  </div>
</div>

</body>
</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...