Align absolutely positioned div within - html

I have a wrapper div (#main-wrapper), and a div centered horizontally inside (#image). It contains a big image.
I'd like to have a div overlaying #image in the bottom-right corner (#thumbs).
Here's what I have:
<div id="main-wrapper">
<div id="image">
<img src="img.jpg" />
</div>
<div id="thumbs">
Link 1
Link 2
Link 3
</div>
</div>
div#main-wrapper
{
width: 100%;
background-color: #000000;
position: relative;
}
div#main-wrapper div#image
{
margin: 0 auto;
width: 800px;
height: 600px;
background-color: #1D9DDD;
}
div#main-wrapper div#thumbs
{
position: absolute;
width: 600px;
height: 400px;
background-color: #FF212C;
bottom: 0;
right: 0;
}
The problem is that #thumbs goes to the bottom-right of #main-wrapper, and not the center of the centered div.
You can see what I'm doing here: http://jsfiddle.net/22NnS/1/

If I'm understanding correctly then this will work. Put the thumbs div within the image container like so:
<div id="main-wrapper">
<div id="image">
<img src="img.jpg" />
<div id="thumbs">
Link 1
Link 2
Link 3
</div>
</div>
</div>
And then change where the position:relative is defined:
div#main-wrapper
{
width: 100%;
background-color: #000000;
}
div#main-wrapper div#image
{
margin: 0 auto;
width: 800px;
height: 600px;
background-color: #1D9DDD;
position: relative;
}
div#main-wrapper div#thumbs
{
position: absolute;
width: 600px;
height: 400px;
background-color: #FF212C;
bottom: 0;
right: 0;
}

Related

Multiple divs on top multiple images

How to make multiple images with a tag name as a link on top of each one?
I can make only one image with a tag name on top of the image, but not other ones. Somehow when I copy the whole div (contains the img and the tag's div), it doesn't show the tags on other images.
I've tried: position: relative for the parent div, position: absolute for the tag (child div), make the image float: left.
I've also tried to "stick" the child div with its parent.
I've tried adding div and class for each item: image, image container, tag, a tag...
.container {
position: relative;
width: 400px;
height: 400px;
}
.container img {
width: 100%;
/*I've tried with px, doesn't make a difference*/
float: left;
/*I've also tried adding a class for img and position: absolute*/
}
.nameTag {
width: 100%;
height: 50px;
position: absolute;
background-color: gray;
}
.nameText {
color: white;
}
<div class="container">
<img src="assets/images/img1.png" />
<div class="nameTag">Mobile App</div>
</div>
<div class="container">
<img src="assets/images/img2.png" />
<div class="nameTag">Mobile App</div>
</div>
<div class="container">
<img src="assets/images/img3.png" />
<div class="nameTag">Mobile App</div>
</div>
Not sure if this is exactly what you are looking for but this is what I've changed in your CSS:
.container {
position: relative;
display: inline-block; //allowed images to float
width: 400px;
height: 400px;
}
.nameTag {
width: 100%;
height: 50px;
position: absolute;
background-color: gray;
top: 100px; //positioned about half way down the image
text-align: center; //center the link text
}
Here is a link to the CodePen for you to view. Let me know!
Try changing your float to "none" or copy/paste this into your html/css files.
Hope this helps.
.container {
position: relative;
width: 400px;
height: 400px;
}
.container img {
width: 100%;
/*I've tried with px, doesn't make a difference*/
float: none;
/*I've also tried adding a class for img and position: absolute*/
}
/* ^^^ Change float to "none"...seems to work here */
.nameTag {
width: 100%;
height: 50px;
position: relative;
background-color: gray;
}
.nameText {
color: white;
}
<div class="container">
<div class="nameTag">Mobile App</div>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRlUiyrmhTXFppqk4aYzqTOU9nimCQsYibukwAV8rstsDkAVQT-mA" />
</div>
<div class="container">
<div class="nameTag">Mobile App</div>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRlUiyrmhTXFppqk4aYzqTOU9nimCQsYibukwAV8rstsDkAVQT-mA" />
</div>
<div class="container">
<div class="nameTag">Mobile App</div>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRlUiyrmhTXFppqk4aYzqTOU9nimCQsYibukwAV8rstsDkAVQT-mA" />
</div>

Div Overlapping With Another Div With image

I create a menubar and make it transparent and I add an image in my container div to look image behind menubar after this when I create another div it overlapping each other I want second div visible below container div
* {
margin: 0;
padding: 0;
}
.top_nav {
height: 80px;
width: 100%;
background: rgba(0, 0, 0, .5);
position: relative;
}
.container {
height: 638px;
width: 100%;
max-width: 100%;
position: absolute;
overflow: hidden;
background-position: center;
top: 0;
z-index: -1;
}
.container img {
width: 100%;
height: 638px;
}
.details {
height: 638px;
width: 100%;
position: absolute;
}
<header>
<div class="top_nav"></div>
</header>
<div class="container">
<img src="http://www.100resilientcities.org/page/-/100rc/img/blog/rsz_resilientcity_headphoto.jpg">
<div id="short-des"></div>
</div>
<div class="details"></div>
I want div name detail to show below the container div image
enter image description here
don't use position:absolute on container , but use it on header . so header will stay on top of the container , and details will stay under container
see snippet below or fiddle > jsfiddle
let me know if it helps
*{
margin: 0;
padding: 0;
}
header {
position:absolute;
z-index:100;
width:100%;
height:80px
}
.top_nav{
height: 80px;
width: 100%;
background: rgba(0,0,0,.5);
position: relative;
}
.container{
height: 638px;
width: 100%;
max-width: 100%;
overflow: hidden;
background-position: center;
top: 0;
z-index: -1;
}
.container img{
width: 100%;
height: 638px;
}
.details{
height: 638px;
width: 100%;
position: absolute;
background:red;
}
<header>
<div class="top_nav">
</div>
</header>
<div class="container">
<img src="http://placehold.it/350x150">
<div id="short-des">
</div>
</div>
<div class="details">
</div>

How to position an image to the right of a center aligned title with HTML & CSS

I'm working on a HTML page, and I've run into a little problem. Here's a picture about what I want: https://i.imgsafe.org/2c4d808.png
I've got a header section which contains the title and the picture, but I can't move the picture into the right side (red area) of the header.
I need to meet these conditions:
The title and the picture must be in the same div (header), however I can use nested divs in the header.
The title must be centered.
The picture must be completely on the right side of the header (both have a height of 100px).
The header is 800x100 px and the picture is 160x100 px.
I can modify anything in my HTML or CSS code.
Just to be clear: The header is with the "TITLE TITLE TITLE TITLE" and it is blue.
#container{
width: 800px;
height: auto;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
padding: 10px;
background-color: #cccccc;
box-shadow: 0px 0px 20px black;
}
#header{
height: 100px;
background-color: #6495ED;
}
#menu{
width: 150px;
height: 400px;
background-color: #FFD700;
float: left;
}
#main{
width: 650px;
height: 400px;
background-color: #00FF00;
float: right;
}
#footer{
height: 80px;
clear: both;
background-color: #6495ED;
}
#footerwords{
float: right;
}
#headerpics{
positioning: absolute;
top: 0px;
}
ul{
font-size: 1.5em;
font-family: arial;
}
<div id="container">
<div id="header">
<h1><center>TITLE TITLE TITLE TITLE</center><h1>
<div id = "headerpics">
<img src="http://placehold.it/160x100/E8117F/ffffff/?text=Books" />
</div>
</div>
<div id = "main">xx t xx </div>
<div id = "menu">
<ul>
<li>1111111</li>
<li>2222222</li>
<li>33333333</li>
<li>4444444</li>
<li>5555555</li>
</ul>
</div>
<div id = "footer">
<div id = "footerwords">
<strong></br>footer........<strong>
</div>
</div>
</div>
give the <div> that holds the text/img a position: relative;
then give the <img> a position: absolute; top: 0; right: 0;
h1 {
text-align: center;
}
.masthead {
position: relative;
height:139px;
background-color: #9cc;
}
.masthead-img {
position: absolute;
right: 0;
top: 0;
}
<div class="masthead">
<h1>This is My Title</h1>
<img src="http://placekitten.com.s3.amazonaws.com/homepage-samples/200/139.jpg" alt="" class="masthead-img" />
</div>

Css conflict extended width

Having a hard time figuring out where and i need to use to avoid over extend of width to right causing the scroll to right appear and the height of the small images gets smaller. it should be 250px in height each to fit. Plus i need to add text in the bottom left of each image.
This is the picture for reference. Click here
HTML
<div class="news-banner">
<h1 class="text-center header-text">News</h1>
</div>
<div class="row">
<div class="col-md-8 img-container">
<img class="img-responsive" src="/assets/icons/people-crowd-child-kid-large.jpg">
</div>
<div class="col-md-4 img-small">
<img class="img-responsive" src="/assets/icons/13-Cuidados-alternativos-en-familia.jpg">
<img class="img-responsive" src="/assets/icons/man-person-cute-young-large.jpg">
</div>
CSS
.news-banner {
height: 120px;
background: #eb1212;
position: relative;
border-bottom: 2px solid white;
}
.header-text{
color: white;
width: 50%;
height: 50%;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
}
.img-container {
height: 500px;
display: flex;
}
.img-small {
height: 100%;
}
Solution for both the points
It should be 250px in height each to fit.
Plus I need to add text in the bottom left of each image.
Adding img-wrapper class to your div with class row, and with some additional css rules, Here is the demo. View it in Full Page Mode
.news-banner {
height: 120px;
background: #eb1212;
position: relative;
border-bottom: 2px solid white;
}
.header-text {
color: white;
width: 50%;
height: 50%;
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.img-container {
height: 100%;
display: flex;
}
.img-small {
height: 100%;
}
.img-small div {
height: 50%;
}
.img-small img {
height: 100%;
}
.img-wrapper {
height: 500px;
}
span.img-desc {
color: white;
bottom: 5px;
left: 30px;
font-size: 20px;
position: absolute;
}
.img-wrapper.row div[class|='col-md'] {
padding: 0px;
}
html {
overflow-x: hidden;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="news-banner">
<h1 class="text-center header-text">News</h1>
</div>
<div class="row img-wrapper">
<div class="col-md-8 img-container">
<img class="img-responsive" src="http://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
<span class="img-desc"> This Image Description </span>
</div>
<div class="col-md-4 img-small">
<div class="col-md-12">
<img class="img-responsive" src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg">
<span class="img-desc"> This Image Description </span>
</div>
<div class="col-md-12">
<img class="img-responsive" src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg">
<span class="img-desc"> This Image Description </span>
</div>
</div>
</div>
Fix
Dont really know of the side effects of Bootstrap with your other code. But you can try this, too. It worked for me with Bootstrap.
html {
width: 100%;
overflow-x: hidden;
}
See https://jsfiddle.net/bzLo33n8/ for the working example.

How to position text over an image with CSS

How do I center a text over an image in css?
<div class="image">
<img src="sample.png"/>
<div class="text">
<h2>Some text</h2>
</div>
</div>
I want to do something like the one below but I'm having difficulties, here's my current css
<style>
.image {
position: relative;
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
margin: 0 auto;
width: 300px;
height: 50px;
}
</style>
When I use background-image I do not get any output from html2pdf:
<style>
#image_container{
width: 1000px;
height: 700px;
background-image:url('switch.png');
}
</style>
Print
<?php ob_start(); ?>
<div id="image_container"></div>
<?php
$_SESSION['sess'] = ob_get_contents();
ob_flush();
?>
Here's prints.php:
<?php require_once('html2pdf/html2pdf.class.php'); ?>
<?php
$html2pdf = new HTML2PDF('L', 'A4', 'en');
$html2pdf->writeHTML($_SESSION['sess']);
$html2pdf->Output('random.pdf');
?>
How about something like this: http://jsfiddle.net/EgLKV/3/
Its done by using position:absolute and z-index to place the text over the image.
#container {
height: 400px;
width: 400px;
position: relative;
}
#image {
position: absolute;
left: 0;
top: 0;
}
#text {
z-index: 100;
position: absolute;
color: white;
font-size: 24px;
font-weight: bold;
left: 150px;
top: 350px;
}
<div id="container">
<img id="image" src="http://www.noao.edu/image_gallery/images/d4/androa.jpg" />
<p id="text">
Hello World!
</p>
</div>
This is another method for working with Responsive sizes. It will keep your text centered and maintain its position within its parent. If you don't want it centered then it's even easier, just work with the absolute parameters. Keep in mind the main container is using display: inline-block. There are many others ways to do this, depending on what you're working on.
Based off of Centering the Unknown
Working codepen example here
HTML
<div class="containerBox">
<div class="text-box">
<h4>Your Text is responsive and centered</h4>
</div>
<img class="img-responsive" src="http://placehold.it/900x100"/>
</div>
CSS
.containerBox {
position: relative;
display: inline-block;
}
.text-box {
position: absolute;
height: 100%;
text-align: center;
width: 100%;
}
.text-box:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}
h4 {
display: inline-block;
font-size: 20px; /*or whatever you want*/
color: #FFF;
}
img {
display: block;
max-width: 100%;
height: auto;
}
Why not set sample.png as background image of text or h2 css class? This will give effect as you have written over an image.
For a responsive design it is good to use a container having a relative layout and content (placed in container) having fixed layout as.
CSS Styles:
/*Centering element in a base container*/
.contianer-relative{
position: relative;
}
.content-center-text-absolute{
position: absolute;
text-align: center;
width: 100%;
height: 0%;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 51;
}
HTML code:
<!-- Have used ionic classes -->
<div class="row">
<div class="col remove-padding contianer-relative"><!-- container with position relative -->
<div class="item item-image clear-border" ><img ng-src="img/engg-manl.png" alt="ENGINEERING MANUAL" title="ENGINEERING MANUAL" ></div> <!-- Image intended to work as a background -->
<h4 class="content-center-text-absolute white-text"><strong>ENGINEERING <br> MANUALS</strong></h4><!-- content div with position fixed -->
</div>
<div class="col remove-padding contianer-relative"><!-- container with position relative -->
<div class="item item-image clear-border"><img ng-src="img/contract-directory.png" alt="CONTRACTOR DIRECTORY" title="CONTRACTOR DIRECTORY"></div><!-- Image intended to work as a background -->
<h4 class="content-center-text-absolute white-text"><strong>CONTRACTOR <br> DIRECTORY</strong></h4><!-- content div with position fixed -->
</div>
</div>
For IONIC Grid layout, evenly spaced grid elements and the classes used in above HTML, please refer - Grid: Evenly Spaced Columns. Hope it helps you out... :)
as Harry Joy points out, set the image as the div's background and then, if you only have one line of text you can set the line-height of the text to be the same as the div height and this will place your text in the center of the div.
If you have more than one line you'll want to set the display to be table-cell and vertical-alignment to middle.
as of 2017 this is more responsive and worked for me.
This is for putting text inside vs over, like a badge.
instead of the number 8, I had a variable to pull data from a database.
this code started with Kailas's answer up above
https://jsfiddle.net/jim54729/memmu2wb/3/
.containerBox {
position: relative;
display: inline-block;
}
.text-box {
position: absolute;
height: 30%;
text-align: center;
width: 100%;
margin: auto;
top: 0;
bottom: 0;
right: 0;
left: 0;
font-size: 30px;
}
.img-responsive {
display: block;
max-width: 100%;
height: 120px;
margin: auto;
padding: auto;
}
.dataNumber {
margin-top: auto;
}
<div class="containerBox">
<img class="img-responsive" src="https://s20.postimg.org/huun8e6fh/Gold_Ring.png">
<div class='text-box'>
<p class='dataNumber'> 8 </p>
</div>
</div>
A small and short way of doing the same:
.image {
position: relative;
margin-bottom: 20px;
width: 100%;
height: 300px;
color: white;
background: url('https://via.placeholder.com/600') no-repeat;
background-size: 250px 250px;
}
<div class="image">
<p>
<h3>Heading 3</h3>
<h5>Heading 5</h5>
</p>
</div>
Quick solution: Set position: relative; on the container element and set position: absolute; on child elements in that container element, with the necessary top, left, bottom, right-adjusting parameters:
.top-left {
position: absolute;
top: 2px;
left: 2px;
}
.bottom-right {
position: absolute;
bottom: 2px;
right: 2px;
}
.container {
position: relative;
text-align: center;
color: white;
float:left;color: white;
text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}
<div class="container" style="">
<img src="https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2#2x.png" width="100">
<div class="top-left">Wikipedia</div>
<div class="bottom-right">Everyone's Encyclopedia</div>
</div>
Center it directly in the middle with the following CSS...
top: 50%;
left: 50%;
transform: translate(-50%, -50%);