css alignment troubles with 3 column layout - css

My site looks like this:
I've coloured the central info bit red, so you can see. It's too far down the page! I can't work out why.
Here's the css (well, actually scss, but you get the idea) for that section:
#searchresult {
.left {
background-color:yellow;
float:left;
margin-right:0.5em;
}
.center {
background-color:red;
#activity {
float:right;
}
}
.right {
background-color:green;
float:right;
width:145px;
margin-left: 1em;
.info, .email {
#include minimal-btn();
a {
padding: 3px 0 0 28px;
}
}
}
}
(If you haven't seen it before, scss is a cool thing that compiles down to css. It works just as you'd think it would.)
Here's the html:
<ItemTemplate>
<div id="searchresult" class="box group">
<div class="left">
<img id="imgLogo" runat="server" alt="Logo" src=""/>
</div>
<div class="right">
<asp:Panel ID="pnlEmail" runat="server">
<div class="minimal email"><asp:HyperLink ID="lnkEmail" runat="server">Email this business</asp:HyperLink></div>
</asp:Panel>
<asp:Panel ID="pnlMicrosite" runat="server">
<div class="minimal info"><asp:HyperLink ID="lnkMicrosite" runat="server">Full company info</asp:HyperLink></div>
</asp:Panel>
<asp:Panel ID="pnlRecommends" runat="server" CssClass="recommends">
<span>Recommends: <strong><asp:Literal ID="litRecommends" runat="server"></asp:Literal></strong></span>
</asp:Panel>
</div>
<div class="center">
<span id="activity">Activity: <asp:Literal ID="litCompanyActivity" runat="server"></asp:Literal></span>
<h3><asp:Literal ID="litCompanyName" runat="server"></asp:Literal></h3>
<em><asp:Literal ID="litCompanyLocation" runat="server"></asp:Literal></em>
</div>
</div>
</ItemTemplate>
I'm pretty new to web design. Css isn't very intuitive for me, and I can't work out what is going on here. In the guide I was following This problem didn't seem to arise.

This is causing the problem:
<h3><asp:Literal ID="litCompanyName" runat="server"></asp:Literal></h3>
specifically, the default margin-top on the h3.
You can remove the margin-top, if that's what you want:
h3 {
margin-top: 0
}
Or, you can set overflow: hidden on .center to prevent collapsing margins, which is the source of your "alignment problem".

Related

CSS margin-top in Asp.net

<form id="form1" runat="server">
<div>
<div style="height: 350px; width: 250px; background-color: #ECECEA; color: #993399">
<div class="image">
<asp:Image ID="imgteacher" runat="server" Height="150" Width="250" /></div>
<div style="margin-left: 3px">
<div style="font-size: 28px">
<asp:Label runat="server" ID="lblname" Text="Mobile Web Development"></asp:Label></div>
<div style="margin-top: 140px; float: left">
<asp:Label ID="lbldate" runat="server" Text="01.04.2014"></asp:Label></div>
<div id="detail" style="margin-top: 150px; font-size: 20px; color: Fuchsia; margin-left: 190px">
Detail</div>
</div>
</div>
</div>
</form>
I am developing in Asp.Net .
I have so problem.
As shown above code margin-top for lbldetail is 140px. At this time it is on the bottom of gray window.
But here lblname can be change by user.
User can add long name as lblname. At this time lbldetail goes downwards and exits border of gray window.(if lblname would be little , at this time it goes up toward as shown picture)
But I want lbldetail's place would not be depend on lblname and its place would be constant(bottom of gray window)
I hope I could explain.
The div with id "detail" needs position absolute. and as Murali Murugesan said, you do need to lose the inline styles and use a CSS file.
div#detail
{
position:absolute;
top:330px;
font-size: 20px;
color: Fuchsia;
margin-left: 190px
}
You can find the example at: http://jsfiddle.net/9Bkha/

Div css not getting applied to layout. Why am I doing wrong?

I'm currently changing from table based layouts to use div layout instead. I'm struggling with the css. My styles just don't seem to be getting applied even though the css file is loading. What am I doing wrong?
.CategoryHeader
{
font-family: Verdana;
font-size: 10pt;
color: #2151b1;
text-align: left;
padding-bottom:3px;
padding-top:3px;
}
.CriteriaHeader {
font-family: Verdana;
font-size: 10pt;
text-align: left;
padding-bottom:3px;
padding-top:3px;
}
.divTable {
display: table;
border: none;
width:100%;
}
.divTR {
display: table-row;
width: 100%;
}
.divTD {
display: table-cell;
margin-bottom:22px;
}
<div class="divTable">
<div class="divTR">
<div class="divTD">
<LABEL class="CriteriaHeader">Number</LABEL>
</div>
</div>
<div class="divTR">
<div class="divTD">
<asp:TextBox id="txtNumber" runat="server" CssClass="Textbox" ToolTip="Enter Number to search"></asp:TextBox>
</div>
</div>
<div class="divTR">
<div class="divTD">
<LABEL class="CriteriaHeader">Description</LABEL>
</div>
</div>
<div class="divTR">
<ajaxToolkit:ListSearchExtender ID="cboDesc_ListSearchExtender" runat="server"
Enabled="True" TargetControlID="cboDesc" PromptCssClass="ListSearch">
</ajaxToolkit:ListSearchExtender>
<div class="divTD">
<asp:DropDownList id="cboDesc" runat="server" CssClass="DropDownList" ToolTip="Choose description to search"></asp:DropDownList>
</div>
</div>
</div>
<div>
<asp:Button id="btnSearch" runat="server" Text="Submit" CssClass="Button"></asp:Button>
<asp:Button id="btnClear" runat="server" Text="Clear" CssClass="Button"></asp:Button>
</div>
Instead of using so many table property, you can use position:relative/absolute/fixed, display:inline/inline-block. They are absolutely compatible with IE6+ and non-IE browsers. Like table、table-row、table-cell,they are not absolutely for IE browser.

How to get text to show outside of the previous div area?

With the code below $title1 and $title2 should be outside of the div and centered against the width of the page. It only does this because I have the "Y" there. If I remove the "Y" the text moves up and it's centered the address class. Obviously I can't keep the "Y" there but not sure why that changes things.
<html>
<head>
<title></title>
<style>
body { margin:12pt auto 12pt auto;width:568pt; }
.sseal { float:left; width:56.25pt; }
.address { float:left;text-align:center; margin:15px auto;width:450pt; }
.dseal { float:right; width:56.25pt;}
wrapper { margin:0px auto; }
.form_title { text-align:center;font-weight:bold;font-size:22pt; }
.header { font-weight:bold; }
.heading { font-size:16pt;font-weight:bold; }
.title1 { font-size:24pt;font-weight:bold;text-align:center; }
.title2 { font-size:22pt;font-weight:bold; font-style:oblique;text-align:center; }
table, th, td { padding:10px; }
hr { padding:0px;spacing:0px;margin:0px; }
.rightpaced { margin:45px; }
</style>
</head>
<body>
<div class="wrapper">
<div class="sseal"><img src="../image2.gif" height="75" width="75" border="0"></div>
<div class="clear:both;"></div>
<div class="address">
<font size=+1><b>
$companyname<br>
$address
</b></font>
</div>
<div class="clear:both;"></div>
<div class="dseal"><img src="../image2.gif" height="75" width="75" border="0"></div>
<div class="clear:both;"></div>
</div>
<div class="clear:both;"></div>
Y<br>
<div class="title1">$title1</div>
<p>
<div class="title2">$title2</div>
</body>
</html>
First of all, unless you have some limitation (browser-support, this is an assignment that has to be done this way), I'd suggest you use newer (CSS2 and CSS3) selectors and HTML tags (for instance, the <br /> is not used much anymore).
See W3Schools for more information on newer HTML and CSS. The site has excellent examples and tutorials as well.
EDIT: See this example of the layout you wanted (I think).

Webpage changes when I run it

I'm trying to design a webpage using Asp.net and CSS in Visual Studio 2010. the problem is simple but i have no idea how to fix it. Im creating a header in my page, this header is a div, its linked to my stylesheet for coloring. I put an image in the div, and i added a label. Now after some time to put the image in the middle of the div and text under it, when i run the website, the Label leaves the div completely and sits outside. How do i fix this? and for future reference, what technique or method do i follow so that the webpage before running always looks the same after running? I've decided to create a stylesheet for every page and put all my styles in there.
Sorry, here it is.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="LoginStyleSheet.css" rel="Stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="HeaderDiv">
<img alt="" class="Logo" longdesc="http://localhost:17260/MECIT_Logo.png"
src="MECIT_Logo.png" />
<asp:Label CssClass="Title" ID="WelcomeLabel" runat="server" Text="SSS">
</asp:label>
</div>
</form>
</body>
</html>
body
{
background-color:Gray;
}
.HeaderDiv
{
background-color: #0099FF;
height: 121px;
}
.Logo
{
position:absolute;
left:40%;
}
.Title
{
position:absolute;
left:38%;
bottom:83%;
font-size:xx-large;
font-family:Cambria;
font-weight:bold;
color:Navy;
width: 336px;
}
I don't understand why you are absolutely positioning the elements inside the container, all this can be handled with margins and alignment. Here is my suggestion:
Click here to view the fiddle
CSS:
body
{
background-color:Gray;
}
.HeaderDiv
{
background-color: #0099FF;
height: 121px;
text-align:center;
}
.Logo
{
margin:5 auto;
}
.Title
{
font-size:xx-large;
font-family:Cambria;
font-weight:bold;
color:Navy;
width: 336px;
}​
HTML:
<div class="HeaderDiv">
<img alt="" class="Logo" longdesc="http://localhost:17260/MECIT_Logo.png"
src="http://www.mecit.edu.om/images/MECIT_Logo.png" /><br />
//Used a <span> for the Label, as I believe that is what it renders as
<span class="Title" id="WelcomeLabel">Some Title</span>
</div>

Move div in next line using css

I have two div's one has textbox in it and other just plain text. This is how it looks:
. I want to move text div which has language in it to the next line where arrow is showing in the pic. I searched every where cant find any solution the wordwrap is not working. Also i have to do this within css.
Here is the aspx code for both:
<asp:Panel ID="search" runat="server" EnableViewState="False" Wrap="False">
<div id="txtBox">
<asp:textbox id="box" runat="server"></asp:textbox>
<div id="text" runat="server">Language</div>
</div>
</asp:Panel>
css:
#search
{
position:absolute;
top:100px;
height:50px;
left:100px;
width:1000px;
}
#txtBox
{
float: left;
}
Here is the solution for anyone who is stuck in same situation:
#text
{
clear: left;
}
clear:left moves the text to next line to the bottom of the textbox. Then you can use margin-left to set the text at any position you want.
You don't want to use float:left in this situation. float:left is for stacking block level HTML elements horizontally.
block level elements automatically stack vertically, which seems to be what you want.
However, the <asp:TextBox> is an inline level element, so you can put a <br /> after it, or wrap it in a <div>.
Solution:
HTML
<asp:Panel ID="search" class="search-class" runat="server" EnableViewState="False" Wrap="False">
<div id="txtBox">
<asp:textbox id="box" runat="server"></asp:textbox>
<br />
<div id="text" runat="server">Language</div>
</div>
</asp:Panel>
OR
<asp:Panel ID="search" class="search-class" runat="server" EnableViewState="False" Wrap="False">
<div id="txtBox">
<div>
<asp:textbox id="box" runat="server"></asp:textbox>
</div>
<div id="text" runat="server">Language</div>
</div>
</asp:Panel>
CSS
.search-class
{ /* Curt is right, the ID="search" is in a naming container, */
/* so use class selector */
position:absolute;
top:100px;
height:50px;
left:100px;
width:1000px;
}
have you tryed doing:
clear:both on the div with the language?
and maybe you should contain the textbox
/* Containing floats */
.contain:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
/* IE6 */
* html .contain {
height: 1%;
}
/* IE7 */
*:first-child+html .contain {
min-height: 1px;
}
When ASP.NET controls are rendered to the client, they sometimes produce different IDs (unless specified otherwise in ASP.NET 4).
Looking at your code, I don't see any control with an ID of txtBox, so these styles aren't being applied.
When working with ASP.NET, I find its best to use classes for styling, as these will stay the same after rendering.
<asp:Panel ID="search" runat="server" EnableViewState="False" Wrap="False" CssClass="search">
<div id="txtBox">
<asp:textbox id="box" runat="server" CssClass="txtBox"></asp:textbox>
<div id="text" runat="server">Language</div>
</div>
</asp:Panel>
.search
{
position:absolute;
top:100px;
height:50px;
left:100px;
width:1000px;
}
.txtBox
{
float: left;
}
I haven't tested this code, but you should now see these styles applying correctly, and therefore you can amend them as you wish.

Resources