Solved

Urgent Help with HTML CSS Positioning

Posted on 2016-11-18
9
51 Views
Last Modified: 2016-11-18
Hi all,

I am trying to get

The text and download buttons to be in the centre of this div, height and width.

My code just don't seem to work I have tried everything. any help is highly appreciated, Thanks.

Here is the design

Screen-Shot-2016-11-18-at-13.52.05.png
Here is My code

HTML

<div id="clear"></div>
       
          <div id="downloadsection">
          <div id="downloadtext">
          <h1>Download the app Today!</h1>
          <div class="button3">TRY APP</div>
          <div class="button4">BUY APP</div>
          </div>
          </div>

Open in new window


CSS

/* START DOWNLOAD SECTION */

#downloadsection {
    background-color: #0C2633;
    height: 400px; 
    width: 100%;
}

#downloadsection h1{
    margin: top: 50px;  
    text-align: center;
    margin-bottom: 20px;
    color: #1da6c4; 
    font-size: 35px; 
    text-transform: uppercase;
    
}

#downloadtext {
      
    width: 52%;
    background-color: pink;
    display: block; 
    margin: 0 auto; 
    

}

Open in new window


I really need to get this sorted asap.

Thanks Again.
0
Comment
Question by:Mike Moore
  • 4
  • 4
9 Comments
 
LVL 9

Expert Comment

by:Paweł
ID: 41892852
here you go

http://codepen.io/chooch/pen/vygBJP

<div id="clear"></div>

<div id="downloadsection">
  <div id="downloadtext">
    <h1>Download the app Today!</h1>
    <span class="button">TRY APP</span>
    <span class="button">BUY APP</span>
  </div>
</div>


/* START DOWNLOAD SECTION */

#downloadsection {
    background-color: #0C2633;
    height: 400px;
    width: 100%;
    display: flex;
  flex-direction: column;
  justify-content: center;
}

#downloadsection h1{
    margin: top: 50px;  
    text-align: center;
    margin-bottom: 20px;
    color: #1da6c4;
    font-size: 35px;
    text-transform: uppercase;
   
}

#downloadtext {
  margin:50% auto;
     text-align: center;
    width: 52%;
    background-color: pink;
    display: block;
    margin: 0 auto;
}
   


just made you two link buttons into inline elements that means they'll just render next to each other as long as they have space, then i just centered everything in your containing div. an volia
0
 

Author Comment

by:Mike Moore
ID: 41892857
Hi, what did you change? sorry I'm new to web dev.

Thanks
0
 
LVL 9

Accepted Solution

by:
Paweł earned 500 total points
ID: 41892863
no worries, takes a bit to get a handle on it. i made the outer container the box that contains the pink content one into a flex box and set it's properties


  display: flex;
  flex-direction: column;
  justify-content: center;

actually rather than me give you a second hand explanation, check out the following
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Closing Comment

by:Mike Moore
ID: 41892875
Thanks a bunch.

I am in my 1st month at uni so this really helps.

Regards,
Mike
0
 

Author Comment

by:Mike Moore
ID: 41892884
just one more thing, sorry.

I can't get the text to align inside the buttons also same sort of problem.

any idea?

Screen-Shot-2016-11-18-at-14.22.33.png
Thanks
0
 
LVL 9

Expert Comment

by:Paweł
ID: 41892893
so the buttons are inside span tags now, which are inline elements, what i would do is give them a padding something like

.button{
  background-color:red;
  padding: 2px 10px;
}

that or give them a static width and change the display of the element to inline-block

.button{
  background-color:red;
  width:200px;
  display:inline-block;
  text-align:center;
}

the text-align:center is probably not needed,

take a look at the codepen
0
 
LVL 9

Expert Comment

by:Paweł
ID: 41892901
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41892917
Flex has cross browser limitations. Another option is to use display: table like so
<style type="text/css">
#downloadsection {
  background-color: #0C2633;
  height: 400px; 
  width: 100%;
  display: table;
}
#downloadsection h1 {
  margin: top: 50px;  
  text-align: center;
  margin-bottom: 20px;
  color: #1da6c4; 
  font-size: 35px; 
  text-transform: uppercase;
}
#downloadtext {
  width: 100%;
  text-align: center;
  display: table-cell;
  height: 100%;
  vertical-align: middle;
}
.button {
  border-radius: 5px;
  padding: 5px 25px;
  color: white;
  font-size: 25px;
  margin-left: 15px;
}
.button3 {
  background: #1fb18a;
}
.button4 {
  background: #1ea6c4;
}
</style>

Open in new window

HTML
    <div id="clear"></div>
      <div id="downloadsection">
        <div id="downloadtext">
          <h1>Download the app Today!</h1>
          <a class="button button3">TRY APP</a>
          <a class="button button4">BUY APP</a>
      </div>
    </div>

Open in new window


Working sample here
0
 

Author Comment

by:Mike Moore
ID: 41892923
Thanks I appreciate all your help. I will give it a shot.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
This video teaches users how to migrate an existing Wordpress website to a new domain.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question