Center image in ajustable div - css

I have a Div with a 10% width and within its content there is an image I want to be able to center vertically/Horizontally and resize to fit in its container.
It resize well when the windows resize but do not know how can i center the image within the container.
<div class="proyecto_holder">
<div class="tipo_proyecto_image">
<img src="http://i57.tinypic.com/vgo9k5.png" border="0" />
</div>
<div class="proyecto_datos_holder">
<div class="proyecto_titulo">This id the title of the project</div>
<div class="proyecto_tipo">Type of Project</div>
</div>
.proyecto_holder {
width:100%;
float:left;
height:75px;
overflow:hidden;
background-color:#F2F2F2;
margin-top:1px;
}
.tipo_proyecto_image {
width:10%;
height:75px;
float:left;
}
.tipo_proyecto_image img {
width:80%;
}
.proyecto_datos_holder {
width:90%;
height:75px;
float:left;
}
.proyecto_titulo {
width:100%;
float:left;
font-family: Titillium Web;
font-size:18px;
font-weight:bold;
line-height:20px;
margin-top:10px;
color:#666666;
}
.proyecto_tipo {
float:left;
font-family: Titillium Web;
font-size:16px;
line-height:20px;
color:#11BB00;
padding: 10px 15px;
}
Here is the demo: https://jsfiddle.net/3t2shesb/
Thanks in advance.

If I understand what you want to do, try using transform and position:relative on the img to give you something like this:
.tipo_proyecto_image img {
width: 80%;
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
As shown here:
.proyecto_holder {
width:100%;
float:left;
height:75px;
overflow:hidden;
background-color:#F2F2F2;
margin-top:1px;
}
.tipo_proyecto_image {
width:10%;
height:75px;
float:left;
}
.tipo_proyecto_image img {
width: 80%;
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.proyecto_datos_holder {
width:90%;
height:75px;
float:left;
}
.proyecto_titulo {
width:100%;
float:left;
font-family: Titillium Web;
font-size:18px;
font-weight:bold;
line-height:20px;
margin-top:10px;
color:#666666;
}
.proyecto_tipo {
float:left;
font-family: Titillium Web;
font-size:16px;
line-height:20px;
color:#11BB00;
padding: 10px 15px;
}
<div class="proyecto_holder">
<div class="tipo_proyecto_image">
<img src="http://i57.tinypic.com/vgo9k5.png" border="0" />
</div>
<div class="proyecto_datos_holder">
<div class="proyecto_titulo">This id the title of the project</div>
<div class="proyecto_tipo">Type of Project</div>
</div>

The following works ...
HTML:
<div class='Container'>
<img src='test.png'>
</div>
CSS:
div.Container {
position:absolute;
top:25%;left:25%;
width:50%;height:50%;
background:#FF0;
}
div.Container > img {
display:block;
position:absolute;
left:10%; width:auto;
top:35%; height:30%;
}
Here I assign all 100% of the parents height in the img’s css-declaration (2*)35% + 30%, and use that for scaling ... Maybe not what you want, but it works ... try it out :)

Related

Box with diagonal section css

I would like to achieve something like in the image
https://www.dropbox.com/s/rhvfaf4bllydl5f/stack1.JPG?dl=0
I use bootstrap also and i have no idea to realize the diagonal section in css.
should i use a background image?
example also available as a fiddle:
https://jsfiddle.net/9xuvacr0/
body {
background-color: #000;
margin: 0px;
}
p {
color: white;
}
.diagonal {
z-index: 1;
padding: 3em;
-webkit-transform: rotate(-3deg);
transform: rotate(-3deg);
background-color:blue;
text-align:center;
width:50%;
}
<header>
<p>Header</p>
</header>
<div class="diagonal">
<p>Lorem ipsum</p>
</div>
hope this help
body{
background-color:#999;
font-family:arial;
}
.cont{
position:relative;
width:300px;
height:350px;
overflow:hidden;
background-color:green;
border-radius:22px;
}
.upper-cont{
position:relative;
width:300px;
height:150px;
background-image: linear-gradient(to right, #8d127c, #711977, #432166 , #132359);
}
.upper-over-top{
position:absolute;
background-color:#fff;
height:70px;
width:400px;
top:-18px;
left:-10px;
transform:rotate(-3deg);
opacity:.1;
}
.upper-text-cont{
position:relative;
padding:20px 20px 0 20px;
max-height:90px;
color:#fff;
}
.upper-text-span{
font-size:12px;
}
.upper-text-head{
text-align:center;
padding-top:30px;
font-size:28px;
}
.upper-over-bottom{
position:absolute;
background-color:#fff;
height:30px;
width:400px;
top:139px;
left:-10px;
transform:rotate(-3deg);
}
.bottom-cont{
position:relative;
width:300px;
height:200px;
background-color:#fff;
}
.bottom-text-cont{
position:relative;
padding:20px 20px 0 20px;
max-height:90px;
color:#333;
text-align:center;
}
<div class="cont">
<div class="upper-cont">
<div class="upper-over-top"></div>
<div class="upper-text-cont">
<div class="upper-text-span">
Lorem Ipsum
</div>
<div class="upper-text-head">
PACCHETTO UNO
</div>
</div>
<div class="upper-over-bottom"></div>
</div>
<div class="bottom-cont">
<div class="bottom-text-cont">
text here
</div>
</div>
</div>

Prevent a specific child div from expanding the parent div

I'm currently developping a website and encountered a problem with CSS.
I have a parent div containing 2 or more children: one containing the name of a user that sits on top of the other children, and just below 1 or more side by side divs which display items owned by the user.
At the moment it works fine, but if the user's name (top div) is larger than the total width of the divs below, it will expand the parent div.
I'd like to only allow the bottom divs to expand the parent div and make the title div use the full parent div's width without being able to make it larger.
I created a fiddle about it: http://jsfiddle.net/mLxjL/2/
HTML:
<div class="matches">
<div class="match-container">
<div class="user-match-container">
<div class="match-owner user">You</div>
<div class="match">
<div class="thumbnail">
<img class="image-container" src="img-path">
<div class="thumbnail-count">2</div>
</div>
<div class="item-name">The Zeppelin of Consequence (Trading Card)</div>
</div>
</div> <span class="arrow">→</span>
<div class="user-match-container">
<div class="match-owner friend">PfaU- [W] King Arthurs Gold</div>
<div style="clear:both;"></div>
<div class="match">
<div class="thumbnail">
<img class="image-container" src="img-path">
<div class="thumbnail-count">2</div>
</div>
<div class="item-name">The Lost Hobo King</div>
</div>
</div>
</div>
</div>
CSS:
.match-container:before, .match-container:after {
content:"";
display:table;
}
.match-container:after {
clear:both;
}
.match-container {
border:1px solid #666;
background-image:url('img/stripes.png');
border-radius:5px;
padding:10px;
margin:10px;
float:left;
}
.match {
width:112px;
float:left;
margin: 0 2px;
}
.match .image-container {
width:112px;
height:130px;
display:block;
}
.match .item-name {
line-height:12px;
font-size:10px;
margin-top:4px;
text-align:center;
height:24px;
overflow:hidden;
clear:both;
}
.match-container .arrow {
float:left;
position:relative;
top:70px;
margin:5px;
}
.match-owner {
line-height:14px;
font-size:12px;
margin-top:4px;
text-align:center;
height:14px;
overflow:hidden;
margin-bottom:4px;
border:1px solid #666;
background-image:url('img/stripes.png');
border-radius:5px;
}
.match-owner.user {
background-color:green;
}
.match-owner.friend {
background-color:red;
}
.thumbnail-count {
position:relative;
top:-24px;
margin-bottom:-24px;
font-size:16px;
font-weight:bold;
border-top:1px solid white;
border-right:1px solid white;
border-top-right-radius: 7px;
font-size:18px;
background: rgb(160, 160, 160) transparent;
background: rgba(160, 160, 160, 0.70);
padding: 0 4px;
float:left;
}
.user-match-container {
float:left;
}
Is it possible to do this without using JavaScript?
You can use Absolute positioning
FIDDLE
position:absolute;
top:0;
left:0;
width:100%;
and on the container div :
padding-top: /*the height of the absolutly positioned child*/ ;
position:relative;
If you add the following styles you should achieve what you want:
.user-match-container {
position: relative;
padding-top: 22px;
}
.match-owner {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
position: absolute;
top: 4px;
left: 0;
right: 0;
}
Example

How to center a 3 column Css Div Site?

My site has a 100% width header & footer, and 3 columns. The columns need to all be fixed width, but in the center of the page.
HTML
<div id="Table_01">
<div id="Header"></div>
<span id="LeftCol">Left Col </span>
<span id="MidCol">Middle </span>
<span id="RightCol">Right Col </span>
<div id="Footer">Footer</div>
</div>
CSS
#Table_01 {
position:absolute;
left:0px;
top:0px;
width:100%;
}
#Header {
position:absolute;
left:0px;
top:0px;
width:100%;
height:42px;
background-image: url("images/Header.gif");
}
#LeftCol {
position:absolute;
left:0px;
top:42px;
width:300px;
height:422px;
text-align:center;
border:2px solid;
}
#MidCol {
position:absolute;
left:300px;
top:42px;
width:550px;
height:422px;
text-align:center;
border:2px solid;
}
#RightCol {
position:absolute;
left:850px;
top:42px;
width:300px;
height:422px;
text-align:center;
border:2px solid;
}
#Footer {
position:absolute;
left:0px;
top:464px;
width:1000px;
height:1536px;
}
JSFIDDLE
What you need is a mix of position:relative and margin:0 auto applied to a container.
Add a container div:
.container {
width:1150px;
margin:0 auto;
position:relative;
}
See updated JSFIDDLE

display image a text inline with each other

i have this CSS:
<style type="text/css">
#box {
width:100%;
height:80px;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
#text, #text a {
font-size:16px;
color:#F36F25;
margin:10px;
}
#text:hover, #text a:hover {
color:#666666;
text-decoration:none;
}
#text img {
vertical-align: middle;
margin-right:20px;
}
</style>
its currently displaying the image and text inline but i have multiple images/text below each other. how can i make all the images align in the same position below each other?
here is a fiddle: http://jsfiddle.net/8dsTu/
http://jsfiddle.net/8dsTu/4/
<div id="text">
<img src="../images/icons/address.png" height="60" />
<div style="display:inline-block;">
Address 1,<br />
Address 2,<br />
County Post Code
</div>
</div>
Edit css:
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:left;
margin-left:100px;
}
Your HTML is invalid, id property is meant to be unique and you have a few <div> elements with id="text". To get what you want you'll have to: (jsFiddle)
replace all id="text" with class="text" and add <div class="caption"> to wrap each of the captions:
<div id="box">
<div class="box-inner">
<div class="text">
<img src="../images/icons/telephone.png" height="60" />
<div class="caption">00000 00 00 00</div>
</div>
<div class="text">
<img src="../images/icons/email.png" height="60" />
<div class="caption">sales#domain.co.uk</div>
</div>
<div class="text">
<img src="../images/icons/address.png" height="60" />
<div class="caption">Address 1,<br />Address 2,<br />County Post Code</div>
</div>
</div>
</div>
Adjust the css:
#box {
width:100%;
height:80px;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
.text, .text a {
font-size:16px;
color:#F36F25;
margin:10px;
}
.text:hover, .text a:hover {
color:#666666;
text-decoration:none;
}
.text img {
vertical-align: middle;
margin-right:20px;
}
.caption{ /* This is the new bit - display:inline-block does the trick. adjust margin-top to your needs */
display:inline-block;
vertical-align:top;
margin-top:15px;
}
#box {
width:100%;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
.text, .text a {
font-size:16px;
color:#F36F25;
}
.text:hover, .text a:hover {
color:#666666;
text-decoration:none;
}
.text img {
vertical-align: middle;
margin-right:20px;
width: 60px;
background: black;
float: left;
}
.text {
overflow: hidden;
width: 250px;
margin: 10px auto;
}
Something like this? But you must replace your id's with classes.

CSS layout zoom issue

My issue is that when I zoom in or out of the page (in all the browsers I tried), only some parts of it are displayed as zoomed (the contents that are in the divs, but not the divs themselves). I put the borders to show it easily.
When I searched for a solution, all of them mentioned that it is because of fixed width values by using pixels (px). So, I used % when putting values to width and height; but still, the issue remains...
Here are some screenshots to illustrate my problem:
When zoomed-in:
When zoomed-out:
Here is my code:
HTML:
<html>
<head>
<link href="style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="title_bar">
some txt here
<div id="title_img"></div>
<div id="title_txt"></div>
<div id="menu_navigation"></div>
</div>
<div id="title_bar_2">
some txt here
</div>
<div id="container_columns">
<div id="column_1">
<span id="column_1_content">some txt here</span>
</div>
<div id="column_2">
<span id="column_2_content">some txt here</span>
</div>
</div>
</body>
</html>
CSS:
html body
{
margin: 0;
width: 100%;
height: 100%;
background-color:#f2f2f2;
}
div#title_bar
{
height:4%;
width:76%;
margin:auto;
margin-top:4%;
border-style:solid;
border-color:blue;
}
div#title_bar_2
{
text-align:center;
height:44%;
width:76%;
margin:auto;
margin-top:2%;
border-style:solid;
border-color:blue;
}
div#title_bar img
{
margin-top:1%;
float:left;
}
div#title_txt
{
float:left;
margin-left:2%;
margin-top:1.4%;
font-style: italic;
font-family:verdana;
font-size: 16px;
}
div#menu_navigation
{
float:left;
margin-left:35%;
margin-top:1.4%;
font-size:19px;
}
div#container_columns
{
margin:auto;
width:76.5%;
margin-top:2%;
height:27%;
border-style:solid;
border-color:blue;
}
div#column_1
{
height:100%;
width:49%;
float:left;
border-style:solid;
border-color:blue;
}
div#column_2
{
margin-left:1%;
width:48%;
float:left;
height:100%;
}
Hi This is happening because you are using the property height. try not to use it, if you want this property.
html body{
margin: 0;
width: 100%;
background-color:#f2f2f2;}
div#title_bar{
width:76%;
margin:auto;
margin-top:4%;
border-style:solid;
border-color:blue;}
div#title_bar_2{
text-align:center;
width:76%;
margin:auto;
margin-top:2%;
border-style:solid;
border-color:blue;}
div#title_bar img{
margin-top:1%;
float:left;}
div#title_txt{
float:left;
margin-left:2%;
margin-top:1.4%;
font-style: italic;
font-family:verdana;
font-size: 16px;}
div#menu_navigation{
float:left;
margin-left:35%;
margin-top:1.4%;
font-size:19px;}
div#container_columns{
margin:auto;
width:76.5%;
margin-top:2%;
border-style:solid;
border-color:blue;
display:block;}
div#column_1{
width:48%;
float:left;
border-style:solid;
border-color:blue;}
div#column_2{
margin-left:1%;
width:48%;
float:left;}

Resources