Child div absolute position is not relative to parent - css

I am using bootstrap as my CSS framework. My HTML code is as below:
.home-image {
position: relative;
}
.photography {
position: absolute;
}
.image-text_left {
/*display:none;*/
position: absolute;
width: 300px;
top: 200px;
;
left: 200px;
z-index: 100;
font-weight: bold
}
<div class="navbar navbar-static-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">Project name</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active">link 1</li>
<li>link 2</li>
<li>Contact Me</li>
</ul>
</div>
</div>
</div>
</div>
<div class="jumbotron">
<div class="container">
<h1>Hello, world!</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-lg" role="button">Learn more »</a></p>
</div>
</div>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="span7">
<div class="home-image">
<img class="photography" src="http://placehold.it/700x400" />
</div>
<p class="image-text_left">Fashion Photography</p>
<h5>Heading</h5>
</div>
<div class="span5">
<div class="home-image">
<img class="photography" src="http://placehold.it/400x200" />
</div>
<div class="home-image below">
<img class="photography" src="http://placehold.it/400x200" />
</div>
<p class="image-text_right-top">Fashion Photography</p>
<h5>Heading</h5>
</div>
But, as I stated in my question, the class .image-text_left is not absolute relative to the parent class home-image? Rather it is absolute to the window! Why this is happening? What's wrong?

Looks like it's not a child of .home-image to me.
<div class="home-image">
<img class="photography" src="http://placehold.it/700x400" />
</div>
<p class="image-text_left">Fashion Photography</p>

This is your current code: (p class image-text_left is not included in Div home Image)
<div class="home-image">
<img class="photography" src="http://placehold.it/700x400" />
</div>
<p class="image-text_left">Fashion Photography</p>
In this example it is included:
<div class="home-image">
<img class="photography" src="http://placehold.it/700x400" />
<p class="image-text_left">Fashion Photography</p>
</div>
Hope it helps you!
Greetings

Related

bootstrap pull-left and pull-right class not working in angular

so basically im doing this in angular and using bootstrap
I want the name and description on the left and img on the right but it isn't working , pls help
code link is below
here
<div class="row">
<div class="col-xs-12">
<button class='btn btn-success'>New bug</button>
</div>
</div>
<hr>
<div class="row">
<div class="col-xs-12">
<a href="#" class="list-group-item clearfix"
style="background:grey ; color:red;"
*ngFor="let bug of bugs">
<div class="pull-left">
<h4 class="list-group-item-headin">name</h4>
<p class="list-group-item-text">description</p>
<span class="list-group-item-text">type</span>
<span class="list-group-item-text">status</span>
<span class="list-group-item-text">priority</span> </div>
<div class="pull-right">
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3f/Dead-Bug_43215-480x360_%285000576310%29.jpg"
alt="{{bug.name}}"
class="img-responsive"
style="max-height: 100px;">
</div>
</a>
<app-bugs-item></app-bugs-item>
</div>
</div>
I'm guessing you want the text to wrap around the image. If that is the case then only put the float class on the image, and reorder the image to above the text.
<div class="container">
<div class="row">
<div class="col-xs-12">
<button class="btn btn-success">New bug</button>
</div>
</div>
<hr />
<div class="row">
<div class="col-xs-12">
<a href="#" class="list-group-item clearfix" style="background: grey; color: red" *ngFor="let bug of bugs">
<div class="float-right">
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3f/Dead-Bug_43215-480x360_%285000576310%29.jpg" alt="{{bug.name}}" class="img-responsive" style="max-height: 100px" />
</div>
<h4 class="list-group-item-headin">name</h4>
<p class="list-group-item-text">description</p>
<span class="list-group-item-text">type</span>
<span class="list-group-item-text">status</span>
<span class="list-group-item-text">priority</span>
</a>
<app-bugs-item></app-bugs-item>
</div>
</div>
</div>
If you want the text and image to be in 2 columns I would suggest using flexbox
<div class="container">
<div class="row">
<div class="col-xs-12">
<button class="btn btn-success">New bug</button>
</div>
</div>
<hr />
<div class="row">
<div class="col-xs-12">
<a href="#" class="list-group-item d-flex justify-content-between" style="background: grey; color: red" *ngFor="let bug of bugs">
<div>
<h4 class="list-group-item-headin">name</h4>
<p class="list-group-item-text">description</p>
<span class="list-group-item-text">type</span>
<span class="list-group-item-text">status</span>
<span class="list-group-item-text">priority</span>
</div>
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3f/Dead-Bug_43215-480x360_%285000576310%29.jpg" alt="{{bug.name}}" class="img-responsive" style="max-height: 100px" />
</div>
</a>
<app-bugs-item></app-bugs-item>
</div>
</div>
</div>

How to center the object with lightbox using bootsrap?

I use Polo - Responsive Multi-Purpose HTML5 Template.
I can't center my object
I did try many solutions, and nothing work for me still on left side.
See screenshot
<!--Single image lightbox -->
<div class="hr-title hr-long center"><abbr>Single image lightbox</abbr> </div>
<div class="row col-no-margin">
<div class="col-md-4">
<div class="grid-item">
<div class="grid-item-wrap">
<div class="grid-image"> <img alt="Image Lightbox" src="https://via.placeholder.com/300x200" /> </div>
<div class="grid-description">
<a title="Paper Pouch!" data-lightbox="image" href="https://via.placeholder.com/300x200" class="btn btn-light btn-rounded">Zoom</a>
</div>
</div>
</div>
</div>
<!--Single image lightbox -->
<hr class="space">
</div>
Add below CSS to center align the image
img {
margin-left: 50%;
transform: translateX(-50%);
}
<!--Single image lightbox -->
<div class="hr-title hr-long center"><abbr>Single image lightbox</abbr> </div>
<div class="row col-no-margin">
<div class="col-md-4">
<div class="grid-item">
<div class="grid-item-wrap">
<div class="grid-image"> <img alt="Image Lightbox" src="https://via.placeholder.com/600x400" /> </div>
<div class="grid-description">
<a title="Paper Pouch!" data-lightbox="image" href="images/mockup/1.jpg" class="btn btn-light btn-rounded">Zoom</a>
</div>
</div>
</div>
</div>
</div>
<!--Single image lightbox -->
<hr class="space">
This is not the only solution, this is a suggestion :)
You can just use class offset-md-4 combined with text-center and it should work.
Also think about mobile. I have added offset-2 and col-8 to make sure it looks good on small screen too.
img {
max-width: 100%;
margin: auto;
display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="hr-title hr-long center">
<abbr>Single image lightbox</abbr>
</div>
<div class="container">
<div class="row col-no-margin">
<div class="offset-2 col-8 offset-md-4 col-md-4 text-center">
<div class="grid-item">
<div class="grid-item-wrap">
<div class="grid-image"> <img alt="Image Lightbox" src="https://via.placeholder.com/300x200" /></div>
<div class="grid-description">
<a title="Paper Pouch!" data-lightbox="image" href="https://via.placeholder.com/300x200" class="btn btn-light btn-rounded">Zoom</a>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Single image lightbox -->
<hr class="space">
Instead of
<div class="col-md-4">
Do the following:
<div class="col-md-12 text-center">
.text-center is the bootstrap class which will center the image with respect to the column
.col-md-12 will imply there is only 1 column in the entire row

"jumping" content in navbar in bootstrap

Edit2:
Okay, the problem was, that I used a <div class="row"> around the <div class="topimage"> tag. Strange. Could someone explain why it is?
I'm pretty new to bootstrap and created a web page for learning purposes.
Everything is working pretty well so far, except the navbar.
This is my nav code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="headertest ">
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="row">
<div class="col-sm-4 col-sm-offset-1">
<form class="navbar-form navbar-left">
<button class="btn btn-default">ENTDECKEN</button>
<button class="btn btn-default">FINDEN</button>
<button class="btn btn-default">PLANEN</button>
<p class="font">
<b> Zurück zur Hafenseite |</b> <a style="text-decoration: none">Salsbury & Mysteriöses Stonehenge</a>
</p>
</form>
</div>
<div class="col-sm-2 ">
<div class="navbar-form">
<img src="../assets/aida.png" class="logo ">
</div>
</div>
<div class="col-sm-4">
<div class="navbar-form navbar-right">
<form action="#" style>
<div class="dropdown">
<img src="../assets/lupe.png" class="icons" />
<img src="../assets/telefon.png" class="icons" />
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li>Erste Aktion</li>
<li>Zweite Aktion</li>
<li>Noch eine Aktion</li>
<li role="separator" class="divider"></li>
<li>Ein Link</li>
</ul>
</div>
</form>
</div>
</div>
</div>
</div>
</nav>
</div>
The problem is, if I use the navbar-fixed-top class, the content inside the navbar is jumping while I scroll.
Like the top margin is vanishing while I'm scrolling down and if I Scroll up, the margin (or whatever the problem is) just magically appears back.
Normal and scrolling up:
Scrolling down:
I hope you can see what I mean.
Does anybody know what I'm doing wrong?
(my css classes shouldn't be the problem. If I delete them, the content still keep "jumping")
Thank you
Edit:
I have an image as the first item (after the navbar) that seems to cause the problems.
If I delete it, the navbar is working as expected.
Css:
.topimage{
height: 600px;
width: 100%;
align-self: center;
background-image: url("./assets/testbild3.jpg");
background-repeat: no-repeat;
background-size: cover;
z-index: -1;
}
and how I implemented it:
<div class="row">
<headertest></headertest><!-- navbar component -->
</div>
<div class="row ">
<div class="topimage">
</div>
</div>
The fiddler link: (where it works without "jumping" navbar content)
https://jsfiddle.net/Biberium/g52cd6v8/

Title keeps shifting into the navigation bar(Bootstrap)

I have a navigation bar, and I have some text goes in front of the image directly below the nav bar above it.This image is responsive, so it scales depending on the size of the screen. However, when I adjust the screen to its smallest size(i.e the size that it would be if it were on a mobile device) the image stays in one place, but the text that would normally be fixed in front of the image pushes upward, behind the navigation bar. Can you please help explain why this is? Here's my code.
HTML
<header>
<!--Navigation Secton-->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#"> Anna's Portfolio</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="active"> About</li>
<li>Works</li>
<li>Talk To Me</li>
</ul>
</div>
</nav>
</header>
<body>
<!-- Top Image, Title Text-->
<div class="container-fluid">
<div class="row">
<img class="image img img-responsive" src="http://www.qerja.com/journal/wp-content/uploads/CODING.jpg">
<div class="text">
<h1>Anna's Portfolio</h1>
<h2>Come Inside.</h2>
</div>
</div>
</div>
<!--About, Mission-->
<div class="container-fluid">
<div class="row">
<div class="about">
<h2>About Me</h2>
<p>My name is Anna Gibson and I'm a web developer<br> who seeks to tell the stories of the marginalized.<br> I'm a staunch advocate for those who struggle with<br> their mental health and I hope that I can create apps<br> that will help people with their mental health as apps<br> have helped me. </p>
</div>
</div>
</div>
</body>
<footer></footer>
</html>
CSS
.navbar-brand {
position:relative;
bottom:70px;
text-align:right;
}
.image {
position:relative;
width:100%;
padding-top:0;
height:200px;
}
.text {
text-align:center;
position:relative;
bottom:400px;
color:white;
font-family:;
font-size:24px;
}
Thanks so much, if anything is unclear, let me know.
Text pushes behind navbar because of bottom:400px; issue on .text class
You Need Some HTML and CSS Fixes
HTML
<header>
<!--Navigation Secton-->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Anna Portfolio</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li class="active"> About</li>
<li>Works</li>
<li>Talk To Me</li>
</ul>
</div>
</div>
</nav>
</header>
<body>
<!-- Top Image, Title Text-->
<div class="container-fluid">
<div class="row">
<div class="main-section">
<img class="image img img-responsive" src="http://www.qerja.com/journal/wp-content/uploads/CODING.jpg">
<div class="text">
<h1>Anna's Portfolio</h1>
<h2>Come Inside.</h2>
</div>
</div>
</div>
</div>
<!--About, Mission-->
<div class="container-fluid">
<div class="row">
<div class="about">
<h2>About Me</h2>
<p>My name is Anna Gibson and I'm a web developer<br> who seeks to tell the stories of the marginalized.<br> I'm a staunch advocate for those who struggle with<br> their mental health and I hope that I can create apps<br> that will help people with their mental health as apps<br> have helped me. </p>
</div>
</div>
</div>
</body>
CSS
.navbar-brand {
position:relative;
bottom:70px;
text-align:right;
}
.main-section{
position: relative;
}
.image {
position:relative;
width:100%;
padding-top:0;
height:200px;
}
.text {
text-align:center;
position:absolute;
color:white;
font-family:;
font-size:24px;
left:0;
right:0;
top: 0;
bottom: 0;
margin:auto;
}
Link for reference
Hope this Helps..

bootstrap accordion in asp.net toggle doesn't work at all

Sorry but another bootstrap question, but after 1 1/2 days battling this, I hoped that maybe someone can help me with this.
I have an asp.net 4.5 web form with a bootstrap menu, tabs (they work great!)
During a mobile view I wanted to display an accordion instead of the tabs.
I created a new section and followed the code in bootstraps example, and cannot get it to toggle. When I click on a link nothing happens.
I changed one of the accordion sections to accordion-body collapse in, so that one would section would be open, hoping maybe it would work them.
No luck. It is open when first opening, but once you click on another accordion header, the open one closes and nothing will open.
<section class="hidden-desktop visible-tablet visible-phone">
<div id="accordion2" class="accordion">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#acServ">Services
</a>
</div>
<div id="acServ" class="accordion-body collapse in">
<div class="accordion-inner">
<div>
Services
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#acSched">Scheduling
</a>
</div>
<div id="acSched" class="accordion-body collapse">
<div class="accordion-inner">
<div>
Scheduling
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#acClient">Clients
</a>
</div>
<div id="acClient" class="accordion-body collapse">
<div class="accordion-inner">
<div>
Clients
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#acForm">Formulas
</a>
</div>
<div id="acForm" class="accordion-body collapse">
<div class="accordion-inner">
<div>
Formulas
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#acProd">Products
</a>
</div>
<div id="acProd" class="accordion-body collapse">
<div class="accordion-inner">
<div>
Products
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#acAbout">About
</a>
</div>
<div id="acAbout" class="accordion-body collapse">
<div class="accordion-inner">
<div>
About
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#acStart">Get Started
</a>
</div>
<div id="acStart" class="accordion-body collapse">
<div class="accordion-inner">
<div>
Get Started
</div>
</div>
</div>
</div>
</div>
</section>
Anyone have any ideas of what is going on?
Oh yes, the scripts are ordered like...
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
<script src="Scripts/bootstrap-collapse.js"></script>
<script src="Scripts/bootstrap-transition.js"></script>
and the css is like...
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/bootstrap-responsive.min.css" rel="stylesheet" />
<link href="Content/Site.css" rel="stylesheet" />
Site.css is some simple changes, (i.e. Colors) I made to bootstrap.css tabs.

Resources