html - 背景颜色和/或文本宽度不起作用

标签 html css

我有一个横跨屏幕的全宽 block 。在这里,文本只需要占 block 的 60%。

我的问题是,当我上传选项 1 时,背景会显示,但文本不是 60% 而是全屏。

如果我上传选项 2,没有背景颜色,但文本占 60%。

我做错了什么?

OPTION 1:

.tekst2 {
	margin-top: 25px;
	margin-bottom:25px;
	text-align: center;
	width: 60%;
	margin-left:auto;
	margin-right:auto;
    font-family: 'Montserrat', sans-serif;
    font-size:16px;
    margin-top:25px;
    float:none;
}

.info
{
	margin-top: 100px;
	width: 100%;
	padding:50px;
	padding-bottom:50px;
	background-color: white;
    text-align:center;
}

OPTION 2:

.info
{
	margin-top: 100px;
	width: 100%;
	padding:50px;
	padding-bottom:50px;
	background-color: white;
    text-align:center;
}


.tekst2 {
	margin-top: 25px;
	margin-bottom:25px;
	text-align: center;
	width: 60%;
	margin-left:auto;
	margin-right:auto;
    font-family: 'Montserrat', sans-serif;
    font-size:16px;
    margin-top:25px;
    float:none;
}
<div class="info">

<div class="tekst1">
<h2 id="tekst1">This is some text</h2>
</div>
<div class="tekst2">
<span id="tekst2">Here is a lot of text and it doesnt scale to 60% when in option 1.</span>
</div>

</div>

最佳答案

HTML 代码

<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

  <style>
  .info
  {
    margin-top: 100px;
    width: 100%;
    height:60%;
    padding:50px;
    padding-bottom:50px;
    background-color:white;
      text-align:center;
  }


  .tekst2 {
    margin-top: 25px;
    margin-bottom:25px;
    text-align: center;
    width: 60%;
    margin-left:auto;
    margin-right:auto;
      font-family: 'Montserrat', sans-serif;
      font-size:16px;
      margin-top:25px;
      float:none;
  }

  </style>
</head>
<body>

关于html - 背景颜色和/或文本宽度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30197165/

相关文章:

html - CSS 不是输入选择器?

html - 如何让SVG元素垂直拉伸(stretch)恰到好处?

c# - "Download all"选项可供用户使用 Html.ActionLink

javascript - 如何在jquery中一次性调用函数

javascript - 如何根据图像大小在 css 中添加背景大小?

html - 网站上奇怪的图像交换错误

javascript - 使用 Javascript 或其他内容更改 HTML 元素内的文本

javascript - 动态更改 React jsx 类,无需 DOM 操作

javascript - ScrollTo 不适用于滚动快照和 100vh 容器

css - 将 Logo 保留在左 Angular 并使用 CSS 居中 ul 元素