[英]How to add a full background-color to a div?
I have a ruby on rails app, and I'd like to put a full width background-color to a div, but without success, everytime I have unwanted left-right and top margin. 我在rails应用程序上有一个ruby,我想为div加上全角的背景色,但是每次我有多余的左右和上边距时都没有成功。
Here is my code: 这是我的代码:
<!DOCTYPE html>
<html lang="en">
<!-- header -->
<body>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<div class="homepage">
<div class="container center">
<div class="texthomepage1">
<br>
<font color="white"><p>Découvrez des startups</p></font>
</div>
<div class="texthomepage2">
<p><font color="white">Faites les découvrir à vos amis & obtenez des récompenses.</font></p></font>
</div>
<br><br><br>
<center>
<!-- REGISTRATION FIELDS -->
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="form-group">
<%= link_to "Rejoindre Gratuitement", new_user_registration_path, class: "btn btn-lg btn-info" %>
<% end %>
<!-- /REGISTRATION FIELDS -->
<br><br><br>
</div>
</div>
</center>
</div>
</div>
Here is my css for the .homepage div: 这是我的.homepage div的CSS:
.homepage {
background-color: #e4685d;
margin: 0
}
But with that code I stil have a margin, so the background color doesn't cover the full background. 但是使用该代码,我仍然留有余量,因此背景色不会覆盖整个背景。
What could be the right way to do this ? 正确的方法是什么?
Make sure your body class doesn't have padding and margins 确保您的健身课没有填充和边距
body{padding:0;margin:0;}
.homepage {
background-color: #e4685d;
margin: 0;
}
Try: 尝试:
body{
margin:0;
}
Also, your <meta />
, <style>
or <link>
tags should be inside a <head>
tag. 另外,您的<meta />
, <style>
或<link>
标记应位于<head>
标记内。 Notice that your <meta />
tag is in your <body>
. 请注意,您的<meta />
标记位于<body>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.