【问题标题】:How to handle margin-left correctly?如何正确处理左边距?
【发布时间】:2020-07-02 11:52:26
【问题描述】:

portfolio页面的位置很好但是我认为我没有正确使用margin-left,我认为我必须使用另一个礼貌?

然后,我的第二个问题是我的languages 页面离我的portfolio 页面太远,我想修复为50 px。但我不能这样做,因为我遇到了第一个问题。

感谢您的帮助。

body{
	margin: 0px;
	padding: 0px;
}

header{
	background-color: #B1DBE8;
	height: 98px;
}

.header-block{
	font-size: 11px;
	text-transform: uppercase;
	padding-top: 8px;
	font-weight: 700;
	color: #777;
	line-height: 20px;
}

.page-left{
	display: inline-block;
	margin-left: 430px;
}
<body>
  <header>
  	<div class="header-block">
  		<div class="page-left">Portfolio</div>
  		<div class="page-left">Languages</div>
  	</div>
  </header>
 </body>

【问题讨论】:

  • 我不认为.page-left 类的工作方式与您在图片中显示的一样。

标签: css css-position margin margin-left


【解决方案1】:

你可以使用“flex”它对你有帮助 在不同的屏幕尺寸下有助于安排正确的比例

试试吧。

body{
	margin: 0px;
	padding: 0px;
}

header{
	background-color: #B1DBE8;
	height: 98px;
}

.header-block{
	font-size: 11px;
	text-transform: uppercase;
	padding-top: 8px;
	font-weight: 700;
	color: #777;
	line-height: 20px;
    display: flex;
}

.page-first{
	display: inline-block;
	margin-left: 430px;
}
.page-second{
	margin-left: 50px;
}
<body>
  <header>
  	<div class="header-block">
  		<div class="page-first">Portfolio</div>
  		<div class="page-second">Languages</div>
  	</div>
  </header>
 </body>

示例。 https://css-tricks.com/snippets/css/a-guide-to-flexbox/

【讨论】:

  • 第一:创建新的选择器类时不需要创建flex,第二:这是什么display: inline-second;?
  • 其实显示:inline-second;不需要
  • 不,我的意思是“内联秒”是什么?没听说过这个楼盘?而且我不是投票反对的人!仅供参考
【解决方案2】:

只需将 margin-left: 430px; 添加到 header-block div

【讨论】:

    【解决方案3】:

    您应该为第二个问题的代码创建一个新的selector:

    全屏查看实际margin-left 工作的结果。

    body{
    	margin: 0px;
    	padding: 0px;
    }
    
    header{
    	background-color: #B1DBE8;
    	height: 98px;
    }
    
    .header-block{
    	font-size: 11px;
    	text-transform: uppercase;
    	padding-top: 8px;
    	font-weight: 700;
    	color: #777;
    	line-height: 20px; 
    }
    
    .page-left{
    	display: inline-block;
    	margin-left: 430px;
      border:1px solid black;
    }
    .Languages{
    	display: inline-block;
    margin-left: 30px;
    border:1px solid red;
    }
    <body>
      <header>
      	<div class="header-block">
      		<div class="page-left">Portfolio</div>
      		<div class="Languages">Languages</div>
      	</div>
      </header>
     </body>

    【讨论】:

    • 我很高兴能帮助你@joel,如果你认为值得投票,请投票。
    猜你喜欢
    • 2015-02-25
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    相关资源
    最近更新 更多