Img changes position of the parent div - html

I'm working on the main page of my website and want to display different kinds of square shape modules. Everything works fine until I use images on the modules. Whenever I add an img, the parent div changes position a few pixels down.
Here's my code:
HTML:
<div class="module-box">
<div class="module-dummy"></div>
<div class="module-body">
<a href="#post.linkToVideo">
<div class="play-button-div">
<img src=#Umbraco.Media(post.image).Url width="100%" height="100%" />
<span class="play-button-icon"><i class="fa fa-play" aria-hidden="true"></i></span>
</div>
</a>
</div>
</div>
CSS:
.module-box {
display: inline-block;
position: relative;
width: 100%;
}
.module-dummy {
margin-top: 100%;
}
.module-body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.play-button-div {
margin: 0 auto;
display:table;
position:relative;
}
.play-button-div img {
display:block;
margin: 0;
padding: 0;
position:relative;
}
.play-button-div i{
width: 100px;
height: 100px;
color: #0080ff;
background-color: #fff;
border-radius: 50px;
border: 3px solid #0080ff;
font-size: 70px;
text-align: center;
line-height:100px;
text-indent:15px;
opacity: .8;
}
.play-button-icon {
width: 100px;
height: 100px;
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
margin:auto;
}
.play-button-div:hover img {
opacity: .6;
}
.play-button-div:hover i {
background-color: #0080ff;
color: #fff;
border: 3px solid #FFF;
}

I suppose you mean that the parent DIV becomes a little bit higher / pushes subsequent elements down by adding a little space below the image? In this case, you can add line-height: 0 to the image container (but only if there is no text in it).
On the other hand, if this is the CSS for your containers and images:
.play-button-div {
margin: 0 auto;
display:table;
position:relative;
}
.play-button-div img {
display:block;
margin: 0;
padding: 0;
position:relative;
}
, then you should change display:block; to display:table-cell; in .play-button-div img, and also add vertical-align: top; to it.

Related

how to make dots inherit the width of the image? (slick)

There is a block 225px. Inside you insert a picture large size (850px). And she goes outside.
It looks like this:
.content {display: inline-block;}
.column {float:right; width:225px;}
.slider {
border: 1px solid;
width: 220px;
padding: 5px;
}
.single-slide img {
width: auto;
}
<div class="content">
<div class="column">
<div class="slider single-slide">
<div><img src='https://s-media-cache-ak0.pinimg.com/736x/2c/d0/19/2cd0197c5eb8c1f84e81734f97e80cd3.jpg' /></div>
<div>to place the center of the image</div>
</div>
</div>
</div>
Using slick slider. I want to add dots to control the slider.
When I add the dots they are placed in the middle of the block. It's okay, I understand. But I want to place them in the center of the picture. How to do it?
UPD: The image goes beyond the block, that's right! And I need to do to the dots were at the center of the image, not the block
I see that your dots are in the center of the window.
To do this, your dots list must be inside a container with the image's width.
I think you should enlarge your slider or limit image's width with a max-width: 100%;
if you want to need image in box then change
.single-slide img { width: auto;}
to
.single-slide img { max-width: 100%;}
Updated: The inherit keyword specifies that a property should inherit its value from its parent element [ Source ]. and image can't be a parent element. see this example.
Here is a solution on based on inherit and position on your latest update.
See the html section I have added a class "img-holder" on div which hold the img and add a class "div_center" on div which contain text's.
img inherit width from its parent div class "img-holder". "img-holder" and "div_center" inherit width from parent div class slider.
N.B: if you set the img width auto text will always center of the div class slider.
.content {
display: inline-block;
}
.column {
float: right;
width: 225px;
}
.slider {
border: 1px solid #000;
width: 220px;
padding: 5px;
position:relative;
}
.img-holder {
width: inherit;
}
.img-holder img {
width: inherit;/*width auto default value. The browser calculates the width*/
}
.div_center {
position: absolute;
top: 50%;
left: 0;
right: 0;
text-align: center;
}
<div class="content">
<div class="column">
<div class="slider single-slide">
<div class="img-holder">
<img src='https://s-media-cache-ak0.pinimg.com/736x/2c/d0/19/2cd0197c5eb8c1f84e81734f97e80cd3.jpg' />
</div><!--./ img-holder -->
<div class="div_center">
to place the center of the image
</div><!--end of txt_center -->
</div><!--./ slider single-slide-->
</div><!--./ column -->
</div><!--./ content -->
Previous: Position absolute for slick-dots class but you dont set any relative position for that. so you need to add position relative to your slide div.
And make the image responsive. I have added responsive property for your image on css section and added border on li for clear view.
.content {display: inline-block;}
.column {float:right; width:225px;}
.slider {
border: 1px solid;
width: 220px;
padding: 5px;
position: relative;
}
.single-slide img {
max-width:100%;
display:block;
height:auto;
margin:0 auto;
}
.slick-dotted.slick-slider
{
margin-bottom: 30px;
}
.slick-dots
{
position: absolute;
top:50%;
left:0;
right:0;
display: block;
width: 100%;
padding: 0;
margin: 0;
list-style: none;
text-align: center;
}
.slick-dots li
{
position: relative;
display: inline-block;
width: 20px;
height: 20px;
margin: 0 5px;
padding: 0;
border:2px solid red;
cursor: pointer;
}
.slick-dots li button
{
font-size: 0;
line-height: 0;
display: block;
width: 20px;
height: 20px;
padding: 5px;
cursor: pointer;
right: 0;
bottom: 0;
left: 0;
color: transparent;
border: 0;
outline: none;
background: transparent;
}
.slick-dots li button:hover,
.slick-dots li button:focus
{
outline: none;
}
.slick-dots li button:hover:before,
.slick-dots li button:focus:before
{
opacity: 1;
}
.slick-dots li button:before
{
font-family: 'slick';
font-size: 12px;
line-height: 20px;
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
content: '•';
text-align: center;
opacity: .25;
color: black;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.slick-dots li.slick-active button:before
{
opacity: .75;
color: black;
}
<div class="content">
<div class="column">
<div class="slider single-slide">
<div><img src='https://s-media-cache-ak0.pinimg.com/736x/2c/d0/19/2cd0197c5eb8c1f84e81734f97e80cd3.jpg' /></div>
<ul class="slick-dots">
<li class="active"><button></button></li>
<li><button></button></li>
<li><button></button></li>
</ul>
</div>
</div>
</div>

Center div on html line

I have a problem with html. I am trying to set a html line and on that line I have to set a div with text. Here is the example, but it is a photo. I would like to get this in html.
I hope someone can help me.
Edit:
I know how to get a line in html and I know how to get this yellow div with the text. The problem is. How do I get the yellow div on the line. This is my current result.
You can do this with Flexbox and pseudo-elements. Here is Fiddle
.element {
display: flex;
align-items: center;
}
.price {
background: #FEC538;
font-size: 30px;
font-weight: bold;
padding: 10px 40px;
border-radius: 50px;
}
.element:before,
.element:after {
content: '';
flex: 5;
height: 3px;
background: #C3C3C3;
}
.element:after {
flex: 1;
}
<div class="element">
<div class="price">Save 35%</div>
</div>
This will do it
<div class='c1'>
<span>save 35%</span>
</div>
.c1{
position:relative;
text-align:center;
}
.c1:before{
content:'';
height:2px;
width:100%;
background:#CDCCCD;
position:absolute;
top:50%;
left:0;
margin:-1px 0 0;
}
.c1 span{
display:inline-block;
padding:5px 15px;
background:#FEC538;
border-radius:20px;
position:relative;
}
see it here : https://jsfiddle.net/IA7medd/6tonuvg6/
That will do..
Html
<div class="center-div"></div>
**Css**
body
{
background-color: #fcfcfc;
}
.center-div
{
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100px;
height: 100px;
background-color: #ccc;
border-radius: 3px;
}
Set width, and set margin:auto;.
div.c2 {
margin:auto;
width:80px;
text-align:center;
/*color*/
background-color: #FEC538;
border-radius: 10px;
}
<div>
<div class=c2>Save 35%</div>
<div>

h1 is too low in the element

<!DOCTYPE html>
<html>
<head>
<style>
/* main elements */
div.body {
display: block;
background-color: Lavender;
border: 0px 20px 0px 20px;
max-width: 1100px;
margin-top: 10px;
margin-right:20px;
margin-left: 20px;
clear: both;
padding: 0px 20px 0px 20px;
}
body {
display: block;
background-color: Lavender;
border: 10px;
max-width:1100px;
margin: 0px 280px 0px 10px;
clear:both;
}
/*Body Divs*/
div.bodycontent{
display:block;
position:absolute;
top: 10px;
width: 1075px;
height: 470px;
background-color: MediumAquaMarine;
margin-right:0;
margin-left:0px;
bottom:10px;
}
div.body1 {
display: inline-block;
background-color: limegreen;
position: absolute;
top: 10px;
width:480px;
height:225px;
margin-left:10px;
padding: 0 10px 0 10px;
}
div.body2 {
display: inline-block;
background-color: Salmon;
position: absolute;
top: 10px;
width:525px;
height:225px;
margin-left:520px;
padding: 0 10px 0 10px;
}
div.body3 {
display: inline-block;
background-color: FireBrick;
position: absolute;
top: 250px;
width:530px;
height:205px;
margin-left:10px;
padding: 0 10px 0 10px;
}
div.body4 {
display: inline-block;
background-color: SeaGreen;
position: absolute;
top: 250px;
width:475px;
height:205px;
margin-left:570px;
padding: 0 10px 0 10px;
}
/*-----------------------------------------------------------------------*/
header {
background-color: Lavender;
}
/*header divs*/
div.header {
display:block;
position:absolute;
width: 1075px;
height:150px;
top:490px;
background-color: PaleGoldenRod;
margin-right:0;
margin-left: 0px;
}
div.backinfo {
display:inline-block;
background-color: lightblue;
position: absolute;
top:80px;
width:455px;
padding:10px 10px 10px 10px;
height:40px;
margin-right:900px;
margin-left:10px;
}
div.digitalbay {
display: inline-block;
background-color: coral;
position: absolute;
width:455px;
height:60px;
top:20px;
margin-top:-10px;
margin-right:560px;
margin-left:180px;
padding: 0 10px 0 10px;
}
div.nav {
display: inline-block;
position: absolute;
background-color: lightblue;
top:10px;
margin-right:0px;
margin-left:665px;
padding: 10px 0px 10px 0px;
height:110px;
width:395px;
}
div.contact {
display: inline-block;
background-color: Chocolate;
position: absolute;
top: 100px;
width:300px;
height:45px;
margin-right:550px;
margin-left:190px;
padding: 0 10px 0 10px;
}
div.contact2 {
display: inline-block;
background-color: DeepPink;
position: absolute;
top: 100px;
width:130px;
height:45px;
margin-right:550px;
margin-left:515px;
padding: 0 10px 0 10px;
}
</style>
</head>
<div class="bodydiv">
<header>
<div class="header">
<div class="backinfo">
</div>
<div class="digitalbay">
<h1>Digital Bay</h1>
</div>
<div class="nav">
</div>
</header>
<body>
<div class="bodycontent">
<div class="body1">
</div>
<div class="body2">
</div>
<div class="body3">
</div>
<div class="body4">
</div>
</div>
</body>
</div>
<aside>
<div class="extrainfo">
</div>
<div class="slideshow">
</div>
</aside>
<footer>
<div class="footer">
</div>
</footer>
</html>
In the elements above, where my <div class=digitalbay>element is located when compiled, the <h1>element nested in the div is too low in the element when compiled. I was wondering if there is a way to make it higher up the div. I already tried changing the margin, but it moves the div up along the page and that doesn't help.
Set a margin on the h1 and it will move up. Example:
h1 {
margin-top: 0.25em;
}
Your .header div has a top: 490px. That is why it is so low.
On other note, here's a bit of feedback on your CSS and HTML.
Never put the <body> tag inside a <div>... it is always supposed to be right after the <head> tag. When the browser parses the HTML, it'll auto correct that for you, but you will have bugs if you start expecting your body tag to be where it is now.
Don't write your CSS as follow div.className. Instead, simply use the class name without the element: .className. This will reduce specificity and make it easier to maintain as it grows. It'll also dramatically reduce your typing.
I don't know what your goal is in the end with this page, but it may be easier to not use position: absolute everywhere. Use position: relative instead.
In HTML, there is a tag called <main>. There can only be one per page, and I use it instead of your <div class="bodydiv">.
You are using <header> and <footer> and putting a <div> inside of it with a class of header and footer... Remove that and put your class directly on the <header> and <footer> tag.
Inside your <div class="bodycontent">, you could use the <section> tag instead of DIVs (if it is semantically correct in your case).

Using opacity to blur a Div's background colour instead of mentioning rgba colour of a Div

I have an Image on the page. I have put a Div on footer with a heading and a paragraph inside the Div. I have made the Div's background transparent like this way , background-color: rgba(0,0,0,.6);.
But I need to implement this like this way , background-color:black; opacity:0.6".
The problem is, if I am doing it using opacity then the heading and paragraph is also getting blur with the Div's colour. How can I solve it?
Below is my full code.
CSS
<style type="text/css">
.div1 {
max-width: 100%;
height: auto;
text-align: center;
display: block;
border: none;
}
.feature-text-overlay {
background-color: rgba(0,0,0,.3);
bottom: 0;
padding: .6em 0 .8em;
position: absolute;
text-align: center;
width: 100%;
}
.feature-title {
font-size: .875em;
margin: 0;
text-transform: uppercase;
color:white;
}
.feature-description {
line-height: 1.2;
margin: 0 2em;
color:white;
}
</style>
Html
<div class="div1">
<img src="~/Content/Image/rendering-graphics-in-resolution-222734.jpg" />
<div class="feature-text-overlay" style="height:52.599999277954px; min-height:1px;">
<h4 class="feature-title">Enterprise Mobility Suite</h4>
<p class="feature-description">Manages Users, Devices and Data</p>
</div>
</div>
css
.feature-text-overlay {
bottom: 0;
padding: .6em 0 .8em;
position: absolute;
text-align: center;
width: 100%;
position:relative; /* add this to specify position */
}
/* create pseudo css element */
.feature-text-overlay:before {
content:"";
background-color: #000;
opacity:0.3;
bottom: 0;
top:0;
right:0;
left:0;
position: absolute;
}
Demo
edit as per comment demo 2

Set absolute positioned element width to its content (it is only a text)

I am going to build this
This is my HTML code
<div class="al-head-container">
<div></div>
<span>Center Websites</span>
</div>
This is css :
.al-head-container{
margin: auto;
width: 100%;
padding:0 4%;
position: relative;
box-sizing: border-box;
}
.al-head-container > span{
font: 2.1em titr;
color: #ae7f00;
background-color: #FFFFFF;
position: absolute;
right: 0;
left:0;
}
.al-head-container > div{
width: 100%;
height: 20px;
background-image: url("../image/head-line.jpg");
position: relative;
top: 25px;
}
But this is the result of code
The problem is the span width is set to 100% and its width doesn't fit to its content. it is what I get from the firebug
As you see the text covers the DIV that contains the line.
I tried to set the display:inline-block for span but nothing changed. How do I can make the absolute positioned span width to fit the content?
Why not accomplish this purely in CSS with a single element:
div {
border-top:1px solid lightgrey;
border-bottom:3px solid lightgrey;
height:2px;
position:relative;
margin-top:15px;
}
div:after {
content:attr(data-label);
position:absolute;
top:-10px;
left:50%;
padding:0 20px;
display:inline-block;
background:#fff;
transform: translateX(-50%);
text-align:center;
color:#A37716;
font-size:24px;
}
<div data-label="Center Websites"></div>
I will suggest make a few changes on your code.
You can remove the div element and instead use a pseudo-element later with CSS
<div class="al-head-container">
<span>Center Websites</span>
</div>
Then with CSS make the pseudo-element be the absolute one to place it behind the span:
.al-head-container{
position:relative;
}
.al-head-container > span{
font: 2.1em titr;
position:relative;
z-index:10;
display:inline-block;
padding:0 20px;
height:2.1em;
line-height:2.1em;
color: #ae7f00;
background-color: #FFFFFF;
}
.al-head-container:after{
content:"";
width: 100%;
top:50%;
transform:translateY(-50%);
border-top:dotted 3px red;
position: absolute;
left:0;
}
Check this Demo on Jsfiddle
Note that you can replace the border on the fiddle with your background image
Try this:
.fancy {
line-height: 0.5;
text-align: center;
}
.fancy span {
display: inline-block;
position: relative;
}
.fancy span:before,
.fancy span:after {
content: "";
position: absolute;
height: 5px;
border-bottom: 3px solid gray;
border-top: 1px solid gray;
top: 0;
width: 600px;
}
.fancy span:before {
right: 100%;
margin-right: 30px;
}
.fancy span:after {
left: 100%;
margin-left: 30px;
}
<div class="subtitle fancy">
<span>Center Websites</span>
</div>
Also here you have a working fiddle
try to add margin auto on absolute span
.al-head-container > span{
font: 2.1em titr;
color: #ae7f00;
background-color: #FFFFFF;
position: absolute;
right: 0;
left:0;
margin : auto;
}