The story title is not centering, when I change it to h1, it just disappears. I am really not sure why this is.
storytitle {
background-color: black;
font-color: #ff0000;
font-size: 150%;
text-align: center;
}
ree {
background-color: black;
color: #0000ff;
font-size: 100%;
text-align: right;
}
body {
background-color: black;
}
<title>Story2</title>
<storytitle style="color:red;text-align:center">
THiS IS A TEST TITLE </br>
</storytitle>
<ree>
this is a test body
</ree>
Your basic problem is that you are not writing HTML.
Error recovery in browsers will create a storytitle element with some default styling that includes display: inline.
The text-align property does not apply to inline elements.
The solution is to write valid HTML. If you use an h1 element (all else being equal) it will not disappear and, being display: block by default, the text-align property will apply.
h1{
background-color:black;
font-color:#ff0000 ;
font-size:150%;
text-align:center;
}
p{
background-color:black;
color:#0000ff;
font-size:100%;
text-align:right;
}
body{
background-color:black;
}
<h1 style="color:red;text-align:center">THiS IS A TEST TITLE</h1>
<p>this is a test paragraph</p>
There are a lot of mistakes:
The HTML tags weren't valid HTML tags
I changed the tags to h1, h2 and p (headers and paragraph).
I assumed you wanted to use story, storytitle and ree as classes, so I did that for you in the code below.
The styling was redundant
on your "storytitle" you had the styles color: red and text-align: center, but they were already applied in your <style></style>
</br> is an end tag but doesn't exist, it's <br> and <br /> in HTML5.
The black background-color on your body was enough to give our page a black background. Applying the same color background to your elements is in this case unnecessary.
Here is the updated version with correct HTML and styling:
body {
background-color: black;
}
.title {
color: yellow;
text-align: center;
}
.storytitle {
color: #ff0000;
font-size: 150%;
text-align: center;
}
.ree {
color: #0000ff;
font-size: 100%;
text-align: right;
}
<h1 class="title">Story2</h1>
<h2 class="storytitle">
THIS IS A TEST TITLE
</h2>
<br />
<p class="ree">
this is a test body
</p>
Related
I think this is a real silly question.
But I really can not find an answer.
I need to give all my h2 tags the border-top element, except my h2 tag that is in my <header>.
Now it gives it a big line there and it is going across my header.
I really don't know how to solve this issue that seems so easy.
body {
background-color: AntiqueWhite;
max-width: 800px;
font-family: "Arial", Helvetica, sans-serif;
color: black;
}
h2, h3 {
font-style: italic;
color: darkblue;
}
h3 {
border-top:1px solid #999; padding-top:10px;
}
header {
background-image: url(pics/bg.jpg);
height: 140px;
background-position: center;
}
You just need to be specific.
header h2 {
border-top:none;
}
You can override the <h2>'s style and set the border back to it's default, like so:
h2 {
border-top: 1px solid white;
}
header h2 {
border-top: initial;
}
Or, and this is the approach I recommend, have your border-top in a class. Then, only instances of <h2> that have that class will have a border:
h2.with_border {
border-top: 1px solid white;
}
And then in your HTML:
<h2 class="with_border">This has a border!</h2>
<h2>This does not have a border!</h2>
CSS lets you compose selectors that are more complex; the simplest way of doing this is the descendant selector, which will work for your question. You can write this:
header h2 { }
to target any h2 that is a child (direct or not) of a header. For example:
h2 { border-bottom: 1px solid blue; }
header h2 { border-bottom: none; }
<header>
<h2>No border here!</h2>
</header>
<h2>But here there is</h2>
You should also do some reading up on how css works; there are all kinds of ways to select elements, including classes and attributes. Which one you use will depend on what you're trying to achieve and how specific you need to be.
I have created a JSFiddle for you.
HTML
<h2>Header One</h2>
<h2>Header Two</h2>
<h2>Header Three</h2>
<header>
<h2>Header Four</h2>
</header>
CSS
h2{
border-top: 1px solid green;
}
header h2{
border-top: none;
}
Hope this helps.
I tried to use the text-align in CSS but it does not work.
here is the CSS and I also had all the body set to center, does that have to do with something?
Here is my CSS:
#Swell {
text-align: left;
}
Here is my HTML:
<a id="Swell" href="https://www.swell.com">Use Swell Bottles<img src="https://s-media-cache-ak0.pinimg.com/originals/f9/93/95/f99395b48463ee8d3bfa16f32df51c98.jpg" height="50"></a>
Also my CSS body text-align:
body {
font-family: sans-serif;
text-align: center;
background-color: rgb(128, 212, 255);
}
Dose the text-align: center have to do with the error and if that is true then how do I overwrite/fix this error
An anchor element <a> is an inline element per default. Meaning it has no width or height on its own but rather is exactly as big as its content.
The text-align property does work in your example. It's just that the text is aligned regarding it's container. Which in this case is exactly as big as it's content. Therefore you would not see any difference.
Try to set the display property of the anchor element to block and see what happens.
a{
display:block;
text-align:right;
}
<a>Blocking beautiful</a>
Edit: More in line with your example:
body{
text-align:center;
}
a{
display:block;
text-align:left;
}
<body>
<a>Still beautiful</a>
<span>centered</span>
</body>
html
<div id="parentdiv">
<a id="Swell" href="https://www.swell.com">Use Swell Bottles<img src="https://s-media-cache-ak0.pinimg.com/originals/f9/93/95/f99395b48463ee8d3bfa16f32df51c98.jpg" height="50"></a>
</div>
css
body {
font-family: sans-serif;
text-align: center;
background-color: rgb(128, 212, 255);
}
#parentdiv {
text-align: left;
}
Example
<html>
<style>
body {
font-family: sans-serif;
text-align: center;
background-color: rgb(128, 212, 255);
}
#parentdiv {
text-align: left;
}
</style>
<div id="parentdiv">
<a id="Swell" href="https://www.swell.com">Use Swell Bottles<img src="https://s-media-cache-ak0.pinimg.com/originals/f9/93/95/f99395b48463ee8d3bfa16f32df51c98.jpg" height="50"></a>
</div>
</html>
This container stubbornly refuses to center. Demo: http://codepen.io/Diego7/pen/KzXgZN
I've tried just about every centering code I can find on the web, to no avail.
Removing width: 90%; from the css aligns the container to the left, even though margin: 0 auto; is telling it to center.
Sorry if this question isn't up to StackOverflow's 'standards', but codingforums.com are down at the moment :(
Thanks heaps!
HTML
<div class="container">
<article>
<header>
<img src="https://softwarereviews.files.wordpress.com/2016/04/bg-header-no-logo.png" width="972px"><br />
<h2>Information</h2>
</header>
<p>There's currently is no information available. Sorry.</p>
<footer>
© 2016
</footer>
</article>
</div>
CSS
##import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: 'Open Sans', sans-serif;
background: #fff;
}
.container {
list-style:none;
margin:0 auto;
width:90%;
padding-top: 20px;
background: #fff;
border-radius: 6px;
box-sizing: container-box;
}
article header h2 {
color: #282828;
font-size: 1.2em;
font-weight: normal;
display:inline;
line-height: 1.3;
}
article p {
font-size: 1em;
display:inline;
line-height: 1.5em;
color: #282828;
max-width: 972px;
}
article footer {
font-size: .9em;
display:inline;
color: #999;
}
a {
color: #2790ae;
text-decoration: none;
outline: none;
}
a:hover {
color: #0f6780;
}
Your .container is already centered: if you change background to red you will see it. And, if you add text-align property its content will be centered too.
.container {
list-style:none;
margin:0 auto;
width:90%;
padding-top: 20px;
border-radius: 6px;
box-sizing: container-box;
text-align:center;
background: red;
}
If you make the width a bit narrower (like 70%), you see that it IS centered.
by the way: " list-style:none;" has no effect whatsoever, and "box-sizing: container-box;" should be "box-sizing: content-box;"
Looks like you're centering the <div class="container">, but it doesn't look like it, because you're looking at the image.
If you want the image to take up the entire <div> element (so that any centering takes effect on both), try something like the following, instead of using an <img> element:
div.container {
background-image: url(https://softwarereviews.files.wordpress.com/2016/04/bg-header-no-logo.png);
}
There are other properties you can use to fiddle with precisely how the image is displayed. You can find more info here.
If you are using container after float tag. It can create problem sometimes. So to avoiding this user <div class="clear"></div>. Also clear class properties would be:
.clear{
clear:both;
margin:0px;
padding:0px;
height:0px;
font-size:0px;
line-height:0px;
float:none;
}
Hope it will be helpful..
I'm making a website and my text won't align to the center for the index-intro h1!
.index-intro {
width:100%;
background-color: #00C8FF;
height: 20px;
float:center;
}
.index-intro h1 {
font-family: tpeb;
font-size: 15px;
text-transform: uppercase;
text-align:center;
display:inline-block;
}
<section>
<div class="index-intro">
<div class="wrapper">
<h1>Welcome to Anime!</h1>
</div>
</div>
</section>
And thanks :)
Here is a trimmed down set of HTML and CSS:
.index-intro {
background-color: #00C8FF;
text-align:center;
}
.index-intro h1 {
font-size: 15px;
text-transform: uppercase;
}
<div class="index-intro">
<div class="wrapper">
<h1>Welcome to Anime!</h1>
</div>
</div>
This aids the vertical alignment issues too, since you had fixed the height of the containing <div>. Although I guess you may have wanted that?
Here it is with some padding thrown in:
https://jsfiddle.net/9a3b4f7g/1/
Your Css is okay.
Just add this class in style tag
<style type="text/css">
.wrapper
{
text-align: center;
}
</style>
Please try following code snippet
.index-intro {
width:100%;
background-color: #00C8FF;
height: 20px;
text-align:center
}
.index-intro h1 {
font-family: tpeb;
font-size: 15px;
text-transform: uppercase;
}
<section>
<div class="index-intro">
<div class="wrapper">
<h1>Welcome to Anime!</h1>
</div>
</div>
</section>
Believe it or not, you can do what you're looking for with just
.index-intro h1 {
font-family: tpeb;
font-size: 15px;
text-transform: uppercase;
text-align:center; /*this makes the text go in the middle*/
display:inline-block;
width:100%;
background-color: #00C8FF; /*your bar color*/
padding-top:20px; /* this "fattens" the blue bar topside */
padding-bottom:20px; /* this "fattens" the blue bar bottomside */
}
What this basically does is, 'make a blue bar that fits 100% the window width, with text in the middle, fatten it top and bottom'. It's better to keep your CSS simple like this if you can. Keeps you from getting confused in the long run.
Right now my header contains two p-tags with different styles:
<p style="color:#FFF; font-size:34px; margin-bottom:10px;">First half</p>
<p style="color:#FFF; font-size:88px;">Second half</p>
Is it possible to convert this into one h1-tag? Or can I have two h1 after each other? The main purpose is that it should work well with seo.
SEO-wise - each web page should contain one H1 tag.
A possible solution for what I believe you're trying to achieve is adding span tags in your H1 enabling you to style each part of your H1 differently:
HTML:
<h1>
<span class="smallerFont">First half</span>
<span class="bigFont">Second half</span>
</h1>
CSS:
h1 {
color: #fff;
}
.smallerFont {
font-size: 34px;
margin-bottom: 10px;
}
.bigFont {
font-size: 88px;
}
1) You should move your styling to a stylesheet.
2) You can easily have several styles in a single h1 ... like this:
HTML:
<h1>First <span class='A'>Second</span></h1>
CSS:
h1 { color:#F00; }
.A { color:#0F0; }
you can use
<h1>
<span >First half</span>
<span class='otherStyle' >Second half</span>
</h1>
Css style:
h1{
color :red;
}
h1> span{ //all the span elements within h1 is applied this style
color : blue;
font-size:34px;
margin-bottom:10px;
}
.otherStyle{
color:yellow;
font-size:88px;
}
Kinda a non-typical way to do this would be to use a combination of ::first-line and white-space: pre-line. This combo works pretty well since white=space: pre-line allows you to determine exactly where the first line ends. Of course, like the other answers, this method keeps you at just one h1 tag—ideal for SEO purposes.
A quick example on how this works:
h1 {
white-space: pre-line;
color: #fff;
font-size: 88px;
}
h1::first-line {
font-size: 34px;
}
body {
background: black;
}
<h1>First half
Second half
</h1>
That HTML looks a little weird. That's because we're forcing a newline with white-space: pre-line. It preserves any line breaks in the code (except, apparently, the last one). This makes new lines important, as demonstrated below.
h1 {
white-space: pre-line;
border: 1px black solid;
}
<h1>First half
Second half</h1>
<h1>
First half
Second half
</h1>
Still, it makes our first line end wherever we want it to, allowing us to target it with the ::first-line pseudo-element. Unfortunately, the styles supported by the ::first-line pseudo-element are fairly limited, but you can still do quite a bit. Sadly, this makes your margin-bottom hard to replicate. My closest attempt came from using line-height, which worked, but left a larger gap between the h1 and the next element. Still, it could be fixed with a little bit of negative margins, but then you could potentially run into other issues.
Though it's probably not the best way to go about doing this, it is a fun and interesting approach to solving the problem.
h1 {
white-space: pre-line;
color: #fff;
font-size: 88px;
line-height: 120px;
}
h1::first-line {
font-size: 34px;
line-height: normal;
}
/* Formatting styles */
* {
margin: 0;
padding: 0;
}
body {
background: black;
padding-top: 10%;
display: flex;
justify-content: center;
align-items: flex-start;
}
h1,
div {
max-width: 475px;
border: 1px white solid;
flex: 1;
/* Makes h1 the same font-weight
of p for better comparison */
font-weight: normal;
}
<h1>First half
Second half
</h1>
<div>
<p style="color:#FFF; font-size:34px; margin-bottom:10px;">First half</p>
<p style="color:#FFF; font-size:88px;">Second half</p>
</div>