Again, just learning CSS and trying to make a fictive homepage.
Here's a problem I came by:
I want to center the links and their background colors inside a DIV- element. However, I also want to keep the DIV centered (15% from each side) and changing the text inside the links will still center them, so the positioning can't be a specific value (need to use per centages, I think).
EDIT: Long explanation shortly: I want to get all four blocks in the middle of the page regardless of changing the size of the browser screen or the texts inside the blocks. Thanks :)
EDIT2: Changed the title to be found more easily from the Search- query.
Anything can be done to the code or do I have to change it somehow? Thanks.
Here's the HTML:
.infos {
padding-left: 15%;
padding-right: 15%;
position: relative;
top: 40px;
}
.infos a {
background-color: black;
color: white;
margin: 0px;
display: inline;
padding-top: 10px;
padding-bottom: 60px;
text-decoration: none !important;
}
.infos #centered {
position: relative;
display: block;
padding: 0px;
}
<DIV CLASS="infos">
<DIV ID="centered">
Application for Membership
Rules
Travel Conditions
Meetings
</DIV>
</DIV>
Thank you for your help!
#centered {
display:table;
background:red;
margin:auto;
}
#centered a {
color: white;
margin: 0;
float:left;
padding-top: 10px;
padding-bottom: 60px;
text-decoration: none !important;
}
<DIV ID="centered">
Application for Membership
Rules
Travel Conditions
Meetings
</DIV>
I made display: inline-block working here. As you can see, checkbox and text were aligned horizontally.
But it does not work on this fiddle:
Actually I have three problems to solve here:
Make the checkbox and text: Swing Equipment Also inline with the checkbox.
In the right content, I have a button Swing System and I want it to be right aligned.
As you can see, I have left and right contents. They are mostly 50% of the width, I want them to be centered. Currently it is not.
Code snippet:
HTML
<li>
<input type="checkbox" class="swing_checkbox" id="swing_equipment" /> <span id="swing_label_small">Swing Equipment Also</span>
</li>
CSS:
#swing_label_small, #swing_equipment {
display: inline-block;
font-size: 0.8em;
}
Make the checkbox and text: Swing Equipment Also inline with the checkbox.
The checkbox has a width set to 90% by this css declaration...
input {
position: relative;
width: 90%;
}
change that to...
input[type=text] {
position: relative;
width: 90%;
}
In the right content, I have a button Swing System and I want it to be right aligned.
First thing I noticed is you are placing a button inside a ul...that will not validate as proper html. I would suggest you to move it out of the ul because is not semantically correct. But working with what you have...adding text-align:right to the ul and then adding text-align:right to the child li should work...
#right_content{
text-align:right;
}
ul#right_content > li {
border: 0px solid green;
margin: 0;
width: 100%;
position: relative;
text-align:left;
}
As you can see, I have left and right contents. They are mostly 50% of the width, I want them to be centered. Currently it is not.
I'm not too sure what you mean...please clarify so I can modify my answer
Here's the changes I made.
For 1) added CSS to checkbox as you make all input widht:90%;
input[type="checkbox"]{
width:auto;
}
For 2) added a div field for clear both purpose. Then make the button float right.
HTML:
<button type="button" class="swing_btn">Swing System</button>
<div class="clear"></div>
CSS:
.clear{ clear:both;}
#right_content > button
{
float:right;
}
3)As your are using ul as structure. there are padding that been use for ul.
Removed the inner ul padding that ruined the structure.
ul li ul {
padding:0px;
}
Gave table a margin to make it center:
.swing_grid, tr, td {
border: 1px solid gray;
border-collapse: collapse;
margin: 0 auto;
}
And finally let the content align center:
ul.content {
border: 0px solid gray;
box-sizing: border-box;
width: 49%;
position: relative;
list-style-type: none;
display: inline-block;
vertical-align: top;
text-align: center;
}
Here's my FIDDLE work.
1) For the checkbox and text issue: apply width: auto; to the checkbox:
.swing_checkbox {
width:auto;
}
The following was giving the checkbox a width of 90%, which is why the text was pushed down to the next line.
input {
position: relative;
width: 90%;
}
2) Something like this will work, I'm using inline styles here because I am lazy. Feel free to tidy that up yourself.
<ul class="content" id="right_content">
<li style="text-align: right;"> <button type="button" class="swing_btn">Swing System</button></li>
...
...
...
3) Use text-align:center; on the container, and then apply text-align:left; to it's inner elements. This will center block level elements with a percentage defined width. There are other ways to do this, however, if you're interested in researching them.
.swing_wrapper {
text-align: center;
}
ul.content,.swing_title, {
text-align: left;
}
4) You should also take a look at some debug tools such as Firebug, it makes debugging issues like this a lot easier with it's Inspection tool.
I have a simple html form.
This form has a specific width and margin auto so the form is in the middle of the screen.
form
{
margin: 0px auto;
padding: 0;
min-width: 600px;
width: 650px;
}
I validate if all textboxes are filled. I use asp:RequiredFieldValidator with an own css class
.ErrorMessage
{
position:relative;
left: 80px;
width: 150px;
font-weight: bold;
display:inline;
}
But the error message are not shown right off the form because of the max width of the form. The error message will break to a second line. I can't use absolute position because the form is in the middle of the screen.
The problem is that the form has a border and i can't expand the max width.
This is a screenshot: http://suffball.de/form_error.png
How can I put the error message in right of the form? I need a solution without javascript.
Is this possible?
Thank You!
Change your .ErrorMessage Css Class like below:
.ErrorMessage
{
position:relative;
left: 80px;
width: 150px;
font-weight: bold;
display:inline;
float: right;
}
Hope this will solve your issue.
I'm attempting to style heading text similar to how your default legend text appears in fieldsets; that is to say, I'd like a strikethrough-like line to come up to, but not through, the text. I can't seem to find any information on how I might accomplish this, and since on numerous other questions Google's always directed me to Stack Overflow for answers, I thought someone here may be able to give me advice.
For greater clarity. I'm attempting to get this effect on header text:
Centered Header Text
Is there any way to do this?
See: http://jsfiddle.net/thirtydot/jm4VQ/
If the text needs to wrap, this won't work. In IE7, there will be no line.
HTML:
<h2><span>Centered Header Text</span></h2>
CSS:
h2 {
text-align: center;
display: table;
width: 100%;
}
h2 > span, h2:before, h2:after {
display: table-cell;
}
h2:before, h2:after {
background: url(http://dummyimage.com/2x1/f0f/fff&text=+) repeat-x center;
width: 50%;
content: ' ';
}
h2 > span {
white-space: nowrap;
padding: 0 9px;
}
Edit:
<h2><strike> </strike>Your Text Here<strike> </strike></h2>
Here's how you can do it with a few simple tags and non-breaking spaces.
I'd use an image and call it a day, but this seemed to work for me:
CSS
fieldset {
border-right: 0px;
border-left: 0px;
border-bottom: 0px;
width: 200px;
}
legend {
margin: 0 25%;
}
HTML
<fieldset>
<legend>My Text Here</legend>
</fieldset>
That's the only way I could figure out how to do it with css. Note the width is fixed. Once again I wouldn't do this myself.
I came up with a quick, image-less solution that seems to work pretty well in IE 8+ and other browsers, whilst gracefully degrading in IE 6/7:
<h1>CSS 2.1 EXAMPLE</h1>
h1 { position: relative; text-align: center; }
h1:first-line { background-color: white; }
h1:before {
position: absolute;
z-index: -1;
content: '';
left: 0px;
right: 0px;
height: 1px;
top: 50%;
background-color: black;
}
It does come with the following limitations, though:
The text must match the overall background colour exactly, otherwise it will look weird.
If you want any kind of padding on the text, you need to use non-breaking spaces at either side of the text (see demo).
Heading text must always be on one line (works best if fixed width).
Here's a demo: http://jsfiddle.net/AndyE/3tFQJ/
With flexbox being supported by all the latest browsers out there, and it being five years since the IE8 requirement was mentioned by the author, I wanted to have some fun building a new solution using that.
A variety of examples getting more complicated:
https://jsfiddle.net/0mL79b4h/1/
https://jsfiddle.net/0mL79b4h/2/
CSS
div {
display: flex;
align-items: center;
}
div:before,
div:after {
border: 1px solid #000000;
border-radius: 2px;
height: 2px;
display: block;
content: "";
flex: 1;
width: 100%;
}
h1 {
text-align: center;
margin: 8px;
}
HTML
<div>
<h1>Example Text</h1>
</div>
<div>
<h1>Multi-Line<br>Example Text</h1>
</div>
Pros:
Uses flexbox!
Super simple HTML.
Left and right sides can be adjusted for asymmetry.
Zero background issues, no inheriting colors, etc.
Fluid width.
Multi-Line support.
Left/Center/Right/Custom Alignment: Just adjust the flex property separately for the before and after elements, higher numbers will dedicate more space to that side. Remove one entirely to left or right align it.
Interesting effects by playing with the border style (I actually chose a round border in this example). Set height to 0px and use border-top instead for a generic line.
Cons:
Uses flexbox. Call me lazy, but I didn't build in any backward compatibility in this example so it'll look odd on a browser that supports psuedo elements but doesn't support flexbox, although last I checked that was Chrome (Firefox, etc), which are all automatically updated anyway. Might want to use some Modernizr.
Here is what I am using on a client's site: http://jsfiddle.net/TPgE4/
Pros:
No images needed - renders instantly
Uses padding to control space on both sides of text
Text can be center aligned, or left/right aligned — just add, e.g., margin-left: 8px or margin-right: 8px on h2 span style definition to make it look good
Cons:
Requires use of additional tag such as <span>...</span> inside heading tag
Text must fit on one line for good appearance
Background color on <span> element must match surrounding background color, so if you have a non-solid background image, gradient or pattern it won't match perfectly
Kind of late to the party, but this is my solution: https://jsfiddle.net/g43pt908/
Requires no images, and doesn't depend on a background color.
HTML
<div class="hr-text">
<span>Some text</span>
</div>
CSS
.hr-text {
border-top: 1px solid #999;
text-align: center;
background-color: inherit;
}
.hr-text span {
display: inline-block;
position: relative;
height: 14px;
top: -12px;
font-size: 14px;
font-style: italic;
color: #666;
background-color: inherit;
padding: 0 10px;
}
I'm not sure if this would suit your need...
h1:before, h1:after {
content: " ------------- ";
}
This doesn't feel like a very good answer, but I'm posting it anyway.
See: http://jsfiddle.net/rFmQg/
<h2><span>Centered Header Text</span></h2>
h2 {
background: url(http://dummyimage.com/2x1/f0f/fff&text=+) repeat-x center;
text-align: center
}
h2 span {
background: #fff;
padding: 0 9px
}
I don't like it because:
You have to use an image.
This. (it only works if the backgrounds match)
body { padding-top: 100px; }
div.parent {
text-align: center;
border-top: 1px solid #ccc;
}
div.parent div {
display: inline-block;
margin-top: -0.8em;
padding: 0 0.5em;
background: #fff;
}
<body>
<div class="parent">
<div>My Text Here</div>
</div>
</body>
This is a fluid-width solution that matches your design and should be ok in IE7 (though I'll admit I didn't check). There are a couple of downsides:
You lose the fieldset/legend semantics.
You can't put a transparent background on the text.
If you don't need it to be fluid-width, onteria_'s solution is probably your best bet.
/* Normal Bubble */
.bubble {
width: auto;
font-size: 0.75em;
margin-bottom: 24px;
}
.bubble blockquote {
margin: 0px;
padding: 0px;
border: 1px solid #c9c2c1;
background-color: #000;
}
.bubble blockquote p {
margin: 10px;
padding: 0px;
font-size: 21px;
}
.bubble cite {
position: relative;
margin: 0px;
padding: 7px 0px 0px 15px;
top: 6px;
background: transparent url(b/tip.gif) no-repeat 20px 0;
font-style: normal;
}
I have this for my comments.. that looks like "speech bubbles" .
I dont want it big from the beginning, i want to have it custom after the text.. I mean if you wrote "hello" then it should be around it with maybe 1-2px margin from the bubble, so if you wrote "Hello my name is and i like to cook!" then it should be bigger..its like this right now:
<div class="bubble">
<blockquote>
<p>the comment text is here</p>
</blockquote>
<cite>Written by me</cite>
</div>
A div, by default, is block level and, therefore, will expand its width to the width of its parent container (rather than its contents).
Two options to consider would be to set the div to
display: inline-block
Or float it.
Do you mean to put it like that?
.bubble blockquote p {
display: inline;
/*(...)*/
}
See http://www.htmldog.com/reference/cssproperties/display/
I'm not sure quite what you are asking either.
Perhaps you are referring to creating a popup (using images) that scales according to the size of the content? To do that you need multiple overlapping images. It it only scales in one direction (vertically or horizontally) you need two images, if it scales in both directions you need to create four images. This technique is sometimes called "sliding doors".