I saw many posts and question asked on this issue but none was useful for me so i ask another one. I have a div that has some text in it and then an img, i have several of these divs in a row and when i open the page on different resolutions the texts sometimes expand to two rows instead of one, so the pictures are not on the same level. because of that i want to make the OMG stick to the bottom of the div so when the text expands they will still be on same level.
any suggestions?
code:
<div id="put_entry" class="main_banner">
<h1>
<center>
published
</center>
</h1>
<center>i published those items<br /><center>
<center>
<img src="search_torent.png" id="index_banner" onclick="document.location='published.php';return false;"/>
</center>
</div>
css:
.main_banner{
margin-left: 15px;
direction: rtl;
border-radius: 10px;
background: #D1E3F3;
border: 1px solid #707070;
margin-top: 10px;
margin-bottom: 10px;
padding: 10px;
min-height: 273px;
width: 270px;
float: left;
}
.main_banner img{
cursor: pointer;
}
Fiddle: http://jsfiddle.net/EFPt7/
.main_banner{
margin-left: 15px;
direction: rtl;
border-radius: 10px;
background: #D1E3F3;
border: 1px solid #707070;
margin-top: 10px;
margin-bottom: 10px;
padding: 10px;
min-height: 273px;
width: 270px;
float: left;
position: relative;
}
.main_banner img{
cursor: pointer;
position: absolute;
bottom: 0;
}
try position:absolute and then set the width, height and margin.
fiddle: http://jsfiddle.net/EFPt7/15/
I suggest you should add new div for published item and then new row for img. Adding some code for css of new div like this for fixed min height of you publish and then new row for image. Anyway you can used align in div class main_banner.
---html---
<div id="put_entry" class="main_banner" align="center">
<div>
<h1>published</h1>
i published those items
<br/>
</div>
<img src="https://www.google.co.th/images/srpr/logo4w.png"
id="index_banner"
onclick="document.location='published.php';return false;"
width="270px"/>
</div>
--- css ---
.main_banner{
margin-left:15px;
direction:rtl;
border-radius:10px;
background:#D1E3F3;
border:1px solid #707070;
margin-top:10px;
margin-bottom:10px;
padding:10px;
width:270px;
float:left;
}
.main_banner img{
cursor:pointer;
}
.main_banner div{
min-height:273px;
}
Related
I am developing a website.
The site is in a very early state, and my problem is the header on the top of the page. I would like to have the Mainline "PersIntra" stand beside the little box with the "log out button" and not over it. I have tried to make this work with my css. I have tried nesting divs.
The header is getting too wide vertical. I want to make the headline text size bigger without the header itself needing to grow wider because of the text is not beside the logout box but over it.
Here is some links to tell you what I mean. (It is complicated to describe in text.)
Screenshot of header
The website is in Danish, but that shouldn't stop you from seeing my problem (screenshot..).
Here is the html:
<div id="header">
<h2> PersIntra </h2>
<div id="border">
Velkommen <?php echo $_SESSION['enummer']; ?> <br>
Du har 1 ny besked <br>
Log Ud <br>
</div>
</div>
</div>
Here is the css:
#header {
background-color:#66cc33;
color:white;
text-align:center;
padding:5px;
border: 10px solid;
border-radius: 25px;
}
#border {
width: 150px;
padding: 5px;
border: 5px solid navy;
margin: 25px;
border-style: solid;
border-color: #eeeeee;
}
Try edit your css.
#header {
background-color:#66cc33;
color:white;
text-align:center;
padding:5px;
border: 10px solid;
border-radius: 25px;
}
#header h2 {
margin-top:50px;
float:right;
margin-right:300px;
}
#border {
width: 150px;
padding: 5px;
border: 5px solid navy;
margin: 25px;
border-style: solid;
border-color: #eeeeee;
}
There are lots of ways to do that kind of thing. One is to float the header to the left and display the header and login box inline, like so:
#header {
background-color:#66cc33;
color:white;
text-align:center;
padding:5px;
border: 10px solid;
border-radius: 25px;
}
h2 {
float: left;
display: inline;
width: 80%;
font-size: 2em;
}
#border {
display: inline;
width: 20%;
width: 150px;
padding: 5px;
border: 5px solid navy;
margin: 25px;
border-style: solid;
border-color: #eeeeee;
}
If you're trying to get something up and running quickly, you might consider using a css framework like bootstrap (http://getbootstrap.com/). If you're trying to learn css, I'd recommend pulling down the code for a framework like that and/or looking at the site for it with dev tools open, and explore what they're doing.
Hope that helps.
If you want to have text bigger or move around without affecting other content you could similar to this:
#header {
background-color:#66cc33;
color:white;
text-align:center;
padding:5px;
border: 10px solid;
border-radius: 25px;
position: relative;
}
#header h2 {
position: absolute;
top: 0;
left: 25px;
}
I would just add this to #border:
#border {
position: absolute;
bottom: 20px
left: 20px;
}
and add position: relative to the surrounding element:
#header {
position: relative;
}
Tha way #border will not take any space in the surrounding element and you can center-align you header without problems.
I designed a navbar for my site. With help from some really kind folks at atackoverflow, I was able to learn the use of table-cell and inline-table display attributes and center the headings for each tab.
However, the same method fails to work when instead of text, I have a circle div positioned inside the tab. It seems to push mess up the positioning of all other tabs.
HTML:
<div id="headContainer">
<div id="rightBar">
<div class="navelement" style="border-bottom: 5px solid #6217FF;"><span>home</span></div><!--
--><div class="navelement"><span>about</span></div><!--
--><div class="navelement"><span>feedback</span></div><!--
--><div class="navelement"><span>contact</span></div><!--
--><div class="navelement"><span><div id="circle"></div></span></div>
</div>
</div>
CSS:
#headContainer {
height: 80px;
width: 100%;
background-color: rgba(28, 35, 46,0.9);
transition:height 0.3s ease-out;
border:0px solid yellow;
position: fixed;
top: 0px;
z-index: 900;
overflow: hidden;
}
#headContainer:hover {
height: 120px;
}
#rightBar {
display: inline-block;
height: 100%;
border:0px solid cyan;
margin-left: 160px;
float: right;
}
.navelement{
display: inline-table;
height: 100%;
border-top:5px solid transparent;
padding-left: 50px;
padding-right: 50px;
padding-left: 3.5vw;
padding-right: 3.5vw;
color: #DFDFDF;
border-bottom: 5px solid transparent;
transition:all 0.3s;
border-top:5px solid #6217FF;
}
.navelement:hover{
background:#6217FF;
}
.navelement span {
display: table-cell;
font-size: 1.2em;
font-size: 1.2rem;
vertical-align: middle;
font-family: 'Open Sans';
}
#circle{
width:50px;
height:50px;
border-radius:50%;
background-color:green;
}
What I want it to look like:
What it looks like right now:
Fiddle: http://jsfiddle.net/R8nGu/1/
inline-table and inline-cell are not commonly used for this task. Rather, it is done with relative positioning. Also, your navigation has a very strange structure, let's correct that first (this is the most widely used approach for nav structures):
<ul id="rightBar">
<li><span>home</span></li>
<li><span>about</span></li>
<li><span>feedback</span></li>
<li><span>contact</span></li>
<li><span id="circle"></span></li>
</ul>
A well-known technique to vertically center content is to use the top and margin-top properties together on a relatively positioned element. Set top: 50%, then set margin-top to minus half of the height of the element. In your case, given that the spans have a font-size of 1.2rem, that would be margin-top: -0.6rem;.
You can do the same for your circle: it is 50px high, so the margin-top should be -25px.
Check out the working fiddle here: http://jsfiddle.net/R8nGu/3/
I'm writing a website and I have some problems with margin.
I have a following HTML code:
<div id="mainBody">
<div class="subTitle" id="backgroundTitle" >
<h3>
Background
</h3>
</div>
</div>
my CSS code is the following:
#mainBody{
height:200px;
width: 500px;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
}
.subTitle {
margin-top=0px;
width: 80%;
margin-left: auto;
margin-right: auto;
}
h3 {
margin-top:100px;
margin-bottom:0px;
}
the result I'm expecting is that the "mainBody" div has 0px top margin while the h3 inside has 100px top margin. However, what I got instead is that the "mainBody" div shifts down with h3 together, meaning that they both have a top-margin of 100px with respect to the top of the page.
Does anyone know why this happens?
Thanks a lot!
Add display:inline-block; to h3 element class.
h3 {
margin-top:100px;
margin-bottom:0px;
display:inline-block;
}
Js Fiddle Demo
I don't see any problem! See the Fiddle. I added borders to the elements to clearly see the element position.
Note:I have tested in FF 26.0, Chrome 32.0 on Ubuntu 12.04 LTS.
This is how it looks:
I added borders to see the element boundaries:
#mainBody{
...
border:1px solid red;
}
.subTitle {
...
border:1px solid green;
}
h3 {
...
border:1px solid blue;
}
During the workflow, You will need to remove collapsing, for that you probably need this http://nicolasgallagher.com/micro-clearfix-hack/
I'm not sure you really need the <h3> - you could just style the text in the subtitle.
CSS
#mainBody{
height:200px;
width: 500px;
margin-top: 0px;
margin-left: auto;
margin-right: auto;
border: 1px solid black;
}
.subTitle {
margin-top=0px;
width: 80%;
margin-left: auto;
margin-right: auto;
margin-top: 70px;
border: 1px solid red;
font-size: 26px;
font-weight: bold;
text-align: center;
border-top: 6px solid red;
}
HTML
<div id="mainBody">
<div class="subTitle" id="backgroundTitle" >
Background
</div>
</div>
FIDDLE
I'm trying to put a logo and a sidebar next to eachother, but it just won't work. The logo container needs to be centered at the top. And the sidebar needs the be at the top-left Can you help me? I already tried float, no succes. :(
code:
<body>
<center>
<div id="logo1">
<div id="logo2"></div>
</div>
</center>
<div id="sidebar1">
<a href="https://test.com/" target="blank">
<div id="test1"></div>
</a>
</div>
</body>
CSS:
#test1 {
display: inline-block;
position: absolute;
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/2.png');
height: 45px;
width: 45px;
}
#test1:hover {
display: inline-block;
position: absolute;
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/1.png');
height: 45px;
width: 45px;
}
#sidebar1 {
display: inline-block;
position: relative;
border: 1px solid;
margin-top: -10px;
margin-left: -15px;
background-image:url('Afbeeldingen/lol.png');
height: 1080px;
width: 118px;
}
#logo1 {
display: inline-block;
position: relative;
border: 1px solid;
margin-top: 10px;
height: 100px;
width: 700px;
}
Ok, This is what you have to do :
You need to remove the display:inline-block from #logo1
And instead of just writing margin-top:10px , you need to use margin:0px auto, or you could write margin:10px auto. By this, it will center your #logo1 div.
But to center a "div" , you need to have another container(div) that wrap within your div. So that it will know, from which side to which side that it will have to be "centered".
For that reason, you will need to create another div or container around your #logo1 div, and lets assume it is called "right" (see the code below).
And for this div/container to be just beside your sidebar, it will need to have a relative position same as your sidebar. Now, you can just float both of your #sidebar1 and also your #logo1 to the left.
Thus, you dont have to use that negative margin for your sidebar anymore (remove that). If you wanted to use the negative margin, you have to use the absolute position in this case. But you will then have to restructure your whole #logo1 div which will create a lot of works.
This is the full code for your reference :
HTML code :
<div id="container">
<div id="sidebar1">
<a href="https://test.com/" target="blank">
<div id="test1">This is sidebar</div>
</a>
</div>
<div id="right">
<div id="logo1">
<div id="logo2"><This is logo</div>
</div>
</div>
</div>
And use this CSS :
#container{
width:1000px;
height:1080px;
position:absolute;
border:1px solid #000;
}
#test1 {
display: inline-block;
position: relative;
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/2.png');
height: 45px;
width: 45px;
}
#test1:hover {
display: inline-block;
position: relative;
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/1.png');
height: 45px;
width: 45px;
}
#sidebar1 {
display: inline-block;
position:relative;
float:left;
border: 1px solid;
background-image:url('Afbeeldingen/lol.png');
height: 1080px;
width: 118px;
border:1px solid red;
}
#right{
position:relative;
float:left;
margin-top:0px;
width:870px;
height:100px;
}
#logo1 {
position:relative;
border: 1px solid;
margin: 0px auto;
height: 100px;
width: 700px;
}
Do you want this ?
#test1 {
border: 1px solid;
margin-top: 15px;
margin-left: 22px;
background-image:url('Afbeeldingen/2.png');
height: 45px;
width: 45px;
}
#test1:hover {
background-image:url('Afbeeldingen/1.png');
}
#sidebar1 {
position:absolute;
border: 1px solid;
background-image:url('Afbeeldingen/lol.png');
height: 1080px;
width: 118px;
}
#logo1 {
border: 1px solid;
margin-top: 10px;
height: 100px;
width: 700px;
}
<div id="sidebar1">
<a href="https://test.com/" target="blank">
<div id="test1"></div>
</a>
</div>
<div id="logo1">
<div id="logo2"></div>
</div>
I assume this is what you want? http://jsfiddle.net/Le6PH/
You should do:
Remove the negative margins (If you don't know what you are doing, don't use negative margins)
Remove the <center> tag (This tag is deprecated since EVER)
Remove the margin of your logo
Add a wrapper div around your whole structure
Add the following CSS to that div
CSS
.wrapper{
position:relative;
width:818px; /* sidebar width + logo width */
}
Change position:relative; to position:absolute for your logo & sidebar divs.
Add top:0; for both divs
Add right:0; for the sidebar div
EDIT:
With a centered logo, like this (http://jsfiddle.net/Le6PH/1/) you'll need to change 2 things:
Add a margin-left:118px; to the logo div
Change the width of the wrapper to width of logo + margin logo + width of sidebar.
Try floating your div, it should look like this..
<div class="row">
<div id="log"></div>
</div>
<div class="row">
<div id="sidebar"></div>
</div>
css
.row{
float: left;
width: 50%;
}
I have icon, which on click adds new div's (columns) to div container. The problem is that when new div's (columns) appears the button doesn't shift right. Is it possible to somehow add position:fixed only inside the div?
Here is a few screens of what I have
And some code
<div id="grid">
<div id="add-col"></div>
<div class="clear"></div>
<div id="squares"></div>
</div>
#grid{
width:710px;
height: 470px;
border:1px dotted #dddddd;
display: none;
margin: 5px auto;
padding: 5px;
text-align:center;
overflow: auto;
}
#add-col{
margin:5px;
float:right;
background-image: url(images/table-add-column-icon.png);
width: 32px;
height: 32px;
cursor: pointer;
}
Your CSS would look like this :
#grid{
width:710px;
height: 470px;
border:1px dotted #dddddd;
display: none;
margin: 5px auto;
padding: 5px;
text-align:center;
overflow: auto;
position:relative; //added
}
#add-col{
margin:5px;
background-image: url(images/table-add-column-icon.png);
width: 32px;
height: 32px;
cursor: pointer;
position:absolute; //added
top:5px; //added
right:5px; //added
}
With position absolute you can place a button in a corner without having it to move from that position ever again.
To use a position you need to place position:relative; to its parent, else it will fly around the page.
Note: float has been deleted from #add-col