1

I created this code in oder to use it to place image and text side by side in a HTML page.

.mydiv {
    width:646px;
    height: auto;
}

.myimage {
    float:left;
    width:378px;
    height:291px;
    margin:5px;
}

The proble I am having is that I want to use the code multiple times in different files and with different image values and I don't want to be creating css file for all of them. So how can I write all the code for the with different values for all the files in one css file?

4
  • 1
    either create different classes for each image sizing set, or use different css files, or dynamically generate the css to match whatever page it's being used in. Commented Nov 17, 2012 at 3:41
  • Perhaps a "CSS compiler" (e.g. LESS, SASS) could be useful .. they might support "templates" or whatnot. Commented Nov 17, 2012 at 3:42
  • 1
    If your images are different sizes then you don't want to use CSS to size them but rather put height and width attributes on the image tags themselves. Commented Nov 17, 2012 at 4:00
  • If the images are meant to be pseudo-responsive (same image with scaling) then that doesn't work. Commented Nov 30, 2012 at 14:52

2 Answers 2

1

First, you can put your CSS in a CSS file, then include this file in all your html page by using this in the

<LINK href="special.css" rel="stylesheet" type="text/css">

(See W3C)

For the values that can't be reuse between your html files (the SRC of your image, for instance), you will have to right it manually in each file. You can do this directly in your HTML (if you use ) or by declaring in your header.

Sign up to request clarification or add additional context in comments.

Comments

0

Create a .css file with the above code. You would need to specify the height of the .myimage class too. In all the files where you want the above file import the file using

<LINK href="example.css" rel="stylesheet" type="text/css">.

Now for the div holding the image give the class as .myimage and the src attribute is independent of the file

Edit- Suppose you have 3 html files in your site and you want the above css classes to be implemented in all the files, then open a new notepad file, paste the css classes in the file and save as somestyle.css. Now in each html file you use the above link tag to import the css and use the classes as you would do normally.

2 Comments

I am really sorry I don't get it. Actually I am new in web design and I'm not finding it easy at all. I am just trying to help my church build a website of their own but everything I'm doing is falling apart. How do I go about all these suggestion you guys are giving me?
Did you read this- w3schools.com/css/css_howto.asp regarding style sheets usage?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.