<style type="text/css">
#displayHeader {
img {
width: 100%;
max-width: 100%;
max-height: 100%;
}
.header-img-inner {
max-height:100%;
}
}
</style>
<div id="displayHeader" style="height: 83.03px;">
<div class="header-inner">
<div class="row">
<div id="headerCol0" class="col-xs-4 text-center header-img-wrapper">
<div class="header-img-inner">
<img src="test.svg">
<p>TEST</p>
</div>
</div>
<div id="headerCol1" class="col-xs-4 text-center header-img-wrapper">
<div class="header-img-inner">
<img src="test.svg">
</div>
</div>
<div id="headerCol2" class="col-xs-4 text-center header-img-wrapper">
<div class="header-img-inner">
<img src="test.svg">
<p>tt</p>
</div>
</div>
</div>
</div>
</div>
<div id="displayContent" style="height: 264.8px;">
<div class="inner">
</div>
<div>
</div>
<div>
</div>
<div>
Image and text go out of the div block, why is this happening?
No float left, right used. It's not working with position:relative for parent and position absolute for child, but still not work well.
I only set maximum height for image when I set in on the header-img-inner
Why not use position: inherit; so as to make the image and whatever you want inside the div to inherit the position. This might help, give it a try.
Do you want something like this?
.block {
text-align: center;
background: #c0c0c0;
border: #a0a0a0 solid 1px;
margin: 20px;
}
.block:before {
content: '\200B';
/* content: '';
margin-left: -0.25em; */
display: inline-block;
height: 100%;
vertical-align: middle;
}
.centered {
display:inline-block;
vertical-align: middle;
width: 300px;
padding: 10px 15px;
border: #a0a0a0 solid 1px;
background: #f5f5f5;
}
<div class="block" style="height: 300px;">
<div class="centered">
<h1>Some Text</h1>
<img src="Untitled-2.jpg" height="150px">
</div>
</div>
Please check this link:-https://css-tricks.com/centering-in-the-unknown/
Related
This question already has answers here:
Floated elements of variable height push siblings down
(3 answers)
What is a clearfix?
(10 answers)
What methods of ‘clearfix’ can I use?
(29 answers)
Closed 3 years ago.
I should align the fixed width divs.
I have a container with a fixed width
I have dynamic divs inside but they also have a fixed width.
I would like to put 4 divs per line.
So I used CSS's float rule
My actual problem is that when the last div (card) on the line has a short height the next card gets under it.
What I'm expecting is the next div get back to a complete line.
.card {
width:200px;
height:200px;
border: 1px solid black;
float: left;
}
.container {
width: 900px;
}
.shortcard {
height:50px
}
<div class="container">
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
</div>
<div class="card shortcard">
</div>
<div class="card">
It should be in next line
</div>
<div class="card">
</div>
</div>
When the height is longer, the element is getting to another line
.card {
width:200px;
height:200px;
border: 1px solid black;
float: left;
}
.container {
width: 900px;
}
.shortcard {
height:50px
}
<div class="container">
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
</div>
<div class="card ">
</div>
<div class="card">
I'm ok here
</div>
<div class="card">
</div>
</div>
I think that what you are trying to achieve is that, you don't want the long div to come under the short div. So for that, you have to use inline-block with float: left like
.card {
width: 200px;
height: 200px;
border: 1px solid black;
display: inline-block; /* to line up the divs in a single line */
float:left; /* to make them stick to the top */
}
.card {
width: 200px;
height: 200px;
border: 1px solid black;
display: inline-block;
float: left;
}
.container {
width: 100%;
}
.shortcard {
height: 50px;
}
body,
html {
height: 100%;
}
.container {
width: 100%;
height: 100%;
}
<div class="container">
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
</div>
<div class="card shortcard">
</div>
<div class="card containerdivNewLine">
beside short div but not under it
</div>
<div class="card">
</div>
</div>
Okay, I try to fix this in your code, so that you understand better!
so basic changes are css, create a new class .container and use display: flex properties.
have a look:
<div class="container">
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
I'm ok here
</div>
<div class="card">
</div>
</div>
.card {
width:200px;
height:200px;
border: 1px solid black;
display: inline-flex;
}
.container
{
display: flex;
width: 900px;
}
.card {
width:200px;
height:200px;
border: 1px solid black;
display: inline-flex;
}
.container
{
display: flex;
width: 900px;
}
<div class="container">
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
</div>
<div class="card">
I'm ok here
</div>
<div class="card">
</div>
</div>
run the code, and let me know if you want a design like this or not?
I have three column's and the middle column has a button which i want to vertially align in the middle.
<div class="row">
<div class="col-md-1">
<div class="mypanel">
</div>
</div>
<div class="col-md-1">
<div class="mypanel">
<div style="vertical-align:middle">
<button type="button">Click</button>
</div>
</div>
</div>
<div class="col-md-1">
<div class="mypanel">
</div>
</div>
</div>
Style
.mypanel {
height: 200px;
border: 1px solid black;
}
However vertical-align:middle does not make any affect on the content of the div
DEMO
.mypanel {
height: 200px;
border: 1px solid black;
display:table;
}
.mypanel div{
display:table-cell;
vertical-align:middle
}
this will solve the problem
https://jsfiddle.net/xyx3enz1/
.mypanel {
height: 100px;
width: 100%;
display: table;
border: 1px solid black;
}
.text-centered {
text-align: center;
display: table-cell;
vertical-align: middle;
}
<div class="row">
<div class="col-md-1">
<div class="mypanel">
</div>
</div>
<div class="col-md-1">
<div class="mypanel">
<div class="text-centered">
<button type="button">Click</button>
</div>
</div>
</div>
<div class="col-md-1">
<div class="mypanel">
</div>
</div>
</div>
My favorite approach is to use pseudo elements like :after to create an element, set its height, and then vertical align based on that. It doesn't require much CSS either:
// I changed the col-md-1 to col-md-4 for this example
.col-md-4 {
text-align: center;
height: 200px;
}
.col-md-4 .mypanel {
height: 100%; // Make sure .mypanel is set to 100% height otherwise our pseudo element won't know what 100% height is
}
// Here is the pseudo element, set the vertical align here and on your button
.col-md-4:nth-child(2) .mypanel:after {
content: '';
height: 100%;
display: inline-block;
vertical-align: middle;
}
.col-md-4:nth-child(2) .mypanel button {
vertical-align: middle;
display: inline-block;
}
Check out this working jsFiddle.
I want to make the image 70% visible stick with the bottom and the rest of it invisible behind the div. I follow the tutorial with z-index 10 position absolute and overflow:hidden. but the image still show and overlap on other div. Could you help me? thanks!
HTML
<div class="screenshot search">
<div class="container container-fluid">
<div class="row">
<div class="col-md-6">
<img class="img-responsive" src="./img/sc-search#2.jpg" alt="pencarian"/>
</div>
<div class="col-md-6">
<h3>
search
</h3>
<p>
test
</p>
</div>
</div>
</div>
</div>
CSS
.screenshot {
padding: 6em 0;
height: auto;
}
.screenshot img {
width: 400px;
max-width: 90%;
z-index: 10;
position: relative;
overflow: hidden;
}
.search {
background-color: #fafafa;
}
There are loads of methods to do what you want if I understand right - (a screenshot would help, also if you are including "working code" include a JS fiddle or codepen link) then the example below has working overlap of your content div and the image.
<div class="screenshot search">
<div class="container container-fluid">
<div class="row">
<div class="wrap">
<div class="col-md-6 image-wrap">
<img class="img-responsive" src="http://www.navipedia.net/images/a/a9/Example.jpg" alt="pencarian"/>
</div>
<div class="col-md-6 content">
<h3>search</h3>
<p>test</p>
</div>
</div>
</div>
</div>
</div>
.screenshot {
padding: 6em 0;
height: auto;
}
.wrap {
position:relative;
}
.screenshot img {
width: 400px;
max-width: 90%;
z-index: ;
position: absolute;
}
.image-wrap {
overflow:hidden;
position:relative;
height: 200px;
}
.content {
display:block;
background:white;
position:absolute;
top:0;
width:100%;
}
.search {
background-color: #fafafa;
}
Fiddle
Read about Z-index here
I need the following HTML (jsfiddle):
<div class="main">
<div class="top">Top</div>
<div class="bottom">Bottom</div>
</div>
To look something like this:
Not like this:
Can you change your HTML layout a little ?
.main {
display: table;
height: 100px;
border: solid 1px;
}
.inner {
display:table-cell;
vertical-align:middle
}
.top, .bottom {background:yellow;}
<div class="main">
<div class="inner">
<div class="top">Top</div>
<div class="bottom">Bottom</div>
</div>
</div>
Check this below.
Just set the display of the parent to table-cell:
.main {
display: table-cell;
height: 100px;
border: solid 1px;
vertical-align: middle;
}
<div class="main">
<div class="top">Top</div>
<div class="bottom">Bottom</div>
</div>
position: relative;
top: 50%;
transform: translateY(-50%);
HTML:
<div class="main">
<div class="wrapper">
<div class="top">Top</div>
<div class="bottom">Bottom</div>
</div>
</div>
CSS:
.main {
display: inline-block;
height: 100px;
border: solid 1px;
line-height: 100px;
vertical-align: middle;
}
.wrapper {
line-height: 1em;
display: inline-block;
vertical-align: middle;
}
DEMO: https://jsfiddle.net/q0kLojwx/5/
My div-overflow is not working.
LINK: jsfiddle
HTML:
<div class="modalDialog" id="chooseVariableDialog">
<h4>Choose Variables</h4>
<div class="" id="variablesContainer">
<div class="variablesDiv">
<div class="variablesType">Variables</div>
</div>
<div class="variablesDiv">
<div class="variablesType">Type</div>
</div>
<div class="variablesDiv">
<div class="variablesType">comp1</div>
</div>
<div class="variablesDiv">
<div class="variablesType">extern1</div>
</div>
<div class="variablesDiv">
<div class="variablesType">coord1</div>
</div>
<div class="variablesDiv">
<div class="variablesType">id1</div>
</div>
</div>
</div>
CSS:
div.variablesDiv {
float: left;
width: 150px;
align-content: center;
}
div.modalDialog {
width: 600px;
height:auto;
overflow:auto;
background-color: #F0F0F0;
top: 10%;
}
div.names {
float:left;
width:100px;
padding-left: 35px;
}
h4 {
color:#66CCFF;
text-align:center;
}
div.variablesType {
color: #66CCFF;
float:left;
padding-left: 45px;
}
div.variablesDiv {
float: left;
width: 150px;
align-content: center;
}
div#variablesContainer {
width: auto;
height: auto;
position: relative;
float:left
}
The 6 divs (variables, type, comp1, extern1, coords1 and id1) should be in a line, but I don't know why the overflow does not work.
try this Demo
HTML
<div class="modalDialog" id="chooseVariableDialog">
<h4>Choose Variables</h4>
<div class="" id="variablesContainer">
<div class="variablesDivWraper">
<div class="variablesDiv">
<div class="variablesType">Variables</div>
</div>
<div class="variablesDiv">
<div class="variablesType">Type</div>
</div>
<div class="variablesDiv">
<div class="variablesType">comp1</div>
</div>
<div class="variablesDiv">
<div class="variablesType">extern1</div>
</div>
<div class="variablesDiv">
<div class="variablesType">coord1</div>
</div>
<div class="variablesDiv">
<div class="variablesType">id1</div>
</div>
</div>
</div>
</div>
Jquery
var variablesDivCount = $('.variablesDiv').length;
$('.variablesDivWraper').width(variablesDivCount * 150);
The problem is with
div#variablesContainer {
width: auto;
height: auto;
position: relative;
float:left
}
By making width: auto you're telling the container to adapt to the width of its parent element, not its content.
Try width: 900px; and it will work.
Few css change will make the div scrollable.
1) Remove float:left and add display: table-cell property to div.variablesDiv. You have declared css for variablesDiv in two places. Remove any on of the declaration and use the following css for div.variablesDiv
div.variablesDiv {
/*float: left;*/
width: 150px;
align-content: center;
display: table-cell;
}
2) Modify overflow property of div.modalDialog to overflow-x: scroll
div.modalDialog {
width: 600px;
height:auto;
overflow-x:scroll;
background-color: #F0F0F0;
top: 10%;
}