Text in an image - html

How can I get my first name and last name below to be shown within an image at the top in the middle middle (with a bit of space from the top), and to have their position remain still together with the image when rendering the browser smaller or bigger?
(I have seen this: https://www.w3schools.com/howto/howto_css_image_text.asp, but is there any other way?)
Any help welcome, please
body{
background-image: url(http://www.icotoken.tel/images/slider_slide_5.jpg);
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
text-align: center;
justify-content: center;
align-items: center;
color: white;
}
.bigger{
padding: 30px;
height: 300px;
}
<div>
<img src="https://pbs.twimg.com/media/DYwc96nXkAY1xFh.jpg" class= "bigger">
<h3>First Name</h3>
<h3>Last Name</h3>
</div>

Is that what you want?
Refer to this post for more information.
body{
background-image: url(http://www.icotoken.tel/images/slider_slide_5.jpg);
background-size: cover;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
text-align: center;
color: white;
}
.container {
position:relative;
}
.TextContainer {
position: absolute;
left: 50%;
top: 0;
transform: translate(-50%,0);
}
<div class="container"><img class="bigger" src="https://pbs.twimg.com/media/DYwc96nXkAY1xFh.jpg"/>
<div class="TextContainer">
<h3>First Name</h3>
<h3>Last Name</h3>
</div>
</div>

Related

background-attachment image: fixed not working on mobile

I am building a website where I want the background image to be attached fixed.
I have achieved this in desktop browsers with the CSS below, but it doesn't work on Smartphone.
This is a known bug with background-attachment: fixed.
I don't know how to fix it.
#page-header{
height: 300px;
background: url("../img/wood.jpg");
background-attachment: fixed;
color: #fff;
border-bottom: 1px #eee solid;
padding-top: 50px;
}
My HTML
<header id="page-header">
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3 text-center">
<h1 id="h1header">Products</h1>
<p>Local, Organic, Tasty</p>
</div>
</div>
</div>
</header>
You can find my website at http://maisonbergeret.com/product.html
My question is how can I keep the exact same effect.
This is what I changed for page-header.
#page-header:before{
content: "";
width: 100%;
height: 300px;
position: fixed;
background: url("../img/wood.jpg")no-repeat center center;
color: #fff;
border-bottom: 1px #eee solid;
padding-top: 50px;
z-index: -10;
display: block;
left: 0;
top: 0;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Below the header, I have a section product with id="products"
section#products{
background-color: #FAEBD7;
}
Same color as my body background-color: #FAEBD7;
Adjusted margins and now it works.

Image not fully responsive

I am using Bootstrap and have an image 1920x1280. It is currently responsive only till about a width of 1000 px and stops shrinking from there. Width below 1000 px, it starts to cut off the side of the image. I need the full image to be visible on any device. I am adding the image via CSS background url. Is there a way around this. Added the relevant code below. The image is placed within the ID 'intro'.
Image
HTML
<div id="intro">
<div class="intro-body">
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h1 style="color: #000000">Title<span class="brand-heading">Quote</span></h1>
<p style="color: #000000" class="intro-text">Short description</p>
Learn More </div>
</div>
</div>
</div>
</div>
CSS
#intro {
display: table;
width: 100%;
height: auto;
padding: 100px 0;
text-align: center;
color: #fff;
background: url(../img/intro-bg.jpg) no-repeat center center fixed;
background-color: #000;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#intro .intro-body {
display: table-cell;
vertical-align: middle;
}
#intro .intro-body H1 {
font-size: 76px;
font-weight: 700;
color: rgba(255,255,255,0.8);
text-transform: uppercase;
}
#media(min-width:768px) {
#intro {
height: 100%;
padding: 0;
}
#intro .intro-body .intro-text {
font-size: 18px;
letter-spacing: 1px;
margin-bottom: 100px;
color: rgba(255,255,255,0.9);
}
}
background-size: cover; try to fill all background space so maybe cutoff edge of image. If you will show image completely without cut off set background-size to contain.
background: url(../img/intro-bg.jpg) no-repeat right bottom scroll;
background-color: #31f1fd;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
Please try this Style instead of your id intro. There are two methods. One is with fixed height and width the other one is without width and height.
#intro{
width: 100%;
height: 400px;
background-image: url('../img/intro-bg.jpg');
background-size: 100% 100%;
border: 1px solid red;
}
or
#intro{
background-image:url('../img/intro-bg.jpg');
background-repeat:no-repeat;
background-size:contain;
background-position:center;
}

HTML and CSS div in middle of screen

<style>
.parallax {
background-image: url("Cpage.png");
min-height: 700px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.box{
position: absolute;
top: 600px;
left: 300px;
width: 900px;
height:600px;
background-color:rgb(0, 32, 45);
font-size:36px;
border-radius: 50%;
}
.cap img{
position: relative;
height:130px;
width:170;
left: 340px;
}
</style>
<div class="parallax">
<div class="box" >
<div class="cap"><img src="Capture.png"/></div>
<p style="color: white;text-align: center;">
LEARNING TOWARDS BETTER FUTURE!<br>
</p>
</div>
</div>
The problem is that when I switch screens. When I go from 15 inch screen to 13 inch screen the div moves. It is not in middle of screen anymore. May be it is because of the "left:" It really gets messy when screen is smaller then that. How can I fix it ?
You can use Flex to help you center it:
.parallax {
display: flex;
align-items: center; // vertical centering
justify-content: center; // horizontal centering
background-image: url("Cpage.png");
min-height: 700px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
And remove top/left attributes from .box.
Fiddle
.box{
width: 400px;
height:400px;
background-color:rgb(0, 32, 45);
font-size:36px;
border-radius: 50%;
display: block;
margin: 0 auto;
}

CSS: Make a background-image appear without having content and/or fixed sizes?

I've got this code (with no header-image visible) so far:
.wrap {
margin: 50px auto;
}
html,
body {
height: 100%;
}
body {
background-image: url('https://placebear.com/1000/800');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
background-attachment: fixed;
}
.header {
background-image: url('https://placebear.com/940/248');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
<div class="wrap">
<div class="row">
<div class="medium-12 columns header"></div>
</div>
</div>
If you give the header-image a fixed size of 248px you can see it appear. Example with visible header-image:
.wrap {
margin: 50px auto;
}
html,
body {
height: 100%;
}
body {
background-image: url('https://placebear.com/1000/800');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
background-attachment: fixed;
}
.header {
background-image: url('https://placebear.com/940/248');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
height: 248px;
border: 3px solid white;
}
<div class="wrap">
<div class="row">
<div class="medium-12 columns header"></div>
</div>
</div>
Is there a way to make it appear without using a fixed height?
Like when using a classic img-tag with just src- and alt-attribute. Then height is read out of the image-file self.
I would like to avoid fixed heights in there because if the image changes then it becomes all wrong.
I think you have to define a height if using background-image. Might be better to use img tag and just put a width of 100%, like so:
.wrap {
margin: 50px auto;
}
html,
body {
height: 100%;
}
body {
background-image: url('https://placebear.com/1000/800');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
background-attachment: fixed;
}
.header {
border: 3px solid white;
}
img {
width: 100%;
}
<div class="wrap">
<div class="row">
<div class="medium-12 columns header">
<img src="https://placebear.com/940/248" alt="Bear Image">
</div>
</div>
</div>

Center text vertically: inline-block div next to text

Link to fiddle: https://jsfiddle.net/ernhep2a/2/
I am trying to center the image and text in the middle of the div. When I do so the text is no longer centered vertically, it drops down. How can one achieve so that the text is centered vertically?
html:
<div>
<div class="secureHome-sessions-top-status0">
<div class="secureHome-sessions-top-status-img0"></div>
Status
</div>
</div>
<div>
<div class="secureHome-sessions-top-status">
<div class="secureHome-sessions-top-status-img"></div>
Status <!-- <-- this is not centered vertically anymore -->
</div>
</div>
css:
div.secureHome-sessions-top-status0 {
float:left;
width: 10%;
margin-left:2%;
height: 20px;
background:lightblue;
}
div.secureHome-sessions-top-status-img0 {
float:left;
width: 20px;
height: 20px;
background: red;
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Thumbs_up_font_awesome.svg/512px-Thumbs_up_font_awesome.svg.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
div.secureHome-sessions-top-status {
float:left;
width: 10%;
margin-left:2%;
height: 20px;
background:lightblue;
text-align:center;
}
div.secureHome-sessions-top-status-img {
display:inline-block;
width: 20px;
height: 20px;
background: red;
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Thumbs_up_font_awesome.svg/512px-Thumbs_up_font_awesome.svg.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
Try adding this CSS to your non-floating thumbs up div:
vertical-align: middle;
When you set the second div to "inline-block" that placed the div in your text string instead of beside it. Since the div is taller than the text, it's stretching the line height and the text just falls in place afterwards. The vertical-align:middle will prevent that by centering your div against the rest of the string.
When you use inline-block, then you make a wrapper which will behave like span and text would always start from the bottom. to fix this issue please use vertical-align:middle in class div.secureHome-sessions-top-status-img issue will get resolve.
But I would recommend you to use all the text and images in separate blocks. It will help you in maintaining the content.
<div>
<div class="secureHome-sessions-top-status0">
<div class="secureHome-sessions-top-status-img0"></div>
<div>this is center</div>
</div>
</div>
<div>
<div class="secureHome-sessions-top-status">
<div class="secureHome-sessions-top-status-img"></div>
<div>this isn't center</div>
</div>
</div>
CSS
<style>
div.secureHome-sessions-top-status0 {
float: left;
width: 20%;
margin-left: 2%;
height: 20px;
background: lightblue;
}
div.secureHome-sessions-top-status-img0 {
float: left;
width: 20px;
height: 20px;
background: red;
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Thumbs_up_font_awesome.svg/512px-Thumbs_up_font_awesome.svg.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
vertical-align: middle;
}
div.secureHome-sessions-top-status {
float: left;
width: 20%;
margin-left: 2%;
height: 20px;
background: lightblue;
text-align: center;
}
div.secureHome-sessions-top-status-img {
display: inline-block;
width: 20px;
height: 20px;
background: red;
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Thumbs_up_font_awesome.svg/512px-Thumbs_up_font_awesome.svg.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
vertical-align: middle;
}
</style>
In img0 you're using float. Float elements are not in the page page normal "flow". So when you use float the image is not interfering to the text.
you could try vertical-align but that probably will dislocate the image a bit.
It will be better if you wrap the image and the text in a separated div and just center that div then you can make the float with no problem.
div.secureHome-sessions-top-status0 {
float:left;
width: 10%;
margin-left:2%;
height: 20px;
background:lightblue;
}
div.secureHome-sessions-top-status-img0 {
float:left;
width: 20px;
height: 20px;
background: red;
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Thumbs_up_font_awesome.svg/512px-Thumbs_up_font_awesome.svg.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
.in-center {
display: inline-block;
}
div.secureHome-sessions-top-status {
float:left;
width: 30%;
margin-left:2%;
height: 20px;
background:lightblue;
text-align:center;
}
div.secureHome-sessions-top-status-img {
float: left;
width: 20px;
height: 20px;
background: red;
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Thumbs_up_font_awesome.svg/512px-Thumbs_up_font_awesome.svg.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
<div>
<div class="secureHome-sessions-top-status0">
<div class="secureHome-sessions-top-status-img0"></div>
Status
</div>
</div>
<div>
<div class="secureHome-sessions-top-status">
<div class="in-center">
<div class="secureHome-sessions-top-status-img"></div>
Status
</div>
</div>
</div>
http://jsfiddle.net/8hmwojk5/
This is probably better suited as a comment as it does not answer the question within the constraints presented, but I am not yet able to leave comments; nonetheless, I hope it is helpful.
If you are able to use Flexbox, this sort of layout becomes trivial to implement.
.container {
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: center;
background: lightblue;
margin: 0.5rem;
padding: 0 0.5rem;
width: 20%;
}
.icon {
flex: 0 0 20px;
height: 20px;
background: red;
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Thumbs_up_font_awesome.svg/512px-Thumbs_up_font_awesome.svg.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
.text {
padding: 0 0.5rem;
}
<div class="container">
<div class="icon"></div>
<div class="text">This is centered.</div>
</div>