Why can't I change the margin of my paragraphs? - html

For some context, I am brand new to programming and only about two hours in to an HTML/CSS tutorial, so I don't know many elements, properties etc. beyond what you see in my code here. Forgive me if my terminology is inaccurate, but hopefully this makes sense.
I am doing an exercise at the end of a particular lesson trying to match a design, and trying to eliminate the margin (or blank space) between my first paragraph line and my second paragraph line. As you can see, I've tried changing the margin, line-height, and padding to zero (anything I could think of) but the gap remains.
In the solution code for this exercise, I see the teacher chose to change the bottom margin targeting all paragraphs instead of the specific paragraph classes to make this happen. I would like to understand why that would work, but targeting the specific paragraph classes is not affecting the margin. I assume I will understand this later, but I hesitate to move on until I do.
My code
<style>
p {
font-family: arial;
}
.price {
font-size: 36px;
}
.currency {
margin-left: 12px;
font-size: 16px;
color: gray;
margin-bottom: 0px;
line-height: 0px;
padding-bottom: 0;
}
.change {
padding-top: 0;
margin-top: 0;
color: green;
font-size: 16px;
line-height: 0;
}
.after-hours {
color: gray;
}
.after-hours-change {
color: red;
}
</style>
<p class="price">1,049.61<span class="currency">USD</span></p>
<p class="change">+18.05 (1.75%) today</p>
<p class="after-hours">After hours 1,048.00
<span class="after-hours-change">-1.61 (0.15%)</span></p>
Picture of my result
The teacher's solution code
<style>
p {
font-family: Arial;
margin-top: 0;
margin-bottom: 0;
}
.price {
font-size: 32px;
margin-bottom: 5px;
}
.currency {
font-size: 16px;
color: rgb(100, 100, 100);
}
.change {
color: rgb(24, 128, 56);
margin-bottom: 8px;
}
.after-hours {
color: rgb(100, 100, 100);
}
.after-hours-change {
color: rgb(235, 39, 39);
}
</style>
<p class="price">
1,049.61 <span class="currency">USD</span>
</p>
<p class="change">
+18.05 (1.75%) today
</p>
<p class="after-hours">
After hours 1,048.00
<span class="after-hours-change">-1.61 (0.15%)</span>
</p>
Picture of his result

Because the margin-bottom: 5px; is not set by you to the .price.
Paragraph is a block element, so it adds up a margin below, but the font-size also counts in -- as I can see.
p {
font-family: arial;
}
.price {
font-size: 32px;
margin-bottom: 0.5em;
}
.currency {
margin-left: 12px;
font-size: 16px;
color: gray;
margin-bottom: 0px;
line-height: 0px;
padding-bottom: 0;
}
.change {
padding-top: 0;
margin-top: 0;
color: green;
font-size: 16px;
line-height: 0;
}
.after-hours {
color: gray;
}
.after-hours-change {
color: red;
}
<p class="price">1,049.61<span class="currency">USD</span></p>
<p class="change">+18.05 (1.75%) today</p>
<p class="after-hours">After hours 1,048.00<span class="after-hours-change">-1.61 (0.15%)</span></p>

Related

Why does display: flex break the phrase into lines?

I have such a text:
<div className="rate" >
<mark className="rate-mark"> Currency Rate : </mark>
<mark className="code-mark">1 {code} = </mark>
<mark className="val-mark" style={{color}}>{rate}</mark>
<mark className="base-mark"> {base} </mark>
css
.rate-mark{
font-size: 28px;
font-weight: 500;
position: relative;
left: 30%;
top: 70%;
text-align: center;
background-color: #fff;
width: 250px;
height: 50px;
}
.val-mark{
background: none;
font-family: Economica, serif;
position:relative;
top: 10%;
left: -12%;
font-size: 25px;
}
.code-mark{
background: none;
font-family: Economica, serif;
position:relative;
padding-top: 20px;
margin: 0px 0px 0px 50px;
font-size: 25px;
width: 100px;
top: 80%;
}
.base-mark{
background: none;
font-family: Economica, serif;
position:relative;
padding-top: 20px;
margin: 0px 0px 0px 500px;
font-size: 25px;
width: 100px;
top: 80%;
}
I wanted to make such a text:
1 'code' = 0.12 'base'
But I couldn't shift base and code relative to value.I.e. top,left... didn't work.I saw in a similar situation that it is necessary to set for the parent div .rate{ display: flex; }
But after I did it the phrase Currency Rate : divided into new lines:
I tried to change everything so that it was on the same line, but nothing works.I've worked with css very little, so I'll be glad for help to fix it.
It is not clear at all what your overall objective is, but if all you want is the phrase on one line then, given that there is sufficient width on your device/view to do so, then the following is all you need:
.ratePhrase {
font-family: Economica, serif;
}
span.rate{
font-size: 28px;
background: #fff;
}
span.val {
background: none;
font-size: 25px;
}
span.code {
background: none;
font-size: 25px;
}
span.base {
background: none;
font-size: 25px;
}
<div class="ratePhrase" >
<span class="rate"> Currency Rate : </span><br>
<span class="code">1 {code} = </span>
<span class="val" style={{color}}>{rate}</span>
<span class="base"> {base} </span>
</div>
If you do not want the phrase to wrap, even if your device/view is not wide enough, then add 'white-space: nowrap;' to the .ratePhrase CSS class.
flex are adjustable objects if there isn't enough space for the full sentence it will go to the next line.
You could solve this by wrapping the whole thing around a div like
<div>Currency Rate: </div>
If that doesn't work you could try increasing margin and padding in css

Changing line height of horizontal rule

I have followed a tutorial on the internet and I have the following html template:
body {
font-weight: 200;
font-size: 14px;
}
.header {
font-size: 20px;
font-weight: 100;
text-align: center;
color: #007cae;
}
.title {
font-size: 22px;
font-weight: 100;
/* text-align: right;*/
padding: 10px 20px 0px 20px;
}
.title span {
color: #007cae;
}
.details {
padding: 10px 20px 0px 20px;
text-align: left !important;
/*margin-left: 40%;*/
}
.hrItem {
border: none;
height: 1px;
/* Set the hr color */
color: #333; /* old IE */
background-color: #fff; /* Modern Browsers */
}
<div class='wrapper'>
<div class='header'>
<p class='title'>Invoice #<hr class='hrItem' /> </p>
</div>
<div>
<div class='details'>
Bill to: <br/>
Amount: <br/>
Date:
</div>
</div>
The problem that I am having is that between Invoice # and the horizontal rule there is a significant amount of white space that I want to remove. I tried changing the padding and the margin in the .hrItem,.tittle and .header, however, this made no difference. Is it possible to remove that white space or should I reconsider the method of adding the horizontal line?
You need to place the <hr> outside of your <p>, as having it inside is invalid HTML and actually ends up creating an empty <p></p>, which creates more space:
What you should have is:
<div class='header'>
<p class='title'>Invoice #</p>
<hr class='hrItem' />
</div>
Once you make that change, you can control the spacing between the .hrItem and the .title by changing their margin properties (I set both to 0):
body {
font-weight: 200;
font-size: 14px;
}
.header {
font-size: 20px;
font-weight: 100;
text-align: center;
color: #007cae;
}
.title {
font-size: 22px;
font-weight: 100;
/* text-align: right;*/
padding: 10px 20px 0px 20px;
margin: 0;
}
.title span {
color: #007cae;
}
.details {
padding: 10px 20px 0px 20px;
text-align: left !important;
/*margin-left: 40%;*/
}
.hrItem {
border: none;
height: 1px;
/* Set the hr color */
color: #333; /* old IE */
background-color: #fff; /* Modern Browsers */
margin: 0;
}
<div class='wrapper'>
<div class='header'>
<p class='title'>Invoice #</p>
<hr class='hrItem' />
</div>
<div class='details'>
Bill to: <br/>
Amount: <br/>
Date:
</div>
</div>

Remove blank spaces between buttons in HTML, CSS

I want to remove blank spaces between the buttons, so that when I for example hover over the NORMAL button, there will be no blank space between it and the HARD button. How can I do that and where do these blank spaces come from?
body {
margin: 0;
}
#stripe {
background-color: white;
text-align: center;
height: 50px;
color: black;
}
button {
border: none;
background: none;
text-transform: uppercase;
height: 100%;
font-weight: 700;
color: black;
letter-spacing: 1px;
font-size: inherit;
transition: all 0.3s;
outline: none;
}
button:hover {
color: white;
background: black;
}
.selected {
color: white;
background: black;
}
<div id="stripe">
<button class="mode">Easy</button>
<button class="mode">Normal</button>
<button class="mode selected">Hard</button>
</div>
Browsers always add spaces between some elements, including buttons. To remove these, you need to set font-size to zero for their parent container. Then, to restore text size inside buttons, set font-size for them.
#stripe {
font-size: 0;
}
button {
font-size: 14px; // Set font size that you need here
}
Either remove the spaces and carriage returns, or put an HTML comment between them.
body {
margin: 0;
}
#stripe {
background-color: white;
text-align: center;
height: 50px;
color: black;
}
button {
border: none;
background: none;
text-transform: uppercase;
height: 100%;
font-weight: 700;
color: black;
letter-spacing: 1px;
font-size: inherit;
transition: all 0.3s;
outline: none;
}
button:hover {
color: white;
background: black;
}
.selected {
color: white;
background: black;
}
<div id="stripe">
<button class="mode">Easy</button><!--
--><button class="mode">Normal</button><!--
--><button class="mode selected">Hard</button>
</div>
Add display: flex; to the parent container
If using bootstrap, can group buttons together by wrapping in div with class="btn-group".
Example for v3.3.7: https://getbootstrap.com/docs/3.3/components/#btn-groups-single
Visually might or might not be what you want. Has rounded corners on left and right ends and straight line between buttons. Can probably restyle.

Trying to remove padding from my h2 titles

Hi I'm trying to bring my h2 Titles towards the top of the div they're in, but I can't figure out how to remove the padding / margin / whatever it is that is causing them to be spaced down so far.
This is the first time I've tried using "sections" and I'm using them to create a parallax scrolling website. I've uploaded the site so you can see it in action. Where it states "Title One", "Title Two", etc, this is what I want to bring up towards the top of the div they're inside of.
example website url... http://www.littleroomproductions.com/jQtest/
Below are the parts of code that I think need to be changed in order to bring the titles up to the top of the div...
//HTML
<section class="box content">
<div id="me"></div>
<div class="container">
<h2>Title One</h2>
<p>This is where text goes </p>
<div class="someContent">
<p>click me</p>
</div>
</div>
</section>
//CSS used
section.box:last-child {
margin-bottom: 0;
}
section.box h2 {
padding-top: 0;
margin-bottom: 20px;
color: #606060;
font-family: serif;
font-size: 30px;
}
section.box p {
padding-top: 0;
margin-bottom: 20px;
color: black;
font-size: 20px;
font-family: cursive;
font-weight: 300;
}
section.box p:last-child {
margin-bottom: 300px;
}
section.box.content {
padding-top: 0;
padding-left: 40px;
padding-bottom: 40px;
}
section.box.slide {
padding: 240px 0;
background-position: 0 0;
}
section.box.slide h1 {
color: yellow;
font-size: 48px;
/*line-height: 1;*/
font-weight: 700;
text-align: center;
text-transform: uppercase;
text-shadow: 0 0 10px black;
}
Your
#me #projects #hire have a 100px padding-top;
try this
section.box h2 {
padding-top: 0;
margin: -7px 0;
color: #606060;
font-family: serif;
font-size: 30px;
}

Text not going underneath other portion of text

My text does not seem to want to go underneath this portion of text!
http://prntscr.com/1x2zju
No matter how hard we try to get it to go under it, it doesn't go below it.
.avatar {
float: left;
width: 35px;
height: 35px;
border: 1px solid #000;
}
.name {
color: #3B63DB;
font-size: 15px;
margin-top: 0;
float: left;
padding-left: 5px;
}
.text {
font-size: 12px;
color: #000;
font-family: Helvetica, 'SEGOEUIL', sans-serif;
margin-left: 3px;
float: auto;
}
HTML:
<div id='post'>
<img class='avatar' src='http://cppsgang.com/images/person.png'>
<p class='name'>Thomas A.</p>
<p class='text'>Hello there! This is my status update. Unfortunately, it will not go below my name. Is there any way I can put it below my name, or is it stuck like this forever? I have to add more in, blah blah blah, to show you how it eventually breaks apart - just not underneath the name. Thanks for all the help you can give!</p>
<a href='system/posts/delete.php?id=$row[0]'/><span style='color: red;'>Delete</span></a>
</div>
Thanks!
http://jsfiddle.net/QUFx5/
EDIT WITH WORKING
JSFIDDLE
HTML
<div id='post'>
<img class='avatar' src='http://lorempixel.com/output/people-q-c-35-35-9.jpg'>
<p class='name'>Thomas A.</p>
<p class='text'>Hello there! This is my status update. Unfortunately, it will not go below my name. Is there any way I can put it below my name, or is it stuck like this forever? I have to add more in, blah blah blah, to show you how it eventually breaks apart - just not underneath the name. Thanks for all the help you can give!</p>
<a href='system/posts/delete.php?id=$row[0]'/><span style='color: red;'>Delete</span></a>
</div>
CSS
.avatar {
float: left;
width: 35px;
height: 35px;
border: 1px solid #000;
}
.name {
color: #3B63DB;
font-size: 15px;
margin: 0;
padding-left: 45px;
}
.text {
font-size: 12px;
color: #000;
font-family: Helvetica, 'SEGOEUIL', sans-serif;
margin-left: 5px;
padding-left:45px;
margin:0;
}
I have tried with your jsfiddle.net.
This thing worked for me:
.avatar {
float: left;
width: 50px;
height: 50px;
border: 1px solid #000;
}
.name {
color: #3B63DB;
font-size: 15px;
margin-top: 0;
padding-left: 5px;
}
.text {
font-size: 12px;
color: #000;
font-family: Helvetica, 'SEGOEUIL', sans-serif;
margin-left: 3px;
}
I have removed float from name and text class. Also, increased the width & height of avatar to 50px each.
The new code I tried which works according to your requirement:
.avatar {
float: left;
width: 35px;
height: 35px;
border: 1px solid #000;
}
.name {
color: #3B63DB;
font-size: 15px;
}
.text {
font-size: 12px;
color: #000;
font-family: Helvetica, 'SEGOEUIL', sans-serif;
margin-top:-15px;
}