How can I position my div next to the some text? - html

Using Bootstrap3, I'm trying to position my div beside some text.
CODE:
<h1>Text</h1>
<div style="position: relative; display: inline-block">
<div style="width: 40px; position: absolute">
<div style="padding-top: 100%;overflow: hidden; background-color: darkblue;">
</div>
</div>
<div style="width: 30px; position: absolute">
<div style="padding-top: 100%; overflow: hidden; background-color: #f8ff15;">
</div>
</div>
</div>
codepen: https://codepen.io/anon/pen/ddORed
I just want to use this div like a span icon.
So moreover, I wonder how to make my div's height be responsive to the height of text or text typhograpy .
How to do it?

Just put that DIV - but better as a SPAN - (which you already correctly defined as an inline-block) INTO the h1 tag (BTW: no h1 inside p!) and add vertical-align:top;, so it aligns with the upper border of the text line:
<h1>Text
<span style="position: relative; display: inline-block;vertical-align:top;">
<div style="width: 40px; position: absolute">
<div style="padding-top: 100%;overflow: hidden; background-color: darkblue;">
</div>
</div>
<div style="width: 30px; position: absolute">
<div style="padding-top: 100%; overflow: hidden; background-color: #f8ff15;">
</div>
</div>
</span>
</h1>
https://codepen.io/anon/pen/yvVogM

Not exactly sure what you want to do by you can do this by using linear-gradient as background and no need to use all this markup:
h1 {
display: inline-block;
padding-right: 50px;
background:
linear-gradient(to right, #f8ff15, #f8ff15) calc(100% - 10px) 0/ 30px calc(100% - 10px) no-repeat,
linear-gradient(to right, darkblue, darkblue) 100% 0/ 40px 100% no-repeat;
}
<h1>Text</h1>
<br>
<h1>another<br> text</h1>

You can just move your divs before you text and set the position to absolute.
https://codepen.io/anon/pen/MQboRj
<div style="position: absolute; display: inline-block">
<div style="width: 40px; position: absolute">
<div style="padding-top: 100%;overflow: hidden; background-color: darkblue;">
</div>
</div>
<div style="width: 30px; position: absolute">
<div style="padding-top: 100%; overflow: hidden; background-color: #f8ff15;">
</div>
</div>
</div><h1 style="padding-left:50px;">Here is what I want to position my blue and yellow square. And also I hope my square's height be equal to Text's height</h1></div>

Related

logo in the middle of the two sections

I have a problem, I don't want the image / logo to belong to a certain section, but rather to place it in the middle of the two sections, how can I do that?
<body>
<section class="parent" style="height: 400px; background-color: blue">
<div class="boxparent" style=" top: 10px;">
</div>
</section>
<img src="https://place-hold.it/100x100.jpg/666/fff/000" style="position: absolute;background-color: #254543;z-index: 1; left: 25%; ">
<section class="parent" style="height: 400px; background-color: yellow;">
<div class="boxparent">
</div>
</section>
</body>
A more accurate method to bring it to the exact center. Wrap both of your parent sections inside a wrapper so that the absolute image can be relative to the wrapper. This fixes the image to be inside the wrapper always. Then for the img you can use calc to calculate the left and top positions of the image. With this, the image will be at the 50% distance from both top and left to align it to center. - 50px is here because the width of the given image is 100x100 which means you need to deduct 50px from both top and left to align it to the exact center.
Checkout the snippet below.
.parent-wrapper {
position: relative;
}
img {
position: absolute;
background-color: red;
z-index: 1;
left: calc(50% - 50px);
top: calc(50% - 50px);
}
.parent-a {
height: 100px;
background-color: blue;
}
.parent-b {
height: 100px;
background-color: yellow;
}
<body>
<div class="parent-wrapper">
<section class="parent-a"></section>
<img src="https://place-hold.it/100x100.jpg/666/fff/000">
<section class="parent-b"></section>
</div>
</body>
Enjoy :)
If you want vertically center of both section
top: 350px; // Since 400px is height of first section and 100px of image (400 - 50)px
if you also want horizontally and vertically center of both section
left: 50%;
transform: translate(-50%);
img {
position: absolute;
top: 350px;
left: 50%;
transform: translate(-50%);
}
<section class="parent" style="height: 400px; background-color: blue">
<div class="boxparent" style=" top: 10px;">
</div>
</section>
<img src="https://place-hold.it/100x100.jpg/666/fff/000" style="position: absolute;background-color: #254543;z-index: 1;">
<section class="parent" style="height: 400px; background-color: yellow;">
<div class="boxparent">
</div>
</section>
You can simply place your image in upper section then apply just few css styles to to your image. I recommend to use external stylesheet for styling. However you are using inline styles then do it as follows;
<body>
<section class="parent" style="height: 400px; background-color: blue">
<div class="boxparent" style=" top: 10px;">
</div>
<img src="https://place-hold.it/100x100.jpg/666/fff/000" style="background-color: #254543; position: relative;top: 350px;left: 45%;">
</section>
<section class="parent" style="height: 400px; background-color: yellow;">
<div class="boxparent">
</div>
</section>

how to stylize 3 divs to fit relatively on 100% window size

I am facing a problem in placing divs relatively with each other. I placed them 3 in a row and 3 in each column (the first column is 140px, 2nd is 320px and 3rd is 500px from the left) with each other by pixel formatting in 100% window size but it needs scrolling to see them in any other window size. I want it to arrange themselves accordingly as the window size changes. The code I wrote is given as follows
#box1 {
color: white;
background-color: #ac536f;
position: relative;
display: inline-block;
width: 210px;
height: 162px;
left: 140px;
}
#box2 {
color: white;
background-color: #ac536f;
position: relative;
display: inline-block;
width: 210px;
height: 162px;
left: 320px;
}
#box3 {
color: white;
background-color: #ac536f;
position: relative;
display: inline-block;
width: 210px;
height: 162px;
left: 500px;
}
<div id="box1">
<img src="thumbnail1.jpg" />DIV1
</div>
<div id="box2">
<img src="thumbnail2.jpg" />DIV2
</div>
<div id="box3">
<img src="thumbnail3.jpg" />DIV3
</div>
<br/><br/>
<div id="box1">
<img src="thumbnail4.jpg" />DIV4
</div>
<div id="box2">
<img src="thumbnail5.jpg" />DIV5
</div>
<div id="box3">
<img src="thumbnail6.png" />DIV6
</div>
<br/><br/>
<div id="box1">
<img src="thumbnail7.jpeg" />DIV7
</div>
<div id="box2">
<img src="thumbnail8.png" />DIV8
</div>
<div id="box3">
<img src="thumbnail9.png" />DIV9
</div>
<br/><br/>
• You should read up on flex-box. The flex-box does the layout for you and sorts out any kind of wrapping.
• You should never use <br/> if you want to do the page responsive. Let the CSS take care of any row wrapping.
• Using id is just for unique objects. Use CSS classes instead if you want to apply the same CSS to several elements.
I made the boxes 60x60px to easier display the wrapping on smaller devices.
.box-container {
display: flex;
flex-wrap: wrap;
}
a.box {
width: 60px;
height: 60px;
margin-left: 140px;
margin-bottom: 20px;
color: white;
background-color: #ac536f;
}
<div class="box-container">
<a class="box" href="https://www.youtube.com/watch?v=OUksMAlXQ9w"><img src="thumbnail1.jpg" />DIV1</a>
<a class="box" href="https://www.youtube.com/watch?v=5hEMAPoW3B8"><img src="thumbnail2.jpg" />DIV2</a>
<a class="box" href="https://www.youtube.com/watch?v=iINlkySuCDI"><img src="thumbnail3.jpg" />DIV3</a>
<a class="box" href="https://www.youtube.com/watch?v=zXB5jeceKic"><img src="thumbnail4.jpg" />DIV4</a>
<a class="box" href="https://www.youtube.com/watch?v=tK4pTRySWCM"><img src="thumbnail5.jpg" />DIV5</a>
<a class="box" href="https://www.youtube.com/watch?v=tdH68x36Vxc"><img src="thumbnail6.png" />DIV6</a>
<a class="box" href="https://www.youtube.com/watch?v=_al3HCUNrKo"><img src="thumbnail7.jpeg" />DIV7</a>
<a class="box" href="https://www.youtube.com/watch?v=ua5rZXKj4q0&t=27s"><img src="thumbnail8.png" />DIV8</a>
<a class="box" href="https://www.youtube.com/watch?v=M6PgE_igVz8"><img src="thumbnail9.png" />DIV9</a>
</div>
You can set the height to :
height: 30vh;
That means you set the height to 30% of the screen what the user sees

Centering div content within multiple nested divs

I am trying to center some so that they are displayed within the center, however the tricky part is the html is within a number of (part of the html is static, and part of it is dynamic from a database).
See the screenshot as an example of how it currently looks (I want this content in the centre)
http://postimg.org/image/5fc6ecgy7/
note - the site is using the base 960 grid system
Below is the HTML:
<div class="">
<div class="">
<div class="">
<div id="national-prize-feed" class="panel-wrapper ">
<div class="border">
<div class="content clearfix add-radius">
<div style="padding:10px 0px;">
<div id="nation-prizes-collection" class="clearfix">
<div class="summary"></div>
<div class="">
<div class="national-prizes">
<div class="prizes">
<img class="prizes-img" alt="iPod Shuffle" src="/images/prizes/ipod-shuffle.png">
</div>
</div>
<div class="national-prizes">
<div class="prizes">
<img class="prizes-img" alt="Football" src="/images/prizes/football.png">
</div>
</div>
</div>
<div class="keys" title="/pages/index/slug/prizes" style="display:none">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
My specific css (there is a lot more.. it is based on a grid based layout)
div.prizes {
float: left;
}
div.prizes img {
width: 280px;
}
.prizes-img {
padding: 0 7px 0 7px;
margin: 7px 5px 7px 5px;
max-width: 100%;
height: auto;
}
In order to position a DIV to the center of a screen, you need to set a static width of the div to be centered, left: 0px, right: 0px, and the respective margins to auto.
Here is an example: http://jsfiddle.net/pR4hq/
<style>.center{
position: relative;
display: block;
width: 120px;
background: rgb(90,90,90);
left: 0px;
right: 0px;
margin-left: auto;
margin-right: auto;
text-align: center;
}</style>
<div class="center">Center Content</div>

Put a div on top of a googlemap?

Is there a plugin to do this or method to do this?
See, I have this site and if you scroll to the bottom, you'll see a map. What I want to do is to place a small box on top of the map, just like an overlay that will contain contact information.
Edit: Box will be on top of the watery part. :)
You can try this:
<div class="section" id="contact">
<div style="width:100px; height:200px; background:#ccc;z-index:999999;position:absolute;">test</div>
</div>
Add a div after your section div as my above code...and position set as you want from top and left..(eg: Add this - top:"you need"; left:"you need";)
Good luck
Something like this (without using inline styles obviously):
<div id="googleMapContainer" style="height: 400px; position: relative;">
<div id="overlay" style="height: 300px; width: 25%; max-width: 340px; position: absolute; top: 50px; left: 0px; background-color: rgba(0, 0, 0, 0.7); box-sizing: border-box; padding: 20px; color: #ffffff;">
<p><a style="color: #f1f1f1;">Here's a link in your overlay</a></p>
</div>
<div class="google_map" id="map_canvas" style="width: 100%; height: 400px; margin: 0;"></div>
</div>

How to I get a div that shows on hover, not to push content down on the page?

I have created the following
http://jsfiddle.net/fcW66/1/
CSS
.div_wrapper {
float: left;
width: 100px;
background: 3333;
margin: 15px;
background: #cacaca;
z-index: 1;
}
.div_two {
display: none;
height: 120px;
background: #444;
z-index: 999;
}
.div_one:hover .div_two {
display: block;
}
HTML
<div class="div_wrapper">
<div class="div_one">
<img src="#" style="width: 100px; height: 100px;">
<div class="div_two">description</div>
</div>
</div>
<div class="div_wrapper">
<div class="div_one">
<img src="#" style="width: 100px; height: 100px;">
<div class="div_two">description</div>
</div>
</div>
<div class="div_wrapper">
<div class="div_one">
<img src="#" style="width: 100px; height: 100px;">
<div class="div_two">description</div>
</div>
</div>
<br style="clear:both;" />
<div class="div_wrapper">
<div class="div_one">
<img src="#" style="width: 100px; height: 100px;">
<div class="div_two">description</div>
</div>
</div>
<div class="div_wrapper">
<div class="div_one">
<img src="#" style="width: 100px; height: 100px;">
<div class="div_two">description</div>
</div>
</div>
<div class="div_wrapper">
<div class="div_one">
<img src="#" style="width: 100px; height: 100px;">
<div class="div_two">description</div>
</div>
</div>
When you hover over it shows the description, but it pushes the other divs further. I have tried giving the div_wrapper a fixed width, which fixes that problem but when the div2 appears it shows under the next div that is under it. I tried adding a z-index and it did not change anything. I need the div_two to show over the top of the divs that are below it and not change the layout.
If you want white-space in the location of the object BEFORE hover, you would use visibility, not display.
visibility:hidden, instead of display:none
and visibility:visible, instead of dislpay:block
You should use position: absolute to position this div. Absolutely positioned elements do not take up space within their container preventing them from pushing other elements around.
In most cases such as this, you will want to set the parent element to position: relative as well, so that the absolute element can be positioned relative to its parent instead of the whole document.
http://jsfiddle.net/fcW66/7/
.div_one{
position: relative;
}
.div_two {
/* ... */
position: absolute;
width: 100%;
}
You can use position: absolute; to accomplish this.
Here's a fiddle http://jsfiddle.net/QbAzY/
Add position:absolute; and width: 100px; to your .div_two rules
.div_two {
display: none;
height: 120px;
background: #444;
z-index: 999;
position:absolute;
width: 100px;
}
jsFiddle example
z-index only applies to positioned elements, so by setting position:absolute on your .div_two elements it not only allows the z-index to work, but it takes those elements out of the normal flow of the document and won't push the other divs down. Note that you also have two background rules on your .div_wrapper element, and a z-index rule that isn't doing anything.