BootStrap Responsive Background image with text on it is not working - html

I'm getting started with BootStrap 3 and trying to use a background image with text on it. At same time I want it to be reponsive but it seems there is some issue with the way I implemented it. I'm able to get it work for normal desktop but when I try to emulate on a mobile device, text goes outside of background image.
http://jsfiddle.net/cn5guyt4/2/
<div id="front-landing">
<div class="container jumbotron hero-unit">
<h2 class="h1"><span>"Sample Test"</span></h2>
<h3 class="-sub-title">
<span>"Sample Test text 2"</span>
</h3>
</div>
</div>
.hero-unit {
position: relative;
margin-bottom: 0;
margin-top: 15px;
background: url('http://1.bp.blogspot.com/-P5uqUWLgZmA/UtQDdtahipI/AAAAAAAAF3E/IgvARwfxAlw/s1600/seamless-stone-background.jpg') 50% 80% no-repeat;
background-size: 100%;
min-height: 700px;
}
.h1 {
font-size: 2.625em;
font-weight: 700;
letter-spacing: -0.03em;
margin-bottom: 0.571em;
margin-top: 2em;
text-align: center;
}
.-sub-title {
font-weight: 400;
text-align: center;
}
h2 span {
background-color: white;
}
h3 span {
background-color: white;
}
Can someone help me to figure out what am I doing wrong here ?
Thanks

In your hero-unit class, the background-size set to 100% but it should be cover instead. That made a huge difference: see bootply.
I think what you are really trying to do is get the jumbotron of bootstrap to have a background picture. Why is your jsfiddle code different from the code you posted here? there is a wild margin of difference. My fix is using the code above.
Working bootply
<div id="front-landing">
<div class="container jumbotron ">
<h2 class="h1"><span>"Sample Test"</span></h2>
<h3 class="-sub-title">
<span>"Sample Test text 2"</span>
</h3>
</div>
</div>
.h1 {
font-size: 2.625em;
font-weight: 700;
letter-spacing: -0.03em;
margin-bottom: 0.571em;
margin-top: 2em;
text-align: center;
}
.jumbotron{
background-image: url('http://1.bp.blogspot.com/-P5uqUWLgZmA/UtQDdtahipI/AAAAAAAAF3E/IgvARwfxAlw/s1600/seamless-stone-background.jpg');
background-size: cover;
}
.-sub-title {
font-weight: 400;
text-align: center;
}
h2 span {
background-color: white;
}
h3 span {
background-color: white;
}

you can set image as a background-image
.imageAndText img{
width: 100%;
background: no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
for text you can use col-xs-12 or work write individual media query

Related

A href Link automaticaly moves to top left

I started creating a simple page with a background and a link to my homepage. I formated the text with css:
h1{
font-size: 48px;
color: #fff;
margin: 0px;
text-align: center !important;
display: table-cell;
vertical-align: middle;
text-decoration: none;
}
so the text stays in the middle of the page and the page is formated like this:
.box1{
height: 100vh;
width: 100%;
background-image: url(pics/test.jpg);
background-size: cover;
background-position: center;
display: table;
background-attachment: fixed;
}
So the problem is when i use a simple h1 the text stays in the middle but when I set it in a link to my index. It moves to the top left corner like it isnt formated. I assume it doesnt see my css configuration. In html it looks like this:
<div class="box1">
<h1>Test Site</h1>
</div>
Just add the styling from the h1 to a.
a{
font-size: 48px;
color: #fff;
margin: 0px;
text-align: center !important;
display: table-cell;
vertical-align: middle;
text-decoration: none;
}
and html:
<div class="box1">
Homepage
</div>

How to make a CSS class that contains a background image

I want to make a CSS class that will contain a background image around the element that's applied to it, so if I apply it to a paragraph element(p) it will put the image on the element and write the text inside the image, I tried a couple of times but I couldn't find nor create that. This is what I have so far:
.paragraph {
background-image: url("../../res/images/Plate.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
this is how it looks like for me(the top and bottom of the image don't show up):
Code:
body {
background-image: url("https://cdn.discordapp.com/attachments/704268108759695460/708284755820412938/Text-Effect-No1-bkg.png");
background-repeat: no-repeat;
background-size: cover;
}
.title {
font-family: Accuratist, Ariel, serif;
font-style: normal;
color: orange;
font-size: 250%;
text-align: center;
}
.subtitle {
font-family: Accuratist, Airel, serif;
font-style: normal;
color: orange;
font-size: 200%;
text-align: center;
}
.paragraph {
background-image: url("https://cdn.discordapp.com/attachments/704268108759695460/708284745024405504/Text-Effect-No1-Plate.png");
width: 75%;
display: block;
margin: auto;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
font-family: Accuratist, Ariel, serif;
font-style: normal;
color: orange;
font-size: 100%;
text-align: center;
align-self: center;
}
<html>
<head>
<meta charset="ISO-8859-1">
<title>Something</title>
</head>
<body>
<jsp:include page="NavBar.jsp"></jsp:include>
<h1 class="title">Title</h1>
<h2 class="subtitle">Sbtitle</h2>
<br/>
<p class="paragraph"><br/>
Hello World<br/>
The image extends downards whenever I line down.<br/>
But if I write an extrememly long line, the words will get out of the image's boundires and rip it looks really really weird as you can see.<br/>
Also, the top and botton of the image does not show up (I will show you the original image) which is weird considering I used cover on bg size...<br/><br/></p>
</body>
</html>
Note:
Since the images are on my PC so I didn't use the paths in the css here I just put them on discord and used the links lol, but the paths are correct because the images do display soo.. yeah.
Original Image:
If I understood your requirement correctly, is this what you want?
.paragraph {
background-image: url("http://placekitten.com/301/301");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
color:yellow;
font-size:20px;
height:50px; /* this is just to show the image fit-in */
}
<p class="paragraph">
This is paragraph
</p>
What you are looking for is
background-size: 100% 100%;
to strech the image in both directions to fit the div.
Furthermore your image has a transparent border which couses your text to go outside the blue border.
Using backround-size: cover forces the image to be scaled but preserving the aspect ratio, so parts of the image will be cut off, if your element does not match the aspect ratio of the image.
You could use padding or use css instad of the background image. For example somethink like the following. An alternative would also be a border with gradient.
https://jsfiddle.net/1ju5vkyw/
[EDIT]
Explanaition:
before and after are pseudoelements, the browser is creating them automaticaly. So, when you have the following markup:
...
<style>
.test::before{
content: "";
}
.test::after{
content: "";
}
</style>
<div class="test">
<div></div>
</div>
...
it will be something like this:
<div class="test">
<div:before></div:before>
<div></div>
<div:after></div:after>
</div>
You can style before and after like a normal html element and because their position is inside the div you know, where they will be on screen.
To achieve the effect of your image i took a close look at the image. It has 2 colors (2px small border and another border around it) and rounded borders and a box shadow. So i styled before and after as divs with the background colors of the border of your image, make the one 4px bigger then the div (2px on each side) and the other 20px bigger (10px on each side) positioned them relative to the content div and make them apear behinde it. Then the outer one got a box shadow in css and all togehter it looks like your background image.
body {
background-image: url("https://cdn.discordapp.com/attachments/704268108759695460/708284755820412938/Text-Effect-No1-bkg.png");
background-repeat: no-repeat;
background-size: cover;
}
.title {
font-family: Accuratist, Ariel, serif;
font-style: normal;
color: orange;
font-size: 250%;
text-align: center;
}
.subtitle {
font-family: Accuratist, Airel, serif;
font-style: normal;
color: orange;
font-size: 200%;
text-align: center;
}
.paragraph {
width: 75%;
display: block;
margin: auto;
font-family: Accuratist, Ariel, serif;
font-style: normal;
color: orange;
font-size: 100%;
text-align: center;
background-color: #060922;
position: relative;
border-radius: 25px;
padding: 5px;
}
.paragraph::before {
position: absolute;
width: calc(100% + 20px);
height: calc(100% + 20px);
top: -10px;
left: -10px;
background-color: #103454;
content: "";
z-index: -2;
border-radius: 25px;
-webkit-box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 20px 0px rgba(0,0,0,0.75);
}
.paragraph::after {
position: absolute;
width: calc(100% + 4px);
height: calc(100% + 4px);
top: -2px;
left: -2px;
background-color: #294F6C;
content: "";
z-index: -1;
border-radius: 25px;
}
<html>
<head>
<meta charset="ISO-8859-1">
<title>Something</title>
</head>
<body>
<jsp:include page="NavBar.jsp"></jsp:include>
<h1 class="title">Title</h1>
<h2 class="subtitle">Sbtitle</h2>
<br/>
<p class="paragraph"><br/>
Hello World<br/>
The image extends downards whenever I line down.<br/>
But if I write an extrememly long line, the words will get out of the image's boundires and rip it looks really really weird as you can see.<br/>
Also, the top and botton of the image does not show up (I will show you the original image) which is weird considering I used cover on bg size...<br/><br/></p>
</body>
</html>
Normally I do that putting the paragraph inside one div
<div id class="background-image" >
<p> Paragraph about things and Hello world's </p>
</div>
<style>
.background-image{
background-image: url("../../res/images/Plate.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
other way is using the
.background-image {
display:block;
background-image: url("");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding:2rem;
height:200px;
width: 100%;
}
confirm if the path is correct ../../res/images/Plate.png, try copy the image to the css folder only to see if u can link it correctly

How to stack two header tags instead of side by side

The current header tags are side by side and I'm trying to get the second header tag to sit underneath the first.
I currently have h1 and h2 tags. I have tried putting it all into an h1 tag and using span, however, the styling on span does not take well when sizing and aligning. I am trying to have it centered on the screen and have the subtitle directly underneath of the title, centered by the middle, not left aligned and next to it.
header {
width: 100%;
height: 100vh;
background-image: url("underneath.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.wrapper {
padding-top: 15%;
color: rgb(240, 240, 240);
display: flex;
align-items: center;
justify-content: center;
}
.name {
font-size: 6em;
display: inline;
}
.subtitle {
display: inline;
}
<header>
<div class="wrapper">
<h1 class="name">Answer 42</h1>
<h2 class="subtitle">Customer Acquistions</h2>
</div>
</header>
I am trying to create a title for the page with a subtitle underneath of it and have it centered above a background image I put in CSS. My current code has the the header tags side by side.
I hope this simple solution will help you.
header {
width: 100%;
height: 100vh;
background-image: url("underneath.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.wrapper {
padding-top: 15%;
color: rgb(240, 240, 240);
}
.name {
font-size: 6em;
margin-bottom: 0;
line-height: 1em;
text-align: center;
}
.subtitle {
text-align: center;
margin-top: 0;
}
<header>
<div class="wrapper">
<h1 class="name">Answer 42</h1>
<h2 class="subtitle">Customer Acquistions</h2>
</div>
</header>

text over flowing edge even when it is responsive

I have made my text responsive and it is working in most pages but on my homepage it overflows the edge when the window is resized.
h12 {
width: 120%;
display: block;
padding-top: 40px;
padding-bottom: 30px;
padding-left: 15%;
padding-right: 5%;
font-weight: 700;
color: #ffffff;
text-align: center;
font-size: 20px;
color: #a7ad8d;
-webkit-font-smoothing: antialiased;
-webkit-overflow-scrolling: touch;
position: relative;
overflow: auto;
}
h9 {
display:block;
text-align: left;
font-family: a;
color: #ffffff;
font-size: 14px;
margin-top: 20px;
-webkit-font-smoothing: antialiased;
-webkit-overflow-scrolling: touch;
}
#headerwrap {
background: url(../img/back.jpg) no-repeat center top;
margin-top: -70px;
padding-top: 250px;
text-align: left;
background-attachment: relative;
background-position: center center;
min-height: 650px;
min-width: 200px;
width: 100%;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#headerwrap h9 {
padding-left: 5%;
padding-right: 84%;
width: 1200px;
text-align: left;
padding-top: 5px;
font-weight: 400;
color: #ffffff;
-webkit-font-smoothing: antialiased;
-webkit-overflow-scrolling: touch;
float: none;
margin-left: auto;
margin-right: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="headerwrap">
<div class="container">
<div class="row">
<div class="col-lg-6 col-lg-offset-2">
<h12>WE ALIGN PROFESSIONAL FIRMS TO ACHIEVE THEIR GREATEST VALUE</h12>
<h9> Worthmore provides the focus, structure, accountability and support so leaders can take their firm to continuous improvement and growth.</h9>
<h9> Our leadership and experience in Accounting & Financial Services, and in significant senior corporate roles, provides a breadth of knowledge that can be applied to a multitude of business environments and situations.
We add value by asking the questions that need to be asked, and providing insights and input into the decision-making process.</h9>
</div>
</div>
</div>
</div>
for body set overflow:hidden; css: body{ overflow:hidden}
Remove width from following:
headerwrap h9
And from h12
By adding those unwanted width (120% and 1200px) you are going out of content area and hence getting horizontal scroll.
Is this RWD website you creating? then please read this:
https://www.smashingmagazine.com/2011/01/guidelines-for-responsive-web-design/
to fully understand RWD (Responsive Web Design)
In responsive design, do not using fixed Width value.
i found you using
#headerwrap h9 {width: 1200px;} this will make your website not responsive
try usng % Value #headerwrap h9 {width: 100%;}

CSS Background Style Not Applying?

I have started styling for my new websites navigation bar however my background color isn't working for it or any other Divs that I use, Div IDs are not being picked up either. My whole style seems to be messing up and this has never happened before.
Here is the code:
<div class="bar">
<img src="/img/NavBar/Logo.png">
Link 1
Link 2
Link 3
Link 4
Link 5
</div>
CSS:
body{
margin: 0;
padding: 0;
font-family: 'PT Sans', sans-serif;
font-size: 14px;
background:url("/img/Global/Background.jpg");
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
//*NAV BAR*//
.bar {
background-color: #0F0F0F;
width: 100%;
height: 70px;
opacity: 0.7;
filter: alpha(opacity=70); /* For IE8 and earlier */
}
.bar a {
padding-left: 40px;
padding-right: 40px;
text-decoration: none;
font-size: 20px;
color: #FFFFFF;
float: right;
margin-top: 20px;
}
.bar img {
margin-top: 10px;
margin-left: 20px;
}
The CSS is connected because my background image is showing, however background colours are not showing. I have tried different colours to make sure that it's not just poor contrast between the background image and the colour itself as well.
Anyone have any ideas as to what is wrong here?
The culprit is the //*NAV BAR*// comment. // isn't valid CSS comment syntax. It makes your whole CSS file invalid. Replace it with /*NAV BAR*/