我得到随机的 15px 顶部和底部边距,但我不知道它们来自哪里。
这种情况在 IE 中不会发生,只有 FF 和 Chrome 才会发生。
在以下示例中,每个“Here is content”段落上方和下方的间距是意外的。
#pageContent {
background-color: #fff;
padding: 10px;
}
#contentHead {
height: 33px;
width: 882px;
color: black;
font-size: 14px;
font-weight: bold;
line-height: 34px;
padding-left: 48px;
text-transform: uppercase;
}
#contentBody{
background-color: #d4d3d1;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
-moz-border-radius: 0 0 10px 10px;
border: 1px solid #8b8b8b;
}
#contentNoSidebar{
background-color: #000;
color: white;
}Run Code Online (Sandbox Code Playgroud)
<div id="pageContent">
<div id="contentHead">Sample Page</div>
<div id="contentBody">
<div id="contentNoSidebar">
<p>Here is content</p>
...
<p>Here is content</p>
</div>
</div> …Run Code Online (Sandbox Code Playgroud)我有以下(摘录)html:
<span id="version">Version 1 <small>Last modified 04/August/2012</small><br>unfinished</span>
Run Code Online (Sandbox Code Playgroud)
以及以下(摘录)CSS:
#version {
font-size: xx-large;
color: Black;
text-align: left;
margin-left: 35px;
}
#version small {
font-size: 50%;
}
Run Code Online (Sandbox Code Playgroud)
在 <br> 之后,所有内容都会正确显示,其中文本不会根据边距进行调整。为什么<br>之后没有调整?
我想就一个具体问题寻求帮助。我搜索过类似的问题,但没有找到任何实际的解决方案。我对 CSS 还很陌生。
我正在尝试创建一个名为 的蓝色框buttoncontainer,稍后将在其中包含按钮。现在,我想对其进行格式化,以便浏览器窗口的上边缘和蓝色框的上边缘之间的距离始终为窗口总高度的 42%。如下面的代码所示,我试图通过为框提供 42% 的上边距来实现此目的。
然而,我做不到。当我在 Firefox 或 IE(这是我家庭桌面上的浏览器)中打开 HTML 文件时,当窗口全屏时,距离显然有所不同。如果不是,并且我开始调整它的大小,则该框的位置根本不会响应垂直调整大小。然而,它确实响应水平调整大小,我不希望它这样做。
我想这一定是我犯的一个菜鸟错误,但我就是不知道如何纠正。
重申一下,我希望窗口顶部边缘和蓝色框之间的距离始终为窗口总高度的 42%。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.9.0.js"></script>
<style type="text/css">
body {
background-color: #C94735
}
iframe {
background-color: #FFF;
border: 0;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 63%;
height: 100%;
margin-left: 25%;
margin-right: 12%;
}
.buttoncontainer {
background-color: #00F;
border: 0;
position: fixed; …Run Code Online (Sandbox Code Playgroud)我开始着手创建网站,但有些事情我不明白。例如:
我创建了一个wrapperdiv。里面有三个主要部分:页眉、内容和页脚。我给了wrapperdiv一个固定的大小(1280px x 1024px)并将内容div设置为该大小的2/3。剩下的就是1/3。现在,每当我想在我的子 div 中填充某些内容时,它就会与包装 div 重叠,我不知道如何修复它。
我决定在wrapperdiv 中使用百分比,以便当有人查找网站时缩放等工作流畅。
对此有什么想法吗?我怎样才能做得更好?
谢谢!
代码:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<div id="pagewrapper">
<div id="header">
</div>
<div id="content">
</div>
<div id="footer">
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
CSS:
@font-face {
font-family: "Bickley";
src: url(fonts/Bickley%20Script.ttf);
}
@font-face {
font-family: "American";
src: url(fonts/American%20Classic%20Bold.ttf);
}
body {
font-size: 1em;
font-family: sans-serif;
color: #c6c6c6;
background-image: url("images/bodybackground.jpg");
}
a:link {
text-decoration: none;
color: #c6c6c6;
}
a:visited {
color: #c6c6c6;
}
a:hover …Run Code Online (Sandbox Code Playgroud) 参考以下代码:
body {
height: 500px;
width: 80%;
margin-top: 0;
margin-bottom: 0;
margin-left: auto;
margin-right: auto;
padding: 0;
background-color: lightgray;
}
.header {
width: 80%;
height: 100px;
margin-left: auto;
margin-right: auto;
background-color: yellow;
/* border: solid 1px black; */
}Run Code Online (Sandbox Code Playgroud)
<div class="header">
<ul>
<li><a href="index.html">Dashboard</a></li>
</ul>
</div>Run Code Online (Sandbox Code Playgroud)
当我border: solid 1px black从 .header 中删除时,我会在 div 元素上方获得一些空间。但是当我添加边框属性时,我得到了完美的结果(即删除了空间)。边界属性应该对这个空间产生什么影响?
当我添加像h1with这样的元素时margin: 30px 0;,边距会超出容器!
我以前多次遇到这个问题,我通过使用解决了它 overflow: hidden
我想弄清楚是什么问题以及为什么这个解决方案有效?
在这里找到一个 JSFiddle https://jsfiddle.net/LeoAref/zv6c2c2d/
.container {
background: #ccc;
}
.container.overflow {
overflow: hidden;
}
.secTitle {
margin: 30px 0;
}
code {
color: blue;
}Run Code Online (Sandbox Code Playgroud)
<!-- secTitle margin goes outside the container -->
<div class="container">
<h1 class="secTitle">Container without <code>overflow: hidden</code></h1>
</div>
<!-- works fine here -->
<div class="container overflow">
<h1 class="secTitle">Container with <code>overflow: hidden</code></h1>
</div>Run Code Online (Sandbox Code Playgroud)
我希望在我的 accountOrderButton 上方创建一个边距,以便它可以垂直居中。我正在尝试计算父 div 高度的一半减去子 div 高度的一半。
这应该使按钮居中,但是“margin-top: calc(50%);”行 在我的 CSS 中,返回父 div 的宽度。我如何获得高度?
HTML
<div id="accountOrder">
<div id="accountOrderButton">
Order Now!
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
#accountOrder {
width: 400px;
float: left;
height:100%;
text-align: center;
}
#accountOrderButton {
width: 100px;
height: 20px;
margin: 0 auto;
margin-top: calc(50%); <---- returns width instead of height
padding: 20px;
background-color: <?php echo $data['secondary_color']; ?>;
border-radius: 10px;
}
Run Code Online (Sandbox Code Playgroud) 我有一个高度由封装的 div 决定的 div。问题是,当我在顶部添加一些额外的边距时,encolsing div 会正确调整大小。当我在底部添加边距时,似乎只有封闭的 div 框模型受到影响,而封闭的 div 则不受影响。
HTML
<div style="height:100px;background-color:#adadbb">
IRRELEVANT THINGS HERE
</div>
<div class="dynamicDiv">
<span> title</span>
<div class="card">
Content here
</div>
</div>
<div style="height:100px;background-color:#adadbb">
IRRELEVANT THINGS HERE VOL 2
</div>
Run Code Online (Sandbox Code Playgroud)
CSS
.dynamicDiv{
background-color:yellow;
}
.card{
height:15vh; //an example of the height for this card. could be anything.
margin-top:10px;
margin-bottom:10px;
}
Run Code Online (Sandbox Code Playgroud)
看起来这与<span> title</span>元素有关,好像我在底部添加一个元素,就像我期望的那样工作(除非跨度为空,在这种情况下,事情呈现为好像跨度不存在一样)。
我不太明白为什么会发生这种情况,所以如果它与盒子模型有明显的关系,请告诉我。非常感谢。
在这里小提琴:
https://jsfiddle.net/d88yr4yw/
PS:我试图实现的是有一个始终与封闭的 div 高度一样高的 div + 顶部和底部边距 + 那里可能存在的任何其他元素。如果不是不可能解决这个问题,我宁愿我不必硬编码任何高度。
我想用styles.css更改h4元素的matgins
在 HTML 文件中,h4 嵌套如下:
main div h4 {
margin: 20px, 0, 0, 0;
/* want to change top margin */
}Run Code Online (Sandbox Code Playgroud)
<main role="main" class="col-12 col-md-9 col-xl-8 py-md-3 pl-md-5">
<div style="padding-top: 1.0rem;">
<ul>...</ul>
<h4 id='sec_summary'>Summary</h4>
</div>
</main>Run Code Online (Sandbox Code Playgroud)
在styles.css 中定义的其他样式工作正常。但是当我试图以上面显示的方式设置 h4 边距时,我尝试了不同的数字和单位,h4 的边距根本没有改变。为什么代码不起作用?
我正在尝试创建一个电子邮件签名,当在移动设备上时,文本顶部与照片对齐。在桌面版本上,我的上边距为 32px,媒体查询为 0px。任何线索为什么我的媒体查询不起作用?
@media only screen and (max-width: 500px) {
.mobile {
visibility: hidden;
display: none;
}
.mtext {
margin-top:0px; !important
padding:0px; !important
}
}Run Code Online (Sandbox Code Playgroud)
<table width="100%" border="0" style="font-family:Arial, Helvetica,sans-serif;font-size:12px; margin-left:10px; margin-right:10px;">
<tr>
<td width="100" valign="top" align="left">
<img width="100px" src="https://www.pkallsc.org/wp-content/uploads/2018/04/Headshot-Jeffrey-Ashley-square-e1522622432938.jpg" style="float:left;" alt="John Smith" />
</td>
<td width="1249" valign="top" style="text-align:left; margin-left:5px; font-family:Arial, Helvetica, sans-serif; font-size:16px;" align="left">
<p class="mtext" style="margin-left:10px; margin-top:32px; font-family:Arial, Helvetica, sans-serif; font-size:14px; text-align:left;"> <strong>John Smith</strong>
<br />Chief Executive Officer<br /> 123 Central Suite, Suite 510 | Alpharetta, Georgia 30022<br /> T …Run Code Online (Sandbox Code Playgroud)