鱼C论坛

 找回密码
 立即注册
查看: 3299|回复: 5

[已解决]一个span为何不能设置MARGIN-RIGHT

[复制链接]
发表于 2019-5-27 21:57:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 sxfxtf 于 2019-5-27 22:00 编辑

没办法传附件,代码附上
问题就是84行写的   
我就是要把下面的文字通过margin-right设置边距
<p>坦格利安家族的"风暴降生"</p>
<p>铁王座</p>
<p>安达尔人和先民的</p>
<p>七大王国守护者</p>
<p>大草海上的</p>
<p>不焚者镣铐</p>
                                       
但是span标签,设置了display和宽高以后,但是css中的margin-right为何会在父元素标签范围以外,从而导致视觉上margin-rigth失效的感觉??????

  1. <!DOCTYPE html>
  2. <html>
  3.         <head>
  4.                 <meta charset="UTF-8">
  5.                 <title></title>
  6.                 <style type="text/css">
  7.                         *{
  8.                                 margin: 0px;
  9.                                 padding: 0px;
  10.                         }
  11.                         .page-left{
  12.                                 min-height: 1000px;
  13.                                 width: 70%;
  14.                                 height: 100%;
  15.                                 background-color: #22c3aa;
  16.                                 float: left;
  17.                                 transition: background-color 1s;
  18.                         }
  19.                         .left-dis{
  20.                                 text-align: right;
  21.                                 margin-right:10px;
  22.                                 margin-bottom: 20px;
  23.                                 color: white;
  24.                                 font-size: 50px;
  25.                                 font-weight: 500px;
  26.                                 transition: color 1s;
  27.                         }
  28.                         .left-title{
  29.                                 margin-right: 20px;
  30.                                 height: 200px;
  31.                                 width: 1332px;
  32.                                 font-size: 20px;
  33.                                 display:block
  34.                         }
  35.                         .ul-left{
  36.                                 list-style: none;
  37.                                 height: 100%;
  38.                                 width: 70%;
  39.                         }       
  40.                         .page-right{
  41.                                 min-height: 1000px;
  42.                                 width: 30%;
  43.                                 height: 100%;
  44.                                 background-color: white;
  45.                                 transition: background-color 1s;
  46.                                 float: left;
  47.                         }
  48.                         .right-dis {
  49.                                 font-size: 50px;
  50.                                 margin-bottom: 20px;
  51.                                 font-weight: 500px;
  52.                                 margin-left:5px;
  53.                                 color: #22c3aa;
  54.                                 transition: color 1s;
  55.                         }
  56.                         .right-title{
  57.                                 display: inline-block;
  58.                                 font-size: 20px;
  59.                         }
  60.                         .ul-right{
  61.                                 list-style: none;
  62.                                 height: 100%;
  63.                                 width: 30%;
  64.                         }
  65.                         .page-left:hover{
  66.                                 background-color: white;
  67.                         }
  68.                         .page-left:hover .left-dis{
  69.                                 color: #22c3aa;
  70.                         }
  71.                         .page-left:hover+.page-right{
  72.                                 background-color:#22c3aa
  73.                         }
  74.                         .page-left:hover+.page-right>.right-dis{
  75.                                 color: white
  76.                         }
  77.                        
  78.                 </style>
  79.         </head>
  80.         <body>
  81.                 <div class="page-left">
  82.                         <p class="left-dis">小树苗的</p>
  83.                         <span class="left-dis left-title">
  84.                         <!就是这里的span,设置了display和宽高,但是css中的margin-right为何会在父元素标签范围以外-->
  85.                                 <p>坦格利安家族的"风暴降生"</p>
  86.                                 <p>铁王座</p>
  87.                                 <p>安达尔人和先民的</p>
  88.                                 <p>七大王国守护者</p>
  89.                                 <p>大草海上的</p>
  90.                                 <p>不焚者镣铐</p>
  91.                         </span>
  92.                         <ul class="ul-left">
  93.                                 <li>左</li>
  94.                                 <li>左</li>
  95.                                 <li>左</li>
  96.                                 <li>左</li>
  97.                         </ul>
  98.                 </div>
  99.                 <div class="page-right">
  100.                         <p class="right-dis">成长相册</p>
  101.                         <span class="right-dis right-title">
  102.                                 <p>Daenerys</p>
  103.                                 <p>Lawful hei</p>
  104.                                 <p>Queen</p>
  105.                                 <p>Mother of Dragen</p>
  106.                                 <p>Khaleesi</p>
  107.                                 <p>Breaker</p>
  108.                         </span>
  109.                         <ul class="ul-right">
  110.                                 <li>右边</li>
  111.                                 <li>右边</li>
  112.                                 <li>右边</li>
  113.                                 <li>右边</li>
  114.                                 <li>右边</li>
  115.                         </ul>
  116.                 </div>
  117.         </body>
  118. </html>
复制代码
最佳答案
2019-5-28 18:32:27
本帖最后由 sukiwhip 于 2019-5-28 18:35 编辑
  1. <!DOCTYPE html>
  2. <html>

  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title></title>
  6.     <style type="text/css">
  7.         * {
  8.             margin: 0px;
  9.             padding: 0px;
  10.         }
  11.         
  12.         .page-left {
  13.             min-height: 1000px;
  14.             width: 60%;
  15.             height: 100%;
  16.             background-color: #22c3aa;
  17.             float: left;
  18.             transition: background-color 1s;
  19.         }
  20.         
  21.         .left-dis {
  22.             text-align: right;
  23.             margin-right: 10px;
  24.             margin-bottom: 20px;
  25.             color: white;
  26.             font-size: 50px;
  27.             font-weight: 500px;
  28.             transition: color 1s;
  29.         }
  30.         
  31.         .left-title {
  32.             margin-right: 20px;
  33.             height: 200px;
  34.             width: auto;
  35.             font-size: 20px;
  36.             display: block
  37.         }
  38.         
  39.         .ul-left {
  40.             list-style: none;
  41.             height: 100%;
  42.             width: 70%;
  43.         }
  44.         
  45.         .page-right {
  46.             min-height: 1000px;
  47.             width: 30%;
  48.             height: 100%;
  49.             background-color: white;
  50.             transition: background-color 1s;
  51.             float: left;
  52.         }
  53.         
  54.         .right-dis {
  55.             font-size: 50px;
  56.             margin-bottom: 20px;
  57.             font-weight: 500px;
  58.             margin-left: 5px;
  59.             color: #22c3aa;
  60.             transition: color 1s;
  61.         }
  62.         
  63.         .right-title {
  64.             display: inline-block;
  65.             font-size: 20px;
  66.         }
  67.         
  68.         .ul-right {
  69.             list-style: none;
  70.             height: 100%;
  71.             width: 30%;
  72.         }
  73.         
  74.         .page-left:hover {
  75.             background-color: white;
  76.         }
  77.         
  78.         .page-left:hover .left-dis {
  79.             color: #22c3aa;
  80.         }
  81.         
  82.         .page-left:hover+.page-right {
  83.             background-color: #22c3aa
  84.         }
  85.         
  86.         .page-left:hover+.page-right>.right-dis {
  87.             color: white
  88.         }
  89.     </style>
  90. </head>

  91. <body>
  92.     <div class="page-left">
  93.         <p class="left-dis">小树苗的</p>
  94.         <span class="left-dis left-title">
  95.                         <!--就是这里的span,设置了display和宽高,但是css中的margin-right为何会在父元素标签范围以外-->
  96.                                 <p>坦格利安家族的"风暴降生"</p>
  97.                                 <p>铁王座</p>
  98.                                 <p>安达尔人和先民的</p>
  99.                                 <p>七大王国守护者</p>
  100.                                 <p>大草海上的</p>
  101.                                 <p>不焚者镣铐</p>
  102.                         </span>
  103.         <ul class="ul-left">
  104.             <li>左</li>
  105.             <li>左</li>
  106.             <li>左</li>
  107.             <li>左</li>
  108.         </ul>
  109.     </div>
  110.     <div class="page-right">
  111.         <p class="right-dis">成长相册</p>
  112.         <span class="right-dis right-title">
  113.                                 <p>Daenerys</p>
  114.                                 <p>Lawful hei</p>
  115.                                 <p>Queen</p>
  116.                                 <p>Mother of Dragen</p>
  117.                                 <p>Khaleesi</p>
  118.                                 <p>Breaker</p>
  119.                         </span>
  120.         <ul class="ul-right">
  121.             <li>右边</li>
  122.             <li>右边</li>
  123.             <li>右边</li>
  124.             <li>右边</li>
  125.             <li>右边</li>
  126.         </ul>
  127.     </div>
  128. </body>

  129. </html>
复制代码

是想要这个效果?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-27 22:56:47 | 显示全部楼层
1、页面看着效果挺好的,鱼油准确描述下问题:
Snip20190527_1.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-28 09:49:41 | 显示全部楼层
不二如是 发表于 2019-5-27 22:56
1、页面看着效果挺好的,鱼油准确描述下问题:


不二学长.你好
在小树苗的下面有一段p标签,他们的父标签是span.
span是行内元素,所以我设置了display属性和宽高.想设置右边距(margin-right).
把版面白色和青色的那条分界线和p标签产生距离.
但是似乎无效.不知道什么原因
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-28 18:32:27 | 显示全部楼层    本楼为最佳答案   
本帖最后由 sukiwhip 于 2019-5-28 18:35 编辑
  1. <!DOCTYPE html>
  2. <html>

  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title></title>
  6.     <style type="text/css">
  7.         * {
  8.             margin: 0px;
  9.             padding: 0px;
  10.         }
  11.         
  12.         .page-left {
  13.             min-height: 1000px;
  14.             width: 60%;
  15.             height: 100%;
  16.             background-color: #22c3aa;
  17.             float: left;
  18.             transition: background-color 1s;
  19.         }
  20.         
  21.         .left-dis {
  22.             text-align: right;
  23.             margin-right: 10px;
  24.             margin-bottom: 20px;
  25.             color: white;
  26.             font-size: 50px;
  27.             font-weight: 500px;
  28.             transition: color 1s;
  29.         }
  30.         
  31.         .left-title {
  32.             margin-right: 20px;
  33.             height: 200px;
  34.             width: auto;
  35.             font-size: 20px;
  36.             display: block
  37.         }
  38.         
  39.         .ul-left {
  40.             list-style: none;
  41.             height: 100%;
  42.             width: 70%;
  43.         }
  44.         
  45.         .page-right {
  46.             min-height: 1000px;
  47.             width: 30%;
  48.             height: 100%;
  49.             background-color: white;
  50.             transition: background-color 1s;
  51.             float: left;
  52.         }
  53.         
  54.         .right-dis {
  55.             font-size: 50px;
  56.             margin-bottom: 20px;
  57.             font-weight: 500px;
  58.             margin-left: 5px;
  59.             color: #22c3aa;
  60.             transition: color 1s;
  61.         }
  62.         
  63.         .right-title {
  64.             display: inline-block;
  65.             font-size: 20px;
  66.         }
  67.         
  68.         .ul-right {
  69.             list-style: none;
  70.             height: 100%;
  71.             width: 30%;
  72.         }
  73.         
  74.         .page-left:hover {
  75.             background-color: white;
  76.         }
  77.         
  78.         .page-left:hover .left-dis {
  79.             color: #22c3aa;
  80.         }
  81.         
  82.         .page-left:hover+.page-right {
  83.             background-color: #22c3aa
  84.         }
  85.         
  86.         .page-left:hover+.page-right>.right-dis {
  87.             color: white
  88.         }
  89.     </style>
  90. </head>

  91. <body>
  92.     <div class="page-left">
  93.         <p class="left-dis">小树苗的</p>
  94.         <span class="left-dis left-title">
  95.                         <!--就是这里的span,设置了display和宽高,但是css中的margin-right为何会在父元素标签范围以外-->
  96.                                 <p>坦格利安家族的"风暴降生"</p>
  97.                                 <p>铁王座</p>
  98.                                 <p>安达尔人和先民的</p>
  99.                                 <p>七大王国守护者</p>
  100.                                 <p>大草海上的</p>
  101.                                 <p>不焚者镣铐</p>
  102.                         </span>
  103.         <ul class="ul-left">
  104.             <li>左</li>
  105.             <li>左</li>
  106.             <li>左</li>
  107.             <li>左</li>
  108.         </ul>
  109.     </div>
  110.     <div class="page-right">
  111.         <p class="right-dis">成长相册</p>
  112.         <span class="right-dis right-title">
  113.                                 <p>Daenerys</p>
  114.                                 <p>Lawful hei</p>
  115.                                 <p>Queen</p>
  116.                                 <p>Mother of Dragen</p>
  117.                                 <p>Khaleesi</p>
  118.                                 <p>Breaker</p>
  119.                         </span>
  120.         <ul class="ul-right">
  121.             <li>右边</li>
  122.             <li>右边</li>
  123.             <li>右边</li>
  124.             <li>右边</li>
  125.             <li>右边</li>
  126.         </ul>
  127.     </div>
  128. </body>

  129. </html>
复制代码

是想要这个效果?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-5-28 21:05:10 | 显示全部楼层
sukiwhip 发表于 2019-5-28 18:32
是想要这个效果?

是的,多谢多谢,我看到哪里的问题了.我竟然忘记了auto这个值,蠢哭了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-29 10:33:46 | 显示全部楼层
sxfxtf 发表于 2019-5-28 21:05
是的,多谢多谢,我看到哪里的问题了.我竟然忘记了auto这个值,蠢哭了

另外,如果你的浏览器宽度小于一定的范围,你的第一行会换行,导致左右不对称,当然,很少人会这样缩小浏览器。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-8 07:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表