Solved

Urgent Help with HTML CSS Positioning

Posted on 2016-11-18
9
20 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 8

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 8

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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 8

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 8

Expert Comment

by:Paweł
ID: 41892901
0
 
LVL 51

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now