如何在一个盒子的右上角放置一个盒子?

问题描述 投票:1回答:1

我应该如何将一个框放置在一个框的右上角,以使它的位置不受媒体查询引起的尺寸变化的影响。另外,如果我们将属性放在类内的CSS中,并将该类用于snap,则它不会检测到CSS中在相应类下提及的属性。这就是为什么在style属性下提及这些属性。请帮助

Click to check the error. Click to check the error

* {
  box-sizing: border-box;
}
h1 {
  margin-bottom: 15px;
  text-align: center;
  font-size:175%;
}

p {
  border: 1px solid black;
  background-color: #808080;
  width: 100%;
  height: 150px;
  margin-right: auto;
  margin-left: auto;
  font-family: Helvetica;
  color: black;
  position: relative;
}

/* Simple Responsive Framework. */
.row {
  width: 100%;
}

/********** Large devices only **********/
@media (min-width: 992px) {
  .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
    float: left;

  }
  .col-lg-1 {
    width: 8.33%;
  }
  .col-lg-2 {
    width: 16.66%;
  }
  .col-lg-3 {
    width: 25%;
  }
  .col-lg-4 {
    width: 33.33%;
    margin: auto;
  }
  .col-lg-5 {
    width: 41.66%;
  }
  .col-lg-6 {
    width: 50%;
  }
  .col-lg-7 {
    width: 58.33%;
  }
  .col-lg-8 {
    width: 66.66%;
  }
  .col-lg-9 {
    width: 74.99%;
  }
  .col-lg-10 {
    width: 83.33%;
  }
  .col-lg-11 {
    width: 91.66%;
  }
  .col-lg-12 {
    width: 100%;
  }
}

/********** Medium devices only **********/
@media (min-width: 768px) and (max-width: 991px) {
  .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
    float: left;

  
  }
  .col-md-1 {
    width: 8.33%;
  }
  .col-md-2 {
    width: 16.66%;
  }
  .col-md-3 {
    width: 25%;
  }
  .col-md-4 {
    width: 33.33%;
  }
  .col-md-5 {
    width: 41.66%;
  }
  .col-md-6 {
    width: 50%;
  }
  .col-md-7 {
    width: 58.33%;
  }
  .col-md-8 {
    width: 66.66%;
  }
  .col-md-9 {
    width: 74.99%;
  }
  .col-md-10 {
    width: 83.33%;
  }
  .col-md-11 {
    width: 91.66%;
  }
  .col-md-12 {
    width: 100%;
    margin: auto;
  }
  /********** Small devices only **********/
@media (max-width: 767px) {
  .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 {
    float: left;
  
  }
  .col-sm-1 {
    width: 8.33%;
  }
  .col-sm-2 {
    width: 16.66%;
  }
  .col-sm-3 {
    width: 25%;
  }
  .col-sm-4 {
    width: 33.33%;
  }
  .col-sm-5 {
    width: 41.66%;
  }
  .col-sm-6 {
    width: 50%;
  }
  .col-sm-7 {
    width: 58.33%;
  }
  .col-sm-8 {
    width: 66.66%;
  }
  .col-sm-9 {
    width: 74.99%;
  }
  .col-sm-10 {
    width: 83.33%;
  }
  .col-sm-11 {
    width: 91.66%;
  }
  .col-sm-12 {
    width: 100%;
    margin: auto;
  }
}
<!DOCTYPE html>
<html>
<head>
	<title style="font-size: 125%">Module 2 Solution</title>
	<link rel="stylesheet" href="module2.css">
</head>
<body>
	<h1>Our menu</h1>
<div class="row">
	<div style="padding: 1rem" class="col-lg-4 col-md-6 col-sm-12 "><p><span style="background-color: pink; position: relative; left: 92%">hello</span></p></div>
	<div style="padding: 1rem" class="col-lg-4 col-md-6 col-sm-12 "><p></p></div>
    <div style="padding: 1rem" class="col-lg-4 col-md-12 col-sm-12"><p></p></div> 
    
</div>

</body>
</html>
html css position media-queries css-position
1个回答
3
投票

您可以使用position: absolutespan

https://developer.mozilla.org/en-US/docs/Web/CSS/position

    position: absolute;
    right: 0;
    top: 0;

* {
  box-sizing: border-box;
}
h1 {
  margin-bottom: 15px;
  text-align: center;
  font-size:175%;
}

p {
  border: 1px solid black;
  background-color: #808080;
  width: 100%;
  height: 150px;
  margin-right: auto;
  margin-left: auto;
  font-family: Helvetica;
  color: black;
  position: relative;
}

/* Simple Responsive Framework. */
.row {
  width: 100%;
}

/* Large devices only */
@media (min-width: 992px) {
  .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
    float: left;

  }
  .col-lg-1 {
    width: 8.33%;
  }
  .col-lg-2 {
    width: 16.66%;
  }
  .col-lg-3 {
    width: 25%;
  }
  .col-lg-4 {
    width: 33.33%;
    margin: auto;
  }
  .col-lg-5 {
    width: 41.66%;
  }
  .col-lg-6 {
    width: 50%;
  }
  .col-lg-7 {
    width: 58.33%;
  }
  .col-lg-8 {
    width: 66.66%;
  }
  .col-lg-9 {
    width: 74.99%;
  }
  .col-lg-10 {
    width: 83.33%;
  }
  .col-lg-11 {
    width: 91.66%;
  }
  .col-lg-12 {
    width: 100%;
  }
}

/* Medium devices only */
@media (min-width: 768px) and (max-width: 991px) {
  .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
    float: left;

  
  }
  .col-md-1 {
    width: 8.33%;
  }
  .col-md-2 {
    width: 16.66%;
  }
  .col-md-3 {
    width: 25%;
  }
  .col-md-4 {
    width: 33.33%;
  }
  .col-md-5 {
    width: 41.66%;
  }
  .col-md-6 {
    width: 50%;
  }
  .col-md-7 {
    width: 58.33%;
  }
  .col-md-8 {
    width: 66.66%;
  }
  .col-md-9 {
    width: 74.99%;
  }
  .col-md-10 {
    width: 83.33%;
  }
  .col-md-11 {
    width: 91.66%;
  }
  .col-md-12 {
    width: 100%;
    margin: auto;
  }
  /* Small devices only */
@media (max-width: 767px) {
  .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 {
    float: left;
  
  }
  .col-sm-1 {
    width: 8.33%;
  }
  .col-sm-2 {
    width: 16.66%;
  }
  .col-sm-3 {
    width: 25%;
  }
  .col-sm-4 {
    width: 33.33%;
  }
  .col-sm-5 {
    width: 41.66%;
  }
  .col-sm-6 {
    width: 50%;
  }
  .col-sm-7 {
    width: 58.33%;
  }
  .col-sm-8 {
    width: 66.66%;
  }
  .col-sm-9 {
    width: 74.99%;
  }
  .col-sm-10 {
    width: 83.33%;
  }
  .col-sm-11 {
    width: 91.66%;
  }
  .col-sm-12 {
    width: 100%;
    margin: auto;
  }
}
<!DOCTYPE html>
<html>
<head>
	<title style="font-size: 125%">Module 2 Solution</title>
	<link rel="stylesheet" href="module2.css">
</head>
<body>
	<h1>Our menu</h1>
<div class="row">
	<div style="padding: 1rem" class="col-lg-4 col-md-6 col-sm-12 "><p><span style="background-color: pink;     position: absolute;
    right: 0;
    top: 0;">hello</span></p></div>
	<div style="padding: 1rem" class="col-lg-4 col-md-6 col-sm-12 "><p></p></div>
    <div style="padding: 1rem" class="col-lg-4 col-md-12 col-sm-12"><p></p></div> 
    
</div>

</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.