Trying to add a center title to my page - css

I'm looking to add a center text title in the middle of my page and it won't show up. Code seems correct, don't see a bug.
<div id="welcome_text_div">
<p id="welcome_text"> Welcome </p>
</div>
#welcome_text_div {
position: absolute;
background-color:red;
width:800px;
height:300px;
top: 50%;
margin-top: -150%;
left: 50%;
margin-left: -400px;
}
#welcome_text {
color: white;
font-family: sans-serif;
text-transform: uppercase;
font-weight: bold;
font-size: 55px;
text-align: center;
}

You just need to use text-align: center and it should center automatically. BTW I see you are using ids often which is very bad practice. IDs should be used for javasscript selectors while class for css.
.center-text {
text-align:center;
}
.title-text {
// Do css formating here
}
<div class="center-text title-text">
<p class="page-title"> Welcome </p>
</div>

try this
#welcome_text_div {
position: absolute;
background-color:red;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
#welcome_text {
color: white;
font-family: sans-serif;
text-transform: uppercase;
font-weight: bold;
font-size: 55px;
text-align: center;
width: 800px;
line-height: 300px;
}
<div id="welcome_text_div">
<p id="welcome_text"> Welcome </p>
</div>
<div id="welcome_text_div">
<p id="welcome_text"> Welcome </p>
</div>
#welcome_text_div {
position: absolute;
background-color:red;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
#welcome_text {
color: white;
font-family: sans-serif;
text-transform: uppercase;
font-weight: bold;
font-size: 55px;
text-align: center;
width: 800px;
line-height: 300px;
}

You can achieve this with flexbox.
All you need to do to the container is define its width and height (and give it a bg color):
#welcome_text_div {
background-color:red;
width:800px;
height:300px;
}
Then add these three lines to set the flexbox display context, and center it vertically and horizontally:
display:flex;
align-items:center;
justify-content:center;
Then remove all the extra formatting from your inner div.
#welcome_text_div {
background-color:red;
width:800px;
height:300px;
display:flex;
align-items:center;
justify-content:center;
}
#welcome_text {
color: white;
font-family: sans-serif;
text-transform: uppercase;
font-weight: bold;
font-size: 55px;
}
https://jsfiddle.net/k5zve6bf/

Related

I want to recreate this quote in css

Hello i am a beginner in css and i want to recreate this:
this is my current start,i don`t know how to put the ' " '
#rectangle{
width: 100%;
height: 230px;
background-color:darkcyan;
display: block;
margin: 0px;
}
#rectangle p{
padding-top: 85px;
padding-left: 60px;
padding-right: ;
font-family: roboto_bold;
text-transform: uppercase;
margin: 0 auto;
display: block;
font-size: 38px;
color: aliceblue
}
`
Try to use a :before, something like this should give you an approximative result
#rectangle p:before {
content: '"';
position: absolute;
color: yellow;
font-size: 2em;
transform: translateY(-100%);
}
As a beginner the inclusion of other libraries or pseudo elements may be tricky. Here's a rather straightforward start.
.blue-box {
background: #2edfd2;
padding: 10px 40px;
width: 300px;
}
.lquote {
color: #ace941;
font-size: 60px;
height: 20px;
}
.underline {
background-color: #ace941;
height: 4px;
width: 20px;
}
.fine-print {
margin: 4px 0 0;
font-size: .6em;
}
<div class="blue-box">
<div class="lquote">“</div>
<p>Knowing I was adopted may have made me feel more independent, but I have never felt abandoned. My parents made me feel special.
<div class="underline"></div>
<p class="fine-print">Steve Jobs, 2009</p>
</div>
There can be many ways of doing this, one of which is that you can use icons.
Like I personally use fontawesome.
You can get many icons of different sizes just use them with an online css file.
http://fontawesome.io/icon/quote-left/
This is the link to the quotes that you want to insert
I created a prototype for you.
https://codepen.io/djmayank/pen/opYeyo
#rectangle{
width: 100%;
height: 230px;
background-color:darkcyan;
display: block;
margin: 0px;
}
#rectangle p{
padding-top: 5px;
padding-left: 60px;
padding-right: ;
font-family: roboto_bold;
text-transform: uppercase;
margin: 0 auto;
display: block;
font-size: 38px;
color: aliceblue
}
.fa {
color:#abe941;
margin-top:3%;
margin-left:10%;
}
<div id="rectangle">
<i class="fa fa-quote-left fa-2x" aria-hidden="true"></i>
<p>Loreim ispum Loreim ispumLoreim ispum Loreim </p>
</div>
<script src="https://use.fontawesome.com/8d594f9226.js"></script>

My divs are piling up underneath each other

I was doing some CSS, and my divs keep piling up underneath each other. I tried using position on them but it didn't work. My work is below. The picture I have in it will not be available to you as it is from my computer, but I hope you can get the idea of what my issue is(The sitelingo and Capture12 are the ones piling up):
#logomain {
font-family: museo-sans-rounded, sans-serif;
font-size: 33px;
color: white;
font-weight: 600;
padding-top: 13px;
padding-left: 470px;
}
#sitelingo {
font-family: museo-sans-rounded, sans-serif;
font-size: 14px;
font-weight: bold;
position: relative;
color: white;
padding-left: 232px;
padding-top: 24px;
}
#barone {
position: fixed;
float: left;
width: 50%;
height: 70px;
background-color: #0A4076;
}
#bartwo {
postition: fixed;
float: right;
width: 50%;
height: 70px;
background-color: #0A4076;
}
#login {
padding-left: 400px;
position: absolute;
}
body {
margin: 0;
}
.bold {
font-weight: bold;
}
<head>
<title>Duolingo</title>
</head>
<body>
<div id="barone">
<div id="logomain"> duolingo </div>
</div>
<div id="bartwo">
<div id="sitelingo"> Site language: English </div>
<div id="login"> <img src="images/Capture12.png" /> </div>
</div>
</body>
</html>
A couple of issues:
You set a position:fixed to #barone. This will position the element relative to the actual screen.
You have elements positioned absolute, when the screen resizes, it will overlap with other elements
A padding left is set on your logo, this makes it out of viewpoint
Maybe you may want something as depicted below
#logomain {
font-family: museo-sans-rounded, sans-serif;
font-size: 33px;
color: white;
font-weight: 600;
padding-top: 13px;
/* padding-left: 470px;*/
}
#sitelingo {
font-family: museo-sans-rounded, sans-serif;
font-size: 14px;
font-weight: bold;
position: relative;
color: white;
/*padding-left: 232px;*/
padding-top: 24px;
}
#bar_container {
background-color: #0A4076;
}
#barone {
/* position: fixed;*/
height: 70px;
background-color: #0A4076;
display: inline-block;
}
#bartwo {
postition: fixed;
float: right;
height: 70px;
background-color: #0A4076;
}
#bartwo *{
display:inline-block;
}
#login {
position:relative;
/*padding-left: 400px;
position: absolute; */
vertical-align: middle;
top:0;
}
#login img{
width:100px;
height:100%;
}
body {
margin: 0;
}
.bold {
font-weight: bold;
}
<head>
<title>Duolingo</title>
</head>
<body>
<div id="bar_container">
<div id="barone">
<div id="logomain"> duolingo </div>
</div>
<div id="bartwo">
<div id="sitelingo"> Site language: English </div>
<div id="login"> <img src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRgKSOJmOr8tNodELaCLPrI1T2XE7iwrpuxPDGuFeoJwlJC4AVKZw" /> </div>
</div>
</div>
</body>
</html>

Centering div horizontally and vertically without distorting content

I am trying to center the div with id="center" both vertically and horizontally within the body tag without distorting the placement of the content: M, cicle div and Coming soon... text. Can't really get it to work even though it should be a simple thing..
HTML:
<body>
<div id="center">
<div class="circle"><div>M</div></div>
<h2>Coming soon...</h2>
</div>
</body>
CSS:
* {
margin: 0;
padding: 0;
font-family: futura;
}
body {
height: 100%;
width: 100%;
background-color: black;
}
h2 {
color: #f6c003;
font-family: serif;
font-style: italic;
font-weight: 400;
font-size: 0.9em;
margin-top: 10px;
}
.circle {
text-align: center;
width: 50px;
height: 50px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #f6c003;
}
.circle div {
float:left;
width:50px;
padding-top:25px;
line-height:1em;
margin-top:-0.5em;
text-align:center;
color:black;
font-style: bold;
font-weight: 700;
font-family: serif;
font-size: 2.5em;
}
Fiddle
You can use some absolute positioning to get it done
#center {
position:absolute;
left:50%;
top:50%;
margin: -33px 0 0 -43px;
}
The key being that you have negative margins of half the width and half the height to properly position th element ( fixed size only )
Also make sure your body is set to position: relative; in order for the absolute positioning to work correctly.
<style>
body {
height: 100%;
width: 100%;
background-color: black;
}
h2 {
color: #f6c003;
font-family: serif;
font-style: italic;
font-weight: 400;
font-size: 0.9em;
margin-top: 10px;
}
.circle {
text-align: center;
width: 50px;
height: 50px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #f6c003;
}
.circle div {
float:left;
width:50px;
padding-top:25px;
line-height:1em;
margin-top:-0.5em;
text-align:center;
color:black;
font-style: bold;
font-weight: 700;
font-family: serif;
font-size: 2.5em;
}
#center
{
position:absolute;
left:50%;
top:50%;
}
</style>
<body>
<div id="center">
<div class="circle"><div>M</div></div>
<h2>Coming soon...</h2>
</div>
</body>
As much as I hate tables, tables do a good job of vertically aligning. Maybe there's a better way?
<body>
<table>
<tr>
<td>
<div id="center">
<div class="circle"><div>M</div></div>
<h2>Coming soon...</h2>
</div>
</td>
</tr>
</table>
</body>
Style:
table {
width: 100%;
height: 100%;
border-spacing: 0px;
border-collapse: collapse;
}
.center {
margin: auto;
}

Making css circles at the bottom of an image responsive and at a fixed position

I have a problem I can't figure out in css. At the bottom of an imageslider I have three circles, but they need to be a bit responsive so that everyone on a laptop from 13' till 21' can see them at their exact position. But when I resize the screen, these circles loose their position and will be placed a bit higher or lower. Here is the example I am talking about, you will see when you resize the screen, the circles are not in their original good position, at the bottom of the image.
I am working towards this. The code I have is the following:
CSS
.bxslider {
margin: 0;
padding:0;
}
#bijschrift {
position: relative;
left: 65%;
height: auto;
bottom: 250px;
float: left;
z-index: 9999;
}
#bijschrifthoofd {
z-index: 9999;
opacity: 0.8;
padding-left: 10px;
padding-right: 10px;
background-color: #212121;
}
#bijschrifthoofd span {
width: auto;
color: white;
font-family: 'Open Sans', sans-serif;
font-weight: 500;
line-height: 45px;
font-size: 150%;
}
#bijschriftonder {
z-index: 9999;
opacity: 0.8;
margin-top: 10px;
padding-left: 10px;
padding-right: 10px;
background-color: #212121;
float: left;
}
#bijschriftonder span {
width: auto;
color: white;
font-family: 'Open Sans', sans-serif;
font-weight:100;
line-height: 45px;
font-size: 22px;
}
#cirkelcontainer {
width: 100%;
height: auto;
position: relative;
bottom: 200px;
z-index: 9999;
display: block;
}
.circle
{
display:table-cell;
width:80px;
height:80px;
border-radius:40px;
font-size:16px;
color:white;
vertical-align: top;
text-align:center;
background:#00ccff;
float: left;
font-family: 'Open Sans', sans-serif;
font-size: 22px;
line-height: 80px;
}
.circle2 {
display:table-cell;
margin-left: 2%;
z-index: 9999;
width:80px;
height:80px;
border-radius:40px;
font-size:16px;
color:white;
vertical-align: top;
text-align:center;
background:#e05c50;
float: left;
font-family: 'Open Sans', sans-serif;
font-size: 22px;
line-height: 80px;
}
.circle3 {
display:table-cell;
margin-left: 10%;
z-index: 9999;
width:80px;
height:80px;
border-radius:40px;
font-size:16px;
color:white;
vertical-align: top;
text-align:center;
background:#0099cc;
float: left;
font-family: 'Open Sans', sans-serif;
font-size: 22px;
line-height: 80px;
}
HTML
<ul class="bxslider" >
<li><img src="fotos/Untitled-5.jpg" title="Funky roots" /></li>
<li><img src="fotos/Untitled-4.jpg" title="The long and winding road" /></li>
<li><img src="fotos/Untitled-3.jpg" title="Happy trees" /></li>
</ul>
<div id="bijschrift">
<div id="bijschrifthoofd"><span>UW SPRINGPLANK NAAR INSPIRATIE</span></div>
<div id="bijschriftonder"><span>En authentieke waterpret</span></div>
</div>
<div style="clear:both"></div>
<div id="cirkelcontainer">
<div class="circle">O</div>
<div class="circle2">IB</div>
<div class="circle3">T</div>
</div>
</body>
</html>
I'm not sure where is the "exact position" of the circles. I'm assuming it's over the image at the bottom, like this:
http://jsfiddle.net/Y65mW/1/
So I changed the circles Html like this:
<div id="circle1" class="circle">O</div>
and the Css so we can use a single circle style definition:
.circle {
position: absolute;
width:80px;
height:80px;
border-radius:40px;
...
}
#circle1 {
left: 60px;
background:#00ccff;
}
You should still add a 'min-width' property to the whole site.
I updated the solution here http://jsfiddle.net/Y65mW/3/embedded/result/
The solution was quite obvious: I had to position the circles to absolute so it wouldn't affect the position of my next divs, and add a 'margin-left: -width px' to it. In this case: "margin-left: -50px;".

Create a text overflow on a image

I want to have a nice hover effect on some image i made. I want to display a text when the mouse is hover the image. I can get the text working but i would like to have a backgroud to make it more readable.
here is the HTML :
<div class="portfolio-frame">
<div class="portfolio-overflow-hidden">
<img width="420" height="236" src="http://benjaminbinauld.lfdb.fr/files/2013/03/mire-servitel16-9.jpg" />
<div class="portfolio-overlay">
<span class="text-overlay">Click here boy !</span>
</div>
</div>
</div>
And the CSS :
.portfolio-frame {
height: 94px;
width: 165px;
margin-left: 10px;
margin-top: 46px;
z-index:1;
}
.portfolio-overflow-hidden {
height: 94px;
width: 165px;
}
.portfolio-overlay .text-overlay {
display: none;
}
.portfolio-frame:hover .portfolio-overlay {
display:block;
position:inherit;
z-index:999;
background-color: #000;
}
.portfolio-frame:hover .text-overlay {
display:block;
z-index:999;
text-transform: uppercase;
font-weight: bold;
color: #fff;
margin-top: -45px;
}
I make live version here : http://jsfiddle.net/fzKe7/
You need to add position:relative to .portfolio-overlay
See fiddle here
You could also tidy up your css:
.portfolio-frame {
height: 94px;
width: 165px;
margin-left: 10px;
margin-top: 46px;
}
.portfolio-overflow-hidden {
height: 94px;
width: 165px;
}
.portfolio-overlay .text-overlay {
display: none;
position:inherit;
background-color: #000;
position:relative;
text-transform: uppercase;
font-weight: bold;
color: #fff;
top:-45px;
}
.portfolio-frame:hover .text-overlay {
display:block;
}
.portfolio-frame:hover .portfolio-overlay { display:block; position:relative; z-index:999; background-color: #000; }
Change the position to Relative. That should work

Resources