0

I'm working on a pomodoro clock and I want to place the controls of the clock to the right of the clock instead of the current position which is down. Right now the html/css code is placing the controls (add time/restart etc) at the bottom of the clock, and I would like to place it to the right. how can I do that? thanks html

<div class="container
  <!-- header title -->
  <div class="title primary-text">
      <h1>Pomodoro Clock</h1>      
  </div>
  <!-- clock / timer goes here -->
  <div class="clock">    
    <div class="timer">
      <h2>Session</h2>
      <h1>23:00</h1>     
    </div>    
  </div>
  <!-- this section for controlling clock -->
  <div class="controls">
    <div class="setTime">
       add time                 
    </div>
    <div class="setTime">
       add time                 
    </div>
    <div class="control">
      play/pause
    </div>
    <div class="control">
      reset
    </div>
  </div>
</div>

css

body {
  background-color: #545454;
}

.title {
  margin: auto;
  text-align: center;
  font-size: 32px;
}

h2 {
  font-size: 50px;
  margin: 0 0 0 0;
}

.timer {
  margin: 0 0 0 0;
  font-size: 44px;
}

.clock {
  margin: auto;
  text-align: center;
  border: solid black 1px;
  width: 500px;
  height: 200px;
}

.controls {
  margin: auto;
  text-align: center;
  border: solid black 1px;
  width: 100px;
}
9
  • 1
    Possible duplicate of How to place div side by side Commented Jul 31, 2017 at 13:47
  • You have a picture of the clock to share? Commented Jul 31, 2017 at 13:47
  • 2
    Your first div isn't closed properly <div class="container
    – j08691
    Commented Jul 31, 2017 at 13:47
  • 1
    @Jason why would anyone suggest such nonsense?
    – malifa
    Commented Jul 31, 2017 at 13:50
  • With either inline-block, float, or flex-box styles. What have you already tried? Commented Jul 31, 2017 at 13:56

3 Answers 3

1

You can use inline-block for both the .clock and .controls in order to align them. However, since you want the .clock to be centered, you will have to add a bit more code. What I did was create a Container .clockContainer in order to then allow for position: absolute on your .controls. This will remove it form the flow and center your .clock while positioning your controls next to it. Then I added some margin to your clock so the 2 elements don't overlap. You can then manipulate the height location of the Controls as you see fit with a top value:

body {
  background-color: #545454;
}

.title {
  margin: auto;
  text-align: center;
  font-size: 32px;
}

h2 {
  font-size: 50px;
  margin: 0 0 0 0;
}

.timer {
  margin: 0 0 0 0;
  font-size: 44px;
}

.clock {
  margin: 0 10px;
  text-align: center;
  border: solid black 1px;
  width: 500px;
  height: 200px;
  display: inline-block;
}

.controls {
  position: absolute;
  text-align: center;
  border: solid black 1px;
  width: 100px;
  display: inline-block;
}

.clockContainer {
  text-align: center;
  position: relative;
}
<div class="container">
  <!-- header title -->
  <div class="title primary-text">
    <h1>Pomodoro Clock</h1>
  </div>
  <!-- clock / timer goes here -->
  <div class="clockContainer">
    <div class="clock">
      <div class="timer">
        <h2>Session</h2>
        <h1>23:00</h1>
      </div>
    </div>
    <!-- this section for controlling clock -->
    <div class="controls">
      <div class="setTime">
        add time
      </div>
      <div class="setTime">
        add time
      </div>
      <div class="control">
        play/pause
      </div>
      <div class="control">
        reset
      </div>
    </div>
  </div>
</div>

0
0

Instead of margin:auto you can use float: left or display: inline-block. check updated CSS below..

.clock {
  /*margin: auto;*/
  float: left;
  text-align: center;
  border: solid black 1px;
  width: 500px;
  height: 200px;
}

.controls {
  /*margin: auto;*/
  float: left;
  text-align: center;
  border: solid black 1px;
  width: 100px;
}
1
  • yes but I would like the clock to be centered and the controls on the right edge of the screen
    – miatech
    Commented Jul 31, 2017 at 13:55
0

I think you need this

to make .clock center you can use display:inline-block; inside .clock and .controls with text-align:center; inside .container

body {
  background-color: #545454;

}

.container{
  text-align:center;	
	}

.title {
  margin: auto;
  text-align: center;
  font-size: 32px;
}

h2 {
  font-size: 50px;
  margin: 0 0 0 0;
}

.timer {
  margin: 0 0 0 0;
  font-size: 44px;
}

.clock {
  margin: auto;
  text-align: center;
  border: solid black 1px;
  width: 400px;
  height: 200px;
  display:inline-block;
}

.controls {
  text-align: center;
  border: solid black 1px;
  width: 100px;
  display:inline-block;
}
<div class="container">
  <!-- header title -->
  <div class="title primary-text">
      <h1>Pomodoro Clock</h1>      
  </div>
  <!-- clock / timer goes here -->
  <div class="clock">    
    <div class="timer">
      <h2>Session</h2>
      <h1>23:00</h1>     
    </div>    
  </div>
  <!-- this section for controlling clock -->
  <div class="controls">
    <div class="setTime">
       add time                 
    </div>
    <div class="setTime">
       add time                 
    </div>
    <div class="control">
      play/pause
    </div>
    <div class="control">
      reset
    </div>
  </div>
</div>

2
  • You can use this customize code inside .controls float:right; margin-right:372px; margin-top:-202px; and remove display:inline-block; from .clock Commented Jul 31, 2017 at 14:27
  • in this example the clock is not center. how could I center the clock and still have the controls to the ritht? codepen.io/pen/?editors=0100
    – miatech
    Commented Jul 31, 2017 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.