无法获得右侧的输入字段以向上移动。此外,需要上一个上午/下午按钮向右移动(蓝色框下方)

时间:2017-05-10 03:21:27

标签: html css

我试过漂浮"部分"在左侧,右侧是.defaultCalc和userInputs,但它变得一团糟。通过使用text-align left和text-align right,我能够让它们按照我需要的方式对齐。我不确定它是否是最好的做法,但它现在仍在运作。

我的问题是,我无法让侧栏向上移动,以便与问题保持一致。此外,底部的AM / PM按钮应位于蓝色框下方(就像上面的AM / PM按钮一样)。这适用于大于768px的屏幕尺寸的媒体查询部分。有任何想法吗?提前谢谢。

/*Base style layouts*/

header,
body {
  font-family: 'Lato', sans-serif;
}

body {
  background: #edf0f1;
  font-family: 'Roboto', sans-serif;
  text-align: center;
}

header {
  width: 100%;
  height: 70px;
  border-bottom-left-radius: 46px;
  border-bottom-right-radius: 46px;
  background-color: #15D1BC;
  box-shadow: 0px 2px 4px rgba(44, 62, 80, 0.15);
  color: #fff;
  text-align: center;
}

header h3 {
  margin: 0;
  padding-top: 20px;
  font-size: 1.25em;
  font-weight: 400;
}

h4 {
  font-weight: 100;
  color: #95989A;
  text-align: center;
}

.sections {
  margin: 30px 0;
}


/*Gray areas that display javascript calculations*/

.defaultCalc {
  border: 1px none;
  width: 133px;
  height: 29px;
  background-color: #DBDBDB;
  border-radius: 12px;
  display: inline-block;
}


/*Sections that require the user to input a number*/

.userInput::placeholder {
  font-weight: 100;
  font-style: italic;
  color: rgba(149, 152, 154, 0.4);
  text-align: center;
}

.userInput {
  border: 1px solid #D3D8DB;
  width: 133px;
  height: 29px;
  border-radius: 12px;
}

.sections {
  margin: 30px 0;
}


/*Buttons*/

.amButton,
.pmButton {
  border: 1px;
  width: 45px;
  height: 30px;
  background-color: #fff;
  color: #95989A;
  border-radius: 12px;
  font-weight: 100;
}

.buttons {
  margin: 25px 0;
}

.calcButton {
  border: 1px;
  width: 217px;
  height: 36px;
  background-color: #15D1BC;
  color: #FFF;
  border-radius: 18px;
  font-weight: 100;
  font-size: 1.1em;
}

.clockOutTime {
  border: 1px none;
  width: 133px;
  height: 29px;
  background-color: #60B6FF;
  color: #fff;
  border-radius: 12px;
  text-align: center;
}

.clockOutAMButton,
.clockOutPMButton {
  border: 1px;
  width: 45px;
  height: 30px;
  background-color: #fff;
  color: #95989A;
  border-radius: 12px;
  font-weight: 300;
  text-align: center;
  display: inline-block;
  line-height: 30px;
}

button:focus {
  outline: 0;
}

input:focus {
  border-color: #15D1BC;
  outline: none;
}

.pmButton:focus {
  background-color: #15D1BC;
  color: #FFF;
}

.amButton:focus {
  background-color: #15D1BC;
  color: #FFF;
}

.calcButton:active {
  font-size: 1.075em;
}


/*Media Queries*/

@media (min-width: 900px) {
  header {
    width: 80%;
    margin: 0 auto;
  }
  .sections {
    text-align: left;
  }
  body {
    text-align: right;
  }
  .wrapper {
    width: 500px;
    margin: 0 auto;
  }
  .calculate {
    text-align: center;
  }
  .buttons {
    padding-right: 20px;
  }
}
<html>

<head>
  <meta charset="utf-8" />
  <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,300i,400,400i,500,700" rel="stylesheet">
  <link rel="stylesheet" href="css/normalize.css" />
  <link rel="stylesheet" href="css/main.css" />

  <title>40 Hour Workweek Calculator</title>

</head>


<body>

  <header>
    <h3>40-Hour Workweek Calculator</h3>
  </header>

  <div class="wrapper">


    <h4 class="sections">Total hours needed to work this week:</h4>
    <input type="text" class="userInput" placeholder="ex: 40" />

    <h4 class="sections">On Friday morning, how many hours<br />(in whole numbers) do you currently have?</h4>
    <input type="text" class="userInput" placeholder="ex: 33" />

    <h4 class="sections">Enter remaining decimals:</h4>
    <input type="text" class="userInput" placeholder="ex: .57" />

    <h4 class="sections">Converted to time format:</h4>
    <div class="defaultCalc"></div>

    <h4 class="sections">Remaining hours to work:</h4>
    <div class="defaultCalc"></div>

    <h4 class="sections">Enter time you clocked in on Friday:</h4>
    <input type="text" class="userInput" placeholder="ex: 7:22" /><br />

    <div class="buttons">
      <button class="amButton">AM</button>
      <button class="pmButton">PM</button>
    </div>

    <h4 class="sections">Enter today's lunch break in minutes:</h4>
    <input type="text" class="userInput" placeholder="ex: 30" />

    <div class="sections calculate">
      <button class="calcButton">Calculate my hours</button>
    </div>

    <h4 class="sections">Time to clock out on Friday:</h4>
    <div class="defaultCalc clockOutTime"></div>

    <div class="sections">
      <div class="clockOutAMButton">AM</div>
      <div class="clockOutPMButton">PM</div>
    </div>

  </div>

</body>

This is the original design I'm going for

2 个答案:

答案 0 :(得分:0)

你的/*Media Queries*/似乎很奇怪,我更新了几个地方,确保你的常规CSS位于你的样式表的顶部,然后你去查询小屏幕尺寸,并覆盖你需要的CSS。

如果这与您正在寻找的内容相近,请告诉我。

&#13;
&#13;
/*Base style layouts*/

header,
body {
  font-family: 'Lato', sans-serif;
}

body {
  background: #edf0f1;
  font-family: 'Roboto', sans-serif;
  text-align: right;
}

header {
  width: 100%;
  height: 70px;
  border-bottom-left-radius: 46px;
  border-bottom-right-radius: 46px;
  background-color: #15D1BC;
  box-shadow: 0px 2px 4px rgba(44, 62, 80, 0.15);
  color: #fff;
  text-align: center;
}

header h3 {
  margin: 0;
  padding-top: 20px;
  font-size: 1.25em;
  font-weight: 400;
}

h4 {
  font-weight: 100;
  color: #95989A;
  text-align: center;
}

.sections {
  margin: 30px 0;
  display: inline-block;
}


/*Gray areas that display javascript calculations*/

.defaultCalc {
  border: 1px none;
  width: 133px;
  height: 29px;
  background-color: #DBDBDB;
  border-radius: 12px;
  display: inline-block;
}


/*Sections that require the user to input a number*/

.userInput::placeholder {
  font-weight: 100;
  font-style: italic;
  color: rgba(149, 152, 154, 0.4);
  text-align: center;
}

.userInput {
  border: 1px solid #D3D8DB;
  width: 133px;
  height: 29px;
  border-radius: 12px;
}


/*Buttons*/

.amButton,
.pmButton {
  border: 1px;
  width: 45px;
  height: 30px;
  background-color: #fff;
  color: #95989A;
  border-radius: 12px;
  font-weight: 100;
}

.buttons {
  margin: -15px 0 25px 0;
}

.calcButton {
  border: 1px;
  width: 217px;
  height: 36px;
  background-color: #15D1BC;
  color: #FFF;
  border-radius: 18px;
  font-weight: 100;
  font-size: 1.1em;
}

.clockOutTime {
  border: 1px none;
  width: 133px;
  height: 29px;
  background-color: #60B6FF;
  color: #fff;
  border-radius: 12px;
  text-align: center;
}

.clockOutAMButton,
.clockOutPMButton {
  border: 1px;
  width: 45px;
  height: 30px;
  background-color: #fff;
  color: #95989A;
  border-radius: 12px;
  font-weight: 300;
  text-align: center;
  display: inline-block;
  line-height: 30px;
}

button:focus {
  outline: 0;
}

input:focus {
  border-color: #15D1BC;
  outline: none;
}

.pmButton:focus {
  background-color: #15D1BC;
  color: #FFF;
}

.amButton:focus {
  background-color: #15D1BC;
  color: #FFF;
}

.calcButton:active {
  font-size: 1.075em;
}

.wrapper {
  width: 500px;
  margin: 0 auto;
}


/*Media Queries*/

@media (max-width: 900px) {
  header {
    width: 80%;
    margin: 0 auto;
  }
  .sections {
    text-align: left;
    display: inline-block;
    width: 100%;
    margin-left: 10%;
  }
  .defaultCalc {
      margin-left: 10%;
    display: block;
    float: left;
  }
  .userInput {
    margin-left: 10%;
  	display: block;
    float: left;
  }
  .wrapper {
    width: 100%;
    margin: 0 auto;
  }
  .calculate {
    text-align: left;
  }
  .buttons {
  	margin: 0 0 0 15px;
    float: left;
		display: block;
  }
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />


<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,300i,400,400i,500,700" rel="stylesheet">
<link rel="stylesheet" href="css/normalize.css" />
<link rel="stylesheet" href="css/main.css" />

<title>40 Hour Workweek Calculator</title>


<body>

  <header>
    <h3>40-Hour Workweek Calculator</h3>
  </header>

  <div class="wrapper">


    <h4 class="sections">Total hours needed to work this week:</h4>
    <input type="text" class="userInput" placeholder="ex: 40" />

    <h4 class="sections">On Friday morning, how many hours<br />(in whole numbers) do you currently have?</h4>
    <input type="text" class="userInput" placeholder="ex: 33" />

    <h4 class="sections">Enter remaining decimals:</h4>
    <input type="text" class="userInput" placeholder="ex: .57" />

    <h4 class="sections">Converted to time format:</h4>
    <div class="defaultCalc"></div>

    <h4 class="sections">Remaining hours to work:</h4>
    <div class="defaultCalc"></div>

    <h4 class="sections">Enter time you clocked in on Friday:</h4>
    <input type="text" class="userInput" placeholder="ex: 7:22" />
    <br />

    <div class="buttons">
      <button class="amButton">AM</button>
      <button class="pmButton">PM</button>
    </div>

    <h4 class="sections">Enter today's lunch break in minutes:</h4>
    <input type="text" class="userInput" placeholder="ex: 30" />

    <div class="sections calculate">
      <button class="calcButton">Calculate my hours</button>
    </div>

    <br />
    <h4 class="sections">Time to clock out on Friday:</h4>
    <div class="defaultCalc clockOutTime"></div>

    <div class="sections">
      <div class="clockOutAMButton">AM</div>
      <div class="clockOutPMButton">PM</div>
    </div>

  </div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

感谢所有插话的人。我终于能够弄清楚如何让输入部分显示在每个问题的右侧。我最后用a封闭了每个部分,然后将每个div中的显示属性更改为内联块,这样它们就会彼此相邻。然后我将问题文本对齐到左边,并添加填充权限,以便输入字段移动到右边75px。如果有人有兴趣,这是我目前的代码。

<!doctype html>
<html>

<head>
  <meta charset="utf-8" />
  <link href="https://fonts.googleapis.com/css?family=Hind:300,400" rel="stylesheet">
  <link rel="stylesheet" href="css/normalize.css" />
  <link rel="stylesheet" href="css/main.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>40 Hour Workweek Calculator</title>

</head>


<body>

  <header>
    <h3>40-Hour Workweek Calculator</h3>
  </header>

  <div class="wrapper">

    <div>
      <h4 class="sections totalHours">How many hours do you plan on working this week?</h4>
      <input type="text" class="userInput" id="hoursWeek" placeholder="ex: 40" />
    </div>

    <div>
      <h4 class="sections fridayHours">On Friday morning, how many hours<br />(in whole numbers) do you currently have?</h4>
      <input type="text" class="userInput" id="fridayMorning" placeholder="ex: 33" />
    </div>

    <div>
      <h4 class="sections remDecimal">Enter remaining decimals:</h4>
      <input type="text" class="userInput" id="remainingDecimals" placeholder="ex: .57" />
    </div>

    <div>
      <h4 class="sections convertedTime">Converted to time format:</h4>
      <div class="defaultCalc" id="convertToTime"></div>
    </div>

    <div>
      <h4 class="sections remainHours">Remaining hours to work:</h4>
      <div class="defaultCalc" id="remainingHours"></div>
    </div>

    <div>
      <h4 class="sections clockFriday">Enter time you clocked in on Friday:</h4>
      <input type="text" class="userInput" id="enterClockIn" placeholder="ex: 7:22" /><br />
    </div>

    <div class="buttons">
      <button class="amButton">AM</button>
      <button class="pmButton">PM</button>
    </div>

    <div>
      <h4 class="sections lunch">Enter today's lunch break in minutes:</h4>
      <input type="text" class="userInput" id="enterLunch" placeholder="ex: 30" />
    </div>

    <div class="sections calculate">
      <button class="calcButton" id="clickCalc">Calculate my hours</button>
    </div>

    <div>
      <h4 class="sections outFriday">Time to clock out on Friday:</h4>
      <div class="defaultCalc clockOutTime" id="clockOutToday"></div>
    </div>

    <div class="lastButtons">
      <div class="clockOutAMButton">AM</div>
      <div class="clockOutPMButton">PM</div>
    </div>

  </div>

  <script src="js/main.js"></script>
</body>

</html>



/*Base style layouts*/

header, body {
  font-family: 'Hind', sans-serif;
}

body {
  background: #edf0f1;
  font-family: 'Hind', sans-serif;
  text-align: center;
}

header {
  width: 100%;
  height: 70px;
  border-bottom-left-radius: 46px;
  border-bottom-right-radius: 46px;
  background-image: linear-gradient(120deg, #96deda 0%, #50c9c3 40%);
  box-shadow: 0px 2px 4px rgba(44, 62, 80, 0.15);
  color: #fff;
  text-align: center;
}

header h3 {
  margin: 0;
  padding-top: 20px;
  font-size: 1.4em;
  font-weight: 300;
}

h4 {
  font-weight: 300;
  color: #000;
  text-align: center;
}

.sections {
  margin: 30px 0;
}


/*Gray areas that display javascript calculations*/

.defaultCalc {
  border: 1px solid #C3C8CB;
  width: 133px;
  height: 29px;
  background-color: #DBDBDB;
  border-radius: 12px;
  display: inline-block;
  line-height: 29px;
}


/*Sections that require the user to input a number*/

.userInput::placeholder {
  font-weight: 300;
  font-style: italic;
  color: rgba(149, 152, 154, 0.4);
  text-align: center;
  padding-top: 7px;
}

.userInput {
  border: 1px solid #C3C8CB;
  width: 133px;
  height: 29px;
  border-radius: 12px;
  text-align: center;
  color: #000;
  font-weight: 300;
  font-family: 'Hind', sans-serif;
  line-height: 14.5px;
  vertical-align: middle;
}

.sections {
  margin: 30px 0;
}


/*Buttons*/

.amButton, .pmButton {
  border: 1px;
  width: 45px;
  height: 29px;
  background-color: #fff;
  color: #95989A;
  border-radius: 12px;
  font-family: 'Hind', sans-serif;
  line-height: 29px;
  font-weight: 300;
  text-align: center;
}

.buttons {
  margin: 25px 0;
}

.calcButton {
  border: 1px;
  width: 250px;
  height: 36px;
  background-color: #50c9c3;
  color: #FFF;
  border-radius: 12px;
  font-weight: 100;
  font-size: 1.1em;
  text-align: center;
}

.clockOutTime {
  border: 1px none;
  width: 133px;
  height: 29px;
  background-color: #60B6FF;
  color: #fff;
  border-radius: 12px;
  text-align: center;
}

.clockOutAMButton, .clockOutPMButton {
  width: 45px;
  height: 29px;
  background-color: #fff;
  color: #95989A;
  border-radius: 12px;
  text-align: center;
  display: inline-block;
  line-height: 30px;
  margin-top: 20px;
  margin-bottom: 100px;
  font-family: 'Hind', sans-serif;
  font-weight: 300;
}

input:focus {
  outline: 0;
}

button:focus {
  outline: 0;
}

.calcButton:active {
  font-size: 1.075em;
}

@media (min-width: 768px) {
  header {
    margin: 0 auto;
    width: 80%;
  }
  .wrapper {
    margin: 0 auto;
    width: 520px;
  }
  .totalHours {
    display: inline-block;
    padding-right: 75px;
    text-align: left;
    width: 300px;
  }
  .fridayHours {
    display: inline-block;
    padding-right: 75px;
    text-align: left;
    width: 300px;
  }
  .remDecimal {
    display: inline-block;
    padding-right: 75px;
    text-align: right;
    width: 300px;
  }
  .convertedTime {
    display: inline-block;
    padding-right: 75px;
    text-align: right;
    width: 300px;
  }
  .remainHours {
    display: inline-block;
    padding-right: 75px;
    text-align: right;
    width: 300px;
  }
  .clockFriday {
    display: inline-block;
    padding-right: 75px;
    text-align: right;
    width: 300px;
  }
  .buttons {
    text-align: center;
    padding-left: 380px;
    margin-top: 0px;
  }

  .amButton, .pmButton {
    text-align: center;
  }

  .lunch {
    display: inline-block;
    padding-right: 75px;
    text-align: right;
    width: 300px;
  }
  .outFriday {
    display: inline-block;
    padding-right: 50px;
    text-align: left;
  }
  .lastButtons {
    text-align: center;
    padding-left: 380px;
  }
  .outFriday {
    padding-right: 75px;
    text-align: right;
    width: 300px;
  }
  .clockOutAMButton, .clockOutPMButton {
    margin-top: 0px;
    margin-bottom: 0px;
  }
  .sections, .clockOutTime, .defaultCalc {
    vertical-align: middle;
  }
  .calcButton {
    width: 520px;
  }

}