Solved

Urgent Help with HTML CSS Positioning

Posted on 2016-11-18
9
82 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 10

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 10

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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

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 10

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 10

Expert Comment

by:Paweł
ID: 41892901
0
 
LVL 57

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

688 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