Positioning and aligning text in CSS/HTML - html

I am new to HTML and CSS and am having trouble positioning and aligning simple text. I am trying to put the text on the right half of the page and have the text be lined up vertically along the first letter of every line. Right now, the header is all the way on the right side of the page, half cut off. The rest of the the rest of the text is not stacked up on top of one another. Rather, there is one block of text on the left, with the other two stacked on top of each other on the right. I have been stuck on this for hours and have read every article on positioning and alignment, but I can't seem to get it. Thanks for the help!
<div class="aboutme"><h3 id="hello">Header</h3></div>
<div class="aboutme"><p id="school">text</p>
</div>
<div class="aboutme"><p id="personal">
text</p>
</div>
<div class="aboutme"><p id="thanks">
text</p>
</div>
.aboutme > *{
font-family: Avenir Next;
display: inline-block;
text-align:left;
float:left;
margin: 0.5em 0.5em 0.5em 0.5em;
position:relative;
left:4em;
}
#hello{
font-size: 3em;
color: #282828;
right: 3.47em;
font-weight: lighter;
position:relative;
text-align: left;
float: right;
margin: 1em 1em 0em 1em;
}
#school {
width: 30em;
clear:right;
}
#personal {
width: 30em;
clear:right;
}
#thanks {
width: 30em;
clear:right;
}

You need to add margin-left: 50% to the about me class and delete the other positioning you have added.
.aboutme > *{
font-family: Avenir Next;
display: block;
margin-left: 50%
}
#hello{
font-size: 3em;
color: #282828;
font-weight: lighter;
}
#school {
width: 30em;
}
#personal {
width: 30em;
}
#thanks {
width: 30em;
}
<div class="aboutme"><h3 id="hello">Header</h3></div>
<div class="aboutme"><p id="school">text</p>
</div>
<div class="aboutme"><p id="personal">
text</p>
</div>
<div class="aboutme"><p id="thanks">
text</p>
</div>
Link to JSFiddle: https://jsfiddle.net/dLy932Lh/
EDIT: Adding a div to the left side
#leftHalf {
display: inline-block;
width: 50%;
height: 200px;
padding: 0;
margin: 0;
}
#rightHalf {
display: inline-block;
width: calc(50% - 10px);
height: auto;
padding: 0;
margin: 0;
background-color: #FFF;
}
.aboutme > *{
font-family: Avenir Next;
display: block;
}
#hello{
font-size: 3em;
color: #282828;
font-weight: lighter;
}
#school {
width: 30em;
}
#personal {
width: 30em;
}
#thanks {
width: 30em;
}
<div id="container">
<div id="leftHalf">
</div>
<div id="rightHalf">
<div class="aboutme">
<h3 id="hello">Header</h3>
</div>
<div class="aboutme"><p id="school">text</p>
</div>
<div class="aboutme">
<p id="personal">text</p>
</div>
<div class="aboutme">
<p id="thanks">text</p>
</div>
</div>
</div>
It is important to have the display set to inline-block for the left and right divs so that they can both be on the same line (hence the inline) and they can have heights and widths (hence the block).
Put any content you want on the left side of the page in the left div and make sure that it's width is not more than 50%.
I hope this solution works for you!

Related

How to set an image that will exceed a div top and bottom in css?

I have tried to make an image exceed bottom and top of a div. but i can make it in bottom portion how i will do it for top?
Here is the Online fiddle.
.about {
background-image: linear-gradient(100deg, #483dec, #4074eb);
}
.about img {
width: 100%;
margin-bottom: -100px;
}
.about .desc-section {
margin: auto 0;
}
.about h2 {
font-size: 24px;
color: #ffffff;
}
.about p {
font-size: 16px;
line-height: 2;
color: #ffffff;
}
<section class="about">
<div class="container">
<div class="row">
<div class="col-6">
<img src="https://images.unsplash.com/photo-1558981001-1995369a39cd?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80" alt="">
</div>
<div class="col-6 desc-section">
<h2>This is heading</h2>
<p>Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is.</p>
</div>
</div>
</div>
</section>
You can add position: relative to the .img selector and specify a bottom: 30px or whatever value you want to move it by. I used 30px on top and bottom in this updated fiddle. I hope it helps
.about {
background-image: linear-gradient(100deg, #483dec, #4074eb);
margin-top: 30px;
}
.about img {
width: 100%;
margin-bottom: -100px;
position: relative;
bottom: 30px;
}
.about .desc-section {
margin: auto 0;
}
.about h2 {
font-size: 24px;
color: #ffffff;
}
.about p {
font-size: 16px;
line-height: 2;
color: #ffffff;
}
/* add margin top for about section */
.about {
background-image: linear-gradient(100deg, #483dec, #4074eb);
margin-top: 100px;
}
/* change margin-bottom to margin-top for image */
.about img {
width: 100%;
margin-top: -100px;
}

div won't expand height for floating contents

This question has been asked a bunch and I've looked at them all (seemingly). I have a div with some floating content that won't expand to the size of the content. I've added clear:both (to literally every possible line, which has effects, but doesn't solve it), and I've tried every permutation of overflow:hidden or overflow:auto on pretty much every element in here. Just for good measure I have also tried changing the divs to spans.
Whatever I do, if you make the window skinny enough eventually the buttons fall below the area of the div. Why and how can I fix it?
JSFiddle
.confirmation-modal {
z-index: 1; /* Sit on top */
width: 100%; /* Full width */
height: 4rem;
max-height:18rem;
overflow: auto;
text-align: center;
border-radius:5px;
}
.confirmation-raised-panel{
background-color: #ffed83;
padding: 0px;
text-align: center;
height: 4rem; /* Full height */
max-height:18rem;
overflow: auto;
}
.buttons{
float:right;
}
.confirmation-message {
overflow: auto;
margin: 20px 0 0 30px;
font-size: 1.2rem;
font-weight: 400;
float:left;
}
.clear{
clear:both;
}
<div class="confirmation-modal">
<div class="confirmation-raised-panel">
<div class="confirmation-message">
This is a big message that takes up a bunch of space. Yes indeed. Do you like it?
</div>
<div>
<div class="buttons">
<button>Yes, I'm Sure</button>
<button>Cancel</button>
</div>
<br class="clear"/>
</div>
</div>
</div>
Well, you have height: 4rem; in the outer two containers - this prevents them from getting any higher. Delete that or make that min-height, and you are all set:
.confirmation-modal {
z-index: 1;
/* Sit on top */
width: 100%;
/* Full width */
min-height: 4rem;
max-height: 18rem;
overflow: auto;
text-align: center;
border-radius: 5px;
}
.confirmation-raised-panel {
background-color: #ffed83;
padding: 0px;
text-align: center;
min-height: 4rem;
max-height: 18rem;
overflow: auto;
}
.buttons {
float: right;
}
.confirmation-message {
overflow: auto;
margin: 20px 0 0 30px;
font-size: 1.2rem;
font-weight: 400;
float: left;
}
.clear {
clear: both;
}
<div class="confirmation-modal">
<div class="confirmation-raised-panel">
<div class="confirmation-message">
This is a big message that takes up a bunch of space. Yes indeed. Do you like it?
</div>
<div>
<div class="buttons">
<button>Yes, I'm Sure</button>
<button>Cancel</button>
</div>
<br class="clear" />
</div>
</div>
</div>
You have a fixed height for your modal (height: 4rem), he can't expand.
.confirmation-modal {
width: 100%;
text-align: center;
border-radius: 5px;
background-color: #ffed83;
overflow: hidden;
}
.confirmation-message {
margin: 1rem;
font-size: 1.2rem;
font-weight: bold;
}
.buttons{
float: right;
margin: 0 1rem 1rem;
}
<div class="confirmation-modal">
<p class="confirmation-message">This is a big message that takes up a bunch of space. Yes indeed. Do you like it?</p>
<div class="buttons">
<button>Yes, I'm Sure</button>
<button>Cancel</button>
</div>
</div>

Move text to bottom of div to align with image

To preface: I've come across a number of other solutions but have had no luck finding one that works. I'm currently using this answer for align my text to the bottom of my divs, but without any luck.
For whatever reason, my vertical-align: bottom; property does not affect the css of the page at all. What am I doing wrong here if I want to align the text to the bottom of the image?
index.html
<body>
<div class="header">
<div class="container">
<div class="pull-left">
What's This?
</div>
<img src="http://placehold.it/75x75" />
<div class="pull-right">
About
</div>
</div>
</div>
<!-- Modules -->
<!-- Controllers -->
<!-- Services -->
</body>
main.css
html, body {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
body {
background-color: #FF3B4E;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
background-color: white;
text-align: center;
height: 125px;
}
.header img {
margin: 25px 0;
}
.header .pull-left{
border: 1px solid black;
height: 75px;
margin-top: 25px;
top: 0;
line-height: 75px;
vertical-align: bottom;
}
.header .pull-right {
border: 1px solid black;
height: 75px;
margin-top: 25px;
top: 0;
line-height: 75px;
vertical-align: bottom;
}
The reason I have boxes around pull-left and pull-right is for visual purposes when dealing with this problem. I'll remove the borders once I can get the text to align properly. Thanks for any help!
jsfiddle: https://jsfiddle.net/rtc498uk/
EDIT: My goal is to get the text to align like this:
.pull-right a, .pull-left a{
line-height: 1em;
vertical-align: bottom;
}

Centering Image and Text

I am creating a web page with 2 <div>s side by side. Each <div> will have 2 sections.
I want to center them (bring them to the middle of the <div>). I am trying to make this <div> responsive. In the website, 2 <div>s will be in one line, while in mobile one <div> will appear on one line and the other <div> will appear on a second line. I am trying to center the image and text of each section.
How can I accomplish that?
.wrapper {
width: 100%;
overflow: hidden;
}
.wrapper div {
min-height: 45px;
padding: 1px;
}
#one {
background-color: gray;
float: left;
width: 50%;
}
#two {
background-color: red;
overflow: hidden;
min-height: 45px;
}
#media screen and (max-width: 400px) {
#one {
float: none;
margin-right: 0;
width: auto;
border: 0;
}
}
<div class="wrapper">
<div id="one">
<img src="http://livebodybuilding.com/images/fast-delivery.png" height="26" width="55" style="float:left; margin-top: 6px;" />
<p style=" font-size:13px; color:#fff; line-height:1.5; font-family: 'Montserrat',sans-serif;"><strong> FREE DELIVERY </strong>ORDERS OVER $100</p>
</div>
<div id="two">
<img src="http://livebodybuilding.com/images/free-gift.png" height="26" width="31" style="float:left; margin-top: 6px;" />
<p style="font-size:13px; color:#fff; line-height:1.5; font-family: 'Montserrat',sans-serif;"><strong> FREE GIFT</strong> ORDERS OVER $100</p>
</div>
</div>
My fiddle: https://jsfiddle.net/4okxw32v/
First of all, the use of floats in layout design is discouraged. It is generally not a good way of doing things, and usually if you're having a layout issue it comes down to a float problem. Instead you should use the display: inline-block setting. When using inline-block there are a couple of things to take into consideration.
Any white space between elements will be shown. To combat this you can set font-size: 0 on the wrapper and then set font-size: 1rem on the children. This will set the font size in the content to the same size as that of the html selector.
You can prevent line-breaking if you set white-space: nowrap on the parent and then set white-space: initial on the children.
Next instead of adding an image and floating it inside the child you can use the css pseudo element ::before (or css2 :before) on the text container inside the element.
Finally to center the contents use text-align: center on the parent
*, *::before, *::after {
box-sizing: border-box;
}
html,
body {
padding: 0px;
margin: 0px;
}
.wrapper {
font-size: 0;
}
.wrapper div {
font-size: 1rem;
min-height: 45px;
padding: 1px;
text-align: center;
font-size: 13px;
color: #fff;
line-height: 1.5;
font-family: 'Montserrat', sans-serif;
overflow: hidden;
display: inline-block;
width: 50%;
}
#one {
background-color: gray;
}
#one p:before {
content: "";
display: inline-block;
width: 4em;
height: 2em;
background-image: url(http://livebodybuilding.com/images/fast-delivery.png);
background-size: cover;
vertical-align: middle;
margin-right: 5px;
}
#two {
background-color: red;
overflow: hidden;
min-height: 45px;
}
#two p:before {
content: "";
display: inline-block;
width: 2.5em;
height: 2em;
background-image: url(http://livebodybuilding.com/images/free-gift.png);
background-size: cover;
vertical-align: middle;
margin-right: 5px;
}
#media screen and (max-width: 620px) {
.wrapper div {
width: 100%;
}
}
<div class="wrapper">
<div id="one">
<p><strong>FREE DELIVERY</strong> ORDERS OVER $100</p>
</div>
<div id="two">
<p><strong>FREE GIFT</strong> ORDERS OVER $100</p>
</div>
</div>

Floating element overlapping the main page content

I've a footer styled with CSS which floats at the bottom of the page but when I re-size browser window my footer overlaps my page contents footer is quit big though but it should not overlay the page content.
body {
padding: 0;
margin: 0;
font-family: 'Open Sans', sans-serif;
}
a {
text-decoration: none;
color: #64aba7;
}
strong {
color: #fff
}
.container {
min-height: 500px;
}
.header {
margin-top: 60px;
}
.header,
img {
display: block;
margin-right: auto;
margin-left: auto;
}
.content {
display: block;
margin-right: auto;
margin-left: auto;
text-align: center;
width: 500px;
}
.green-color {
color: #25b04b;
}
.dark-green {
color: #016838;
}
.footer {
width: 100%;
background: #00756f;
position: absolute;
bottom: 0;
}
.footer-container {
display: block;
margin-right: auto;
margin-left: auto;
width: 500px;
padding-top: 20px;
}
.font-size-12px {
font-size: 12px;
color: #64aba7;
font-weight: 50;
}
.one-third {
width: 30%;
float: left;
margin-right: 3%;
padding-bottom: 40px;
}
<div class="container">
<div class="header">
<img src="images/logo-large.png" alt="LegalHQ">
</div>
<div class="content">
<h3 class="green-color">We are redevloping our website and will be back shortly</h3>
<h4 class="dark-green"><i>In the meantime don't hesitate to call or email us</i></h4>
<p class="dark-green">0330 999 1213
<br />hello#legal-hq.co.uk
</p>
</div>
<div class="footer">
<div class="footer-container">
<div class="one-third img-div">
<img src="images/small-logo.gif" alt="LegalHQ">
</div>
<div class="one-third font-size-12px">
<strong>Legal HQ Limited</strong>
<br />Virginia House
<br />Floor 2
<br />5-7 Great Ancoats Street
<br />Manchester
<br />M4 5AD
<br />0161 974 0500
<br />
support#legal-hq.co.uk
<br />
www.legal-hq.co.uk
</div>
<div class="one-third font-size-12px">
<strong>Legal HQ Limited</strong> is regulated by the Ministry of Justice in respect of regulated claims management activities. <strong>Authorisation Number: CRM30929</strong>
www.claimsregulation.gov.uk
</div>
</div>
</div>
</div>
Here is link if you want to experience it yourself. Try and re-size the browser window to the point where you would see footer overlapping the main content.
give the html,body height of 100%, get the footer out of the container, remove position absolute, remove floats from the div-children, and add display:inline-block to them and give them widths of 28% (or remove whitespaces between them) (or otherwise you should use text-align:center for container...but that's another story)